matlab - MATLAB 无法从串行 COM 端口读取数据
问题描述
我正在使用TSI 流量计 4040,它使用 RS232 串行 COM 端口(38400 波特率,8 个数据位,1 个停止位,无极性,无流量控制)。流量计数据格式为 ASCII。
根据数据表,在 PuTTY 中,我需要键入命令DAFxx1000从流量计获取 1000 个数据读数。现在,我尝试在 MATLAB 中做同样的事情。连接成功。但是,我无法读取传感器数据(见图)。请问有人知道为什么吗?
谢谢!
解决方案
问题解决了。TSI 4040 流量计有点特别。它返回: OK (change line) data1,data2,data3 (change line) 所以我需要使用以下 MATLAB 命令:
% Show all available COM serial ports on the PC
serialportlist
% Set COM serial port, baud rate
%{
Default setting:
Baud rate: 38400
Data bits: 8 bits
Stop bit: 1 bit
Parity: None
Flow control: None
Timeout: 10 seconds
%}
s = serialport("COM1",38400);
% Set terminator for ASCII string communication
% CR = Carriage Return
% LF = Line Feed
configureTerminator(s,"CR/LF");
% Display the terminator
s.Terminator
%% We MUST manually stop the while loop when it's finished
%{
Steps:
1. Send command to TSI flowmeter
2. Read and save data to the string array: OK (change line)
3. Read and save data to the string array: flowmeter return data
%}
i = 1;
while 1
writeline(s,"DAFTP0100");
OK(i) = readline(s);
data(i) = readline(s);
i = i + 1;
end
推荐阅读
- javascript - 在三个 JS 中相交数组为空
- recursion - 通过“for循环”在Maple中定义递归关系
- java - 从 .txt 文件中读取数据并保存为类变量
- mysql - 如何为单列上的不同值获取有限的数据集?
- javascript - 手动选择输入日期到最大值返回未定义
- android - FAB 内的中心图像
- raku - .wrap sub 之后的错误 Signature.ACCEPTS
- ionic3 - 离子错误未处理的承诺拒绝:对象(...)不是一个函数Promise。那么不是ionic3中的函数吗?
- vue.js - Nuxt - 根据布局的全局组件
- java - Jackson 反序列化 Scala Future