factor/extra/io/serial/serial.factor

33 lines
971 B
Factor
Raw Normal View History

2008-08-13 16:18:50 -04:00
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors destructors io kernel math.parser sequences
summary system vocabs ;
2009-02-22 18:50:29 -05:00
IN: io.serial
2008-08-13 16:18:50 -04:00
2011-10-08 14:38:43 -04:00
TUPLE: serial-port < disposable stream path baud
2008-08-13 16:18:50 -04:00
termios iflag oflag cflag lflag ;
ERROR: invalid-baud baud ;
M: invalid-baud summary ( invalid-baud -- string )
2009-02-22 18:50:29 -05:00
baud>> number>string
"Baud rate " " not supported" surround ;
2008-08-13 16:18:50 -04:00
HOOK: lookup-baud os ( m -- n )
HOOK: open-serial os ( serial -- serial' )
2011-10-08 14:38:43 -04:00
HOOK: default-serial-flags os ( m -- n )
M: serial-port dispose* ( serial -- ) stream>> dispose ;
: <serial-port> ( path baud -- obj )
serial-port new
swap >>baud
swap >>path
default-serial-flags ;
: with-duplex-stream ( duplex-stream quot -- )
[ [ in>> ] [ out>> ] bi ] dip with-streams ; inline
: with-serial-port ( serial-port quot -- )
[ open-serial ] dip with-duplex-stream ; inline
2008-08-13 16:18:50 -04:00
"io.serial." os name>> append require