initial code for windows serial support

db4
Doug Coleman 2009-01-13 19:01:01 -06:00
parent d823516b72
commit afc76ecab0
4 changed files with 27 additions and 0 deletions

View File

@ -20,4 +20,5 @@ M: serial dispose ( serial -- ) stream>> dispose ;
{
{ [ os unix? ] [ "serial.unix" ] }
{ [ os windows? ] [ "serial.windows" ] }
} cond require

View File

View File

@ -0,0 +1,4 @@
! Copyright (C) 2009 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test serial.windows ;
IN: serial.windows.tests

View File

@ -0,0 +1,22 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: io.files.windows io.streams.duplex kernel math
math.bitwise windows.kernel32 accessors alien.c-types
windows io.files.windows fry locals continuations ;
IN: serial.windows
: <serial-stream> ( path encoding -- duplex )
[ open-r/w dup ] dip <encoder-duplex> ;
: get-comm-state ( duplex -- dcb )
in>> handle>>
"DCB" <c-object> tuck
GetCommState win32-error=0/f ;
: set-comm-state ( duplex dcb -- )
[ in>> handle>> ] dip
SetCommState win32-error=0/f ;
:: with-comm-state ( duplex quot: ( dcb -- ) -- )
duplex get-comm-state :> dcb
dcb clone quot curry [ dcb set-comm-state ] recover ; inline