Streaming data using serialport
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Walter Roberson
el 27 de Abr. de 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 comentarios
Walter Roberson
el 25 de Mayo de 2023
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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!