How can I specify a serial terminator > 127?

1 visualizzazione (ultimi 30 giorni)
Gus Lott
Gus Lott il 4 Ott 2013
Commentato: cr il 5 Ott 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 Commento
cr
cr il 5 Ott 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Instrument Control Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by