How to read from a serial port in Matlab R2018a
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
jq rq
le 12 Nov 2020
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 commentaires
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!