フィルターのクリア

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

2 ビュー (過去 30 日間)
Michael
Michael 2012 年 8 月 20 日
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 Center および File ExchangeAutomated Driving Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by