Can't specify machineformat when using fread with a serial object

1 次查看(过去 30 天)
I am currently gathering real-time data through a serial port object.
To do so, I set up a serial object, and use the callback to run an fread() command. I would like to read it in big-endian format by setting the machineformat parameter using 'b'.
If I read in binary data from a file, I can successfully use the command:
data=fread(fid, 1, 'uint16',0,'b');
However when I run the same syntax on data from a serial object, I get the error that there are "too many inputs". I currently get around it by using little-endian and the swapbyte() function, however that seems very inefficient.
Below is my code. If anyone has any reasons as to why this error is occurring, I would greatly appreciate the help.
function serial()
s = serial ('COM3');
s.BytesAvailableFcnCount = 2000;
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcn= @callbacktest;
set (s, 'BaudRate', 115200, 'InputBufferSize', 2000, 'OutputBufferSize', 2000);
fopen (s);
function callbacktest(obj, event)
data=fread(obj, 1, 'uint16',0,'b');
Thanks so much for your help!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by