I am using Rebol3 v3.0.99.4.20 that has both the /View and serial functionality.
I am opening a port with:
ser: open serial://ttyUSB0/9600
Then, I set up my asynchronous handler:
ser/awake: func [event /local p][
p: event/port
switch event/type [
lookup [open p]
connect [write p to-binary request]
read [
result: to-string p/data
close p
return true
]
wrote [read event/port]
]
false
]
The problem I have now is that I cannot figure out how to read data from the serial port. I always only get back the last command I wrote to the serial port in ser/data.
For example:
>> ser: open serial://ttyUSB0/9600
>> write ser "debug on^/"
>> read ser
== "debug on^/"
That looks OK so far, but this is how the serial device operates using the Linux command, 'screen':
My input:
debug on
The serial device response:
Debug messages enabled.
>
However, I never can read the "Debug messages enabled." text.
>> read ser
== "debug on^/"
>> wait ser
== none
>> read ser
== "debug on^/"
>> copy ser/data
== "debug on^/"
Not sure what I'm missing.
In Rebol2, it is much more straightforward, but not asynchronous:
>> system/ports/serial
== [com1 com2 com4]
>> ser: open/no-wait serial://port3/9600/8/none/1
>> insert ser "debug on^/"
>> copy ser
== "debug on^/Debug messages enabled.^/>"
>> copy ser
== ""
A 2nd copy doesn't return anything because the first copy cleared the serial buffer. If data was streaming to the serial port, additional 'copy commands would return additional data from the serial buffer. But it doesn't work this way in Rebol3.