]> gitweb.factorcode.org Git - factor.git/blob - extra/io/serial/serial.factor
Make "foo.private" require load foo instead.
[factor.git] / extra / io / serial / serial.factor
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
5 vocabs io ;
6 IN: io.serial
7
8 TUPLE: serial-port < disposable stream path baud 
9     termios iflag oflag cflag lflag ;
10
11 ERROR: invalid-baud baud ;
12 M: invalid-baud summary ( invalid-baud -- string )
13     baud>> number>string
14     "Baud rate " " not supported" surround ;
15
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 ;
20
21 : <serial-port> ( path baud -- obj )
22     serial-port new
23         swap >>baud
24         swap >>path
25         default-serial-flags ;
26
27 : with-duplex-stream ( duplex-stream quot -- )
28     [ [ in>> ] [ out>> ] bi ] dip with-streams ; inline
29
30 : with-serial-port ( serial-port quot -- )
31     [ open-serial ] dip with-duplex-stream ; inline
32
33 {
34     { [ os unix? ] [ "io.serial.unix" ] } 
35     { [ os windows? ] [ "io.serial.windows" ] }
36 } cond require