在 Scilab consol 上复制 Arduino 的串行监视器 [英] replicate Arduino's serial monitor on Scilab consol

查看:78
本文介绍了在 Scilab consol 上复制 Arduino 的串行监视器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 Arduino IDE 的串行监视器,我可以读取以下逗号分隔值对:

<块引用>

我想首先在 SciLab 终端中复制此行为.我使用了

P.S.1. 我在 SimulIDE 中使用了一个虚拟 Arduino 板,并使用 com0com 创建了虚拟串口.更多信息在 SourceForge 上.

PS2.与 Toolbox 开发人员 Aditya Sengupta 进行更多讨论在 Twitter 上.

PS3.此处有关于 Tcl Google 群组

PS4.完整的演示和说明在 Reddit 上

PS5.对于那些可能会在这里结束的人,我决定分叉 Aditya Sengupta 的存储库 此处 进行了多项改进.

If I use the Arduino IDE's Serial monitor I can read the pair of comma separated values as below:

I want to first replicate this behavior in SciLab terminal. I used the Serial Communication Toolbox:

h = openserial(7, "9600,n,8,1") // open COM7
disp(readserial(h))
closeserial(h)

which returns either empty or

, 169

228, 179

228,

228, 205

228, 209 228,

putting the disp(readserial(h)) in a while loop also doesn't help. Not only there are too many empty lines, if I stop the while loop it does not close the port (something like try-catch should be used I think). I would appreciate if you could help me know how I could get the same behavior as Arduino's serial monitor?

P.S. Next I want to plot these two values in realtime. So maybe using the csvTextScan function to split the string into two integers.

解决方案

OK, after a couple of days struggling I figured this out. It turns out that SciLab doesn't have native serial communication functionality and the Toolbox developer has used TCL_EvalStr to run Tcl commands externally. I had to dig into the Tcl serial communication syntax (i.e. read, open, gets, fconfigure ... ), ask another question, get some help and then finally end up with a new function for the Toolbox which I have committed as a pull request:

function buf = readserialline(h)
    tmpbuf = emptystr();
    while tmpbuf == emptystr()
        TCL_EvalStr("gets " + h + " ttybuf");
        tmpbuf = TCL_GetVar("ttybuf");
    end
    buf = tmpbuf;
endfunction 

now one can get the above behavior by running:

h = openserial(7, "9600,n,8,1") // open COM7

for ii = 1:40
    disp(readserialline(h))
end

closeserial(h)

to read the serial port line by line and print it to the SciLab console. Now to parse the CSV data you may use:

 csvTextScan(part(readserialline(h), 1:$-1), ',')

P.S.1. I have used a virtual Arduino board inside SimulIDE and used com0com to create virtual serial ports. More information here on SourceForge.

P.S.2. More discussion with Toolbox developer Aditya Sengupta here on Twitter.

P.S.3. More discussions here on Tcl Google group

P.S.4. A full demonstration plus instructions here on Reddit

P.S.5. For those who might endup here I have decided to fork Aditya Sengupta's repository here with several improvements.

这篇关于在 Scilab consol 上复制 Arduino 的串行监视器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆