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

1 Ansicht (letzte 30 Tage)
Michael
Michael am 20 Aug. 2012
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!

Antworten (0)

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by