[plt-scheme] Need low-level help: blocking on reading from serial port in Windows
On Fri, Oct 23, 2009 at 4:09 PM, Neil Van Dyke <neil at neilvandyke.org> wrote:
> I suggest using "sync" to block until bytes are once again ready to be read
> from the port.
Tried that; it still hangs most of the time, and when I break the
execution, it highlights the "sync" or "sync/enable-break"
expression....
;; raw-read : number bot -> (listof byte)
(define (raw-read n a-bot)
;(printf " raw-read")
(local [(define bstr (make-bytes n))
(define in (bot-in-port a-bot))
;; read-aux : number port -> number
(define (read-aux start-pos tries)
(cond [(>= start-pos n) start-pos] ; should never be > really
[else
(let [(r (read-bytes-avail!* bstr
(sync/enable-break in) start-pos))]
(cond [(number? r) (read-aux (+ r start-pos) 0)]
[else (read-aux start-pos (add1 tries))]
))]))
]
(read-aux 0 0)
(bytes->list bstr)
))