Streaming data using serialport
이전 댓글 표시
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
2023년 4월 27일
0 개 추천
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
Rifat
2023년 4월 27일
Rifat
2023년 5월 24일
Walter Roberson
2023년 5월 24일
serial() allowed buffer sizes to be changed, serialport() does not appear to have any method to configure buffer sizes.
Rifat
2023년 5월 24일
Walter Roberson
2023년 5월 25일
The older serial() port had https://www.mathworks.com/help/matlab/ref/serial-properties.html#mw_5d33f1bd-97a2-4474-b2ea-8499775ddce4 -- InputBufferSize property (default: 512) and https://www.mathworks.com/help/matlab/ref/serial-properties.html#mw_f12b6a94-309a-4c7b-a160-f585876d0b35 -- OutputBufferSize (default: 512)
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
2023년 5월 26일
카테고리
도움말 센터 및 File Exchange에서 Serial Port Interface에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!