How can I specify a serial terminator > 127?
2 ビュー (過去 30 日間)
古いコメントを表示
I am implementing serial communications specified in ICOM Communications Interface - V ver 3.2. I do not get an error number.
Each CI-V message begins with 'FEFE' [254 254] and terminates with 'FD' (253). Actual serial communications is in decimal. A typical message would look like:
['FE';'FE';'E1';'E0';'03';'FD'] or
[254
254
225
224
3
253] as actually transmitted.
Is there a way to specify a 253 ('FD') terminator? If not, can you suggest a method to have the BytesAvailableFcn trigger on the 253 ['FD']?
serial object specified in Methods:
obj.serialObj = serial(obj.serialPort,...
'BaudRate',19200,...
'Parity','None',...
'StopBits',2,...
'FlowControl','None',...
'BytesAvailableFcn',{@rfcPerseusRead,obj},...
'BytesAvailableFcnMode','byte',...
'BytesAvailableFcnCount',1,...
'TimeOut',3,...
'Name',['SDR-Serial-',obj.serialPort],...
'Tag','perseusSerialObj') ;
Right now I accumulate the message response byte-by-byte:
function rfcPerseusRead(scr,~,obj)
ba = get(obj.serialObj,'BytesAvailable') ;
try
while ba > 0
dataDecimal = fread(obj.serialObj,1,'uint8') ;
obj.dataMsg = [obj.dataMsg,dec2hex(dataDecimal,2)] ;
ba = get(obj.serialObj,'BytesAvailable') ;
end
catch
try
while ba > 0
dataDecimal = fread(obj.serialObj,1,'uint8') ;
obj.dataMsg = [obj.dataMsg,dec2hex(dataDecimal,2)] ;
ba = get(obj.serialObj,'BytesAvailable') ;
end
catch
'disp('Read Error') ;
end
end
end
1 件のコメント
cr
2013 年 10 月 5 日
Matlab allows only 0-127 for terminator character. Is the number of output bytes 6 per communication? If that is the case, increment your 'BytesAvailableFcnCount' to a multiple of 6. In the callback function extract the 3,4,5 bytes of interest.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Instrument Control Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!