Streaming data using serialport

조회 수: 11 (최근 30일)
Rifat
Rifat 2023년 4월 27일
댓글: Rifat 2023년 5월 26일
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.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 4월 27일
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
Walter Roberson
Walter Roberson 2023년 5월 25일
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 2023년 5월 26일
Thanks Walter for a bit of a serialport()'s background. I will give it a go.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by