How can I specify a serial terminator > 127?

1 view (last 30 days)
Gus Lott
Gus Lott on 4 Oct 2013
Commented: cr on 5 Oct 2013
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 Comment
cr
cr on 5 Oct 2013
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.

Sign in to comment.

Answers (0)

Categories

Find more on Instrument Control Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!