Can't specify machineformat when using fread with a serial object
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Automated Driving Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!