1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types assocs combinators destructors
4 kernel math math.bitwise math.parser sequences summary system
8 TUPLE: serial-port < disposable stream path baud
9 termios iflag oflag cflag lflag ;
11 ERROR: invalid-baud baud ;
12 M: invalid-baud summary ( invalid-baud -- string )
14 "Baud rate " " not supported" surround ;
16 HOOK: lookup-baud os ( m -- n )
17 HOOK: open-serial os ( serial -- serial' )
18 HOOK: default-serial-flags os ( m -- n )
19 M: serial-port dispose* ( serial -- ) stream>> dispose ;
21 : <serial-port> ( path baud -- obj )
25 default-serial-flags ;
27 : with-duplex-stream ( duplex-stream quot -- )
28 [ [ in>> ] [ out>> ] bi ] dip with-streams ; inline
30 : with-serial-port ( serial-port quot -- )
31 [ open-serial ] dip with-duplex-stream ; inline
34 { [ os unix? ] [ "io.serial.unix" ] }
35 { [ os windows? ] [ "io.serial.windows" ] }