How to continuously read data on serial port in Matlab?
To continuously read data on serial port in Matlab, the best option is to use the serialport
object. Once the port is opened, read the data in a loop. In the following example, we'll assume data on serial port is a series of 3 integers separated by a space. Each series is separated a line feed (LF):
80 7 160
82 8 156
83 9 162
85 8 168
84 8 164
79 7 159
...
The following Matlab code open the serial device, read each line and convert to matrix:
close all;
clear all;
% Open the serial device and set LF as terminal character
device = serialport('COM1', 9600);
configureTerminator(device,"LF");
% Main loop
while (1)
% Get data line by line
line = readline(device);
data = sscanf(line, '%d')
end;
To continuously read data on serial port in Matlab, the best option is to use the serialport
object. Once the port is opened, read the data in a loop. In the following example, we'll assume data on serial port is a series of 3 integers separated by a space. Each series is separated a line feed (LF):
80 7 160
82 8 156
83 9 162
85 8 168
84 8 164
79 7 159
...
The following Matlab code open the serial device, read each line and convert to matrix:
close all;
clear all;
% Open the serial device and set LF as terminal character
device = serialport('COM1', 9600);
configureTerminator(device,"LF");
% Main loop
while (1)
% Get data line by line
line = readline(device);
data = sscanf(line, '%d')
end;
To continuously read data on serial port in Matlab, the best option is to use the serialport
object. Once the port is opened, read the data in a loop. In the following example, we'll assume data on serial port is a series of 3 integers separated by a space. Each series is separated a line feed (LF):
80 7 160
82 8 156
83 9 162
85 8 168
84 8 164
79 7 159
...
The following Matlab code open the serial device, read each line and convert to matrix:
close all;
clear all;
% Open the serial device and set LF as terminal character
device = serialport('COM1', 9600);
configureTerminator(device,"LF");
% Main loop
while (1)
% Get data line by line
line = readline(device);
data = sscanf(line, '%d')
end;
In the following we'll assume data on serial port is a series of 3 integers separated by a space. Each series is separated a line feed (LF):
80 7 160
82 8 156
83 9 162
85 8 168
84 8 164
79 7 159
...
The following Matlab code open the serial device, read each line and convert to matrix:
close all;
clear all;
device = serialport('COM1', 9600);
configureTerminator(device,"LF");
while (1)
line = readline(device);
data = sscanf(line, '%d')
end;
In the following we'll assume data on serial port is a series of 3 integers separated by a line feed (LF) :
80 7 160
82 8 156
83 9 162
85 8 168
84 8 164
79 7 159
...
The following Matlab code open the serial device, read each line and convert to matrix:
close all;
clear all;
device = serialport('COM1', 9600);
configureTerminator(device,"LF");
while (1)
line = readline(device);
data = sscanf(line, '%d')
end;
# | ID | Query | URL | Count |
---|