1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.files.windows io.streams.duplex kernel math
4 math.bitwise windows windows.kernel32 windows.errors accessors
5 alien.c-types fry locals continuations classes.struct ;
8 : <serial-stream> ( path encoding -- duplex )
9 [ open-r/w dup ] dip <encoder-duplex> ;
11 : get-comm-state ( duplex -- dcb )
13 DCB new [ GetCommState win32-error=0/f ] keep ;
15 : set-comm-state ( duplex dcb -- )
17 SetCommState win32-error=0/f ;
19 :: with-comm-state ( duplex quot: ( dcb -- ) -- )
20 duplex get-comm-state :> dcb
21 dcb clone quot curry [ dcb set-comm-state ] recover ; inline