How to read from a serial port in Matlab R2018a
25 次查看(过去 30 天)
显示 更早的评论
I need to read and save the input data from a USB port. As I searched, first the serial port, as an object, should be defined:
- serialport (MatLab 2019 and later)
- serial (MatLab 2018 and older)
Then, using the "read" function, the port can be read. Although, the "read" function does not work for "serial":
- Undefined function 'read' for input arguments of type 'serial'.
How could I read the input data from a USB port in MatLab 2018a?
0 个评论
回答(1 个)
jq rq
2020-11-12
Hi Shahin,
I've found something that works for me using older commands in R2019a.
Let's assume device like multimeter where we know port (or we can detect it), baudrate and we're periodically sending there command like tell me value, output is string (char).
clc; clear; close all
s = serial('COM3','BaudRate',230400);
fopen(s)
for i = 1:11
fprintf(s,"VAL?")
pause(1)
fgets(s) % <- output
end
fclose(s)
Hope this helped you!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!