我正在使用Rebol3 v3.0.99.4.20,它具有/ View和串行功能。读取Rebol3中的串口
我打开一个端口:
ser: open serial://ttyUSB0/9600
然后,我建立了我的异步处理程序:
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
]
我现在的问题是,我无法弄清楚如何读取数据串口。我总是只回收我在ser/data中写入串口的最后一条命令。
例如:
>> ser: open serial://ttyUSB0/9600
>> write ser "debug on^/"
>> read ser
== "debug on^/"
这看起来不错,到目前为止,但这是怎样的串口设备使用Linux命令, '屏幕':
我输入:
debug on
串口设备响应:
Debug messages enabled.
>
但是,我永远无法阅读“启用调试消息”。文本。
>> read ser
== "debug on^/"
>> wait ser
== none
>> read ser
== "debug on^/"
>> copy ser/data
== "debug on^/"
不知道我错过了什么。
在Rebol2,它是更直接的,但不是异步:因为第一个副本清除串行缓冲器
>> 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
== ""
位于2副本不返回任何东西。如果数据流式传输到串行端口,则额外的“复制命令”会从串行缓冲区返回附加数据。但在Rebol3中这种方式不起作用。