factor/extra/io/serial/serial.factor

37 lines
1.1 KiB
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 alien.c-types assocs combinators destructors
2008-09-05 20:29:14 -04:00
kernel math math.bitwise math.parser sequences summary system
vocabs io ;
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
{
{ [ os linux? ] [ "io.serial.linux" ] }
2009-02-22 18:50:29 -05:00
{ [ os windows? ] [ "io.serial.windows" ] }
2008-08-13 16:18:50 -04:00
} cond require