1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors destructors io kernel math.parser sequences
4 summary system vocabs ;
7 TUPLE: serial-port < disposable stream path baud
8 termios iflag oflag cflag lflag ;
10 ERROR: invalid-baud baud ;
11 M: invalid-baud summary ( invalid-baud -- string )
13 "Baud rate " " not supported" surround ;
15 HOOK: lookup-baud os ( m -- n )
16 HOOK: open-serial os ( serial -- serial' )
17 HOOK: default-serial-flags os ( m -- n )
18 M: serial-port dispose* ( serial -- ) stream>> dispose ;
20 : <serial-port> ( path baud -- obj )
24 default-serial-flags ;
26 : with-duplex-stream ( duplex-stream quot -- )
27 [ [ in>> ] [ out>> ] bi ] dip with-streams ; inline
29 : with-serial-port ( serial-port quot -- )
30 [ open-serial ] dip with-duplex-stream ; inline
32 "io.serial." os name>> append require