How to store continuous serial data from COM port

13 Ansichten (letzte 30 Tage)
Joes Lanters
Joes Lanters am 27 Okt. 2020
Kommentiert: Walter Roberson am 30 Okt. 2020
I want to be able to store my data from a scale that I have connected to my laptop via a COM port. I have the following code, but it only shows the values in the Command Window:
% Assign port to s
s = serialport("COM3",9600);
configureCallback(s,"terminator",@readSerialData)
function readSerialData(src,~)
data = readline(src);
disp(data)
end
What can I do to store it in a variable?

Antworten (1)

Amrtanshu Raj
Amrtanshu Raj am 30 Okt. 2020
Hi,
You can achieve the required function using a global variable. They allow you to share variables across multiple functions and scripts. Here you can use a global array and add a value to it in the callback.
Hope this helps !!
  1 Kommentar
Walter Roberson
Walter Roberson am 30 Okt. 2020
We recommend against global variables!! They should only be used as a last resort or if for some reason the performance would be significantly improved by using global variables (which would take some doing, as global variables are the slowest kind of variables.)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by