在Scilab控制台上复制Arduino的串行监视器

问题描述 投票:0回答:1

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

enter image description here

我想首先在SciLab终端中复制此行为。我用过Serial Communication Toolbox

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

返回空或

, 169

228, 179

228,

228, 205

228, 209 228,

disp(readserial(h))放入while循环也无济于事。不仅有太多的空行,如果我停止while循环它不会关闭端口(我认为应该使用类似try-catch的东西)。如果您能帮助我知道如何获得与Arduino串行监视器相同的行为,我将不胜感激?

附:接下来我想实时绘制这两个值。所以也许使用csvTextScan函数将字符串拆分为两个整数。

serial-port tcl serial-communication scilab
1个回答
0
投票

好吧,经过几天的努力,我想出了这个。事实证明,SciLab没有本机串行通信功能,Toolbox开发人员使用TCL_EvalStr从外部运行Tcl命令。我不得不深入研究Tcl串口通信语法(即readopengetsfconfigure ......),询问another question,获取some help然后最终得到一个新工具箱,我已将其作为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 

现在可以通过运行来获得上述行为:

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

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

closeserial(h)

逐行读取串行端口并将其打印到SciLab控制台。现在解析您可能使用的CSV数据:

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

enter image description here

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

P.S.2。与Toolbox开发人员Aditya Sengupta here on Twitter进行更多讨论。

P.S.3。关于Tcl Google group的更多讨论

P.S.4。完整的演示加上说明here on Reddit

P.S.5。对于那些可能会在这里结束的人,我决定将Aditya Sengupta的存储库here与几个改进分开。

© www.soinside.com 2019 - 2024. All rights reserved.