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!