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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!