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
답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!