Streaming data using serialport

6 Ansichten (letzte 30 Tage)
Rifat
Rifat am 27 Apr. 2023
Kommentiert: Rifat am 26 Mai 2023
Hi,
I am using serialport() object to hex data from a serial port. I can read a data section by setting the 'TimeOut' property of the serial object and setting the number for characters to read with the read() function. But I wish to read the data continuously, as long as the serial port is connected to the computer. The 'ReadAsyncMode’ mode does not work with serialport() object. Does anyone know how to read data continuously using the serialport() object? Thanks.

Antworten (1)

Walter Roberson
Walter Roberson am 27 Apr. 2023
serialport() is continually reading and putting data into a buffer. As long as you do not overflow the buffer, it will grab data in the background.
In the situation you describe, you would typically use https://www.mathworks.com/help/matlab/ref/serialport.configurecallback.html configureCallback for "byte" and a count and a callback handle that is to be invoked each time sufficient data is read in.
  6 Kommentare
Walter Roberson
Walter Roberson am 25 Mai 2023
The newer serialport() has no documented buffer size control. In practice, though, it has hidden user-settable properties InputBufferSize and OutputBufferSize . With the properties not being documented, I cannot promise that it will actually use the buffer size that is set.
Historically, Mathworks has occasionally created object properties that they intend to implement in future, but hard-coding behaviour for a while, or keeping the properties hidden until they are finished testing or finished getting bugs out to their satisfaction. So the fact that the properties exist does not mean that they are used or that they function properly at this point.
... but you could try changing them and see what happens.
Rifat
Rifat am 26 Mai 2023
Thanks Walter for a bit of a serialport()'s background. I will give it a go.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by