I use net-select on serial port
check if it is ready to read data
I use stty to set serial port first
then open it with "non-block" option
(define (read_proc)
(setq rusbdev (open dev "r" "n"))
(if (nil? rusbdev)
(begin
(println "open " dev " read failed")
(exit rusbdev)
)
)
(until (= (share talk) 3) ;; for stoping and exiting
(while (and (net-select rusbdev "read" 10000) (> (peek rusbdev) 0) )
(setq read_ret (read_serial rusbdev) )
(share content read_ret)
(println "in read_proc " (share content))
)
(sleep 80)
)
(close rusbdev)
(exit 0)
)
the share parts are not important
I use share memory to send read results back to writing process
I forked a process to do reading stuff, and send results back to main process, the writing process.
but it seems net-select return at once, without waiting for like 10000ms
I know it's kind of wired , But I need a "function" like select
Maybe I can set something ,so make serial port dev fd to work like socket fd
Can I do that in newlisp?
BTW: this works, but not perfect, somehow, the speed of read is too fast, so it will might read twice on a
very short data
That's not I wanted
I want read the whole data from serial port at one time.
When I add (sleep 80) at the bottom of this function, it work maybe perfect at the most of time
But I am not sure (sleep) is the perfect ,safest way. I think
the number of ms in (sleep) is depend on the performance of my serial device
If my device is faster, then I maybe sleep less
otherwise, more
So I think select(net-select) is the smart way, right?
On Mac OSX and other UNIX use peek :
http://www.newlisp.org/downloads/newlisp_manual.html#peek
But peek wont wait like select or wait forever?
So peek + sleep is the option?
Is this ways good enough as select?