Serial Object with Callback Function Ignores ASCII values > 127

89 Ansichten (letzte 30 Tage)
Frank Schmidt
Frank Schmidt am 28 Sep. 2012
Hello,
I am using a serial object to communicate with an FPGA. I created a callback function that has its terminator set to '\n\r', or [10 13] in ASCII values. The callback works as expected, up until the time I attempt to send ASCII values that are > 127 from the FPGA to MATLAB, even though the '\n\r' is still present at the end of the packet sent from the FPGA to MATLAB. Is there any reason the serial object would ignore ASCII values > 127 and not call the callback function?
Thanks,
Frank

Antworten (2)

Jan
Jan am 30 Sep. 2012
Please post your code. Perhaps your observation is not correct, e.g. if you store the data in an signed integer and convert it to an unsigned later on.
  1 Kommentar
Frank Schmidt
Frank Schmidt am 30 Sep. 2012
Hi Jan,
Thanks for the tip--I was using fscanf(serialObject) without specifying the format, so I changed to using fscanf(serialObject,'%u'), but that still isn't working. Below is my code, and I am using a GUI, hence the references to "handles":
-- main GUI code --
% create serial object
serConn = serial('COM2', 'TimeOut', 10,'BaudRate', 115200);
% specify function to handle data received on serial object
serConn.BytesAvailableFcn = {@serial_callback,handles};
% set input buffer size
serConn.InputBufferSize = 1024;
% set "end of serial message" = terminator
serConn.BytesAvailableFcnMode = 'terminator';
% choose terminator to be '\n\r'
serConn.Terminator = 'LF/CR'; % [10 13]
% open serial connection
fopen(serConn);\
--- callback function ---
function serial_callback(serConn, event, handles)
% get data on serial object, read in as unsigned integers
out = fscanf(serConn,'%u');
% get size of data read from serial object
outSize = size(out);
% print output for debugging
for i = 1:outSize(1,2)
fprintf('ASCII value of out(1,%d): %d\n',i,out(1,i));
end
end
I know I am getting the values on the serial object even when the values are > 127, because I can see outputs like this if I explicitly run the "print output for debugging" for loop:
ASCII value of out(1,1): 96
ASCII value of out(1,2): 3
ASCII value of out(1,3): 3
ASCII value of out(1,4): 19
ASCII value of out(1,5): 233
ASCII value of out(1,6): 43
ASCII value of out(1,7): 64
ASCII value of out(1,8): 10
ASCII value of out(1,9): 13
The issue is the callback is not being triggered when a value > 127 is sent to the MATLAB serial object from the external FPGA. So in this case, the 5th byte = 233, so the callback does not occur, even though the terminator is correct with the 8th and 9th bytes = 10 and 13, respectively.
Thanks in advance, Frank

Melden Sie sich an, um zu kommentieren.


per isakson
per isakson am 29 Sep. 2012
  1. CRLF, i.e [13,10] is used more often
  2. do you have 8 databits?
  3 Kommentare
Frank Schmidt
Frank Schmidt am 30 Sep. 2012
Have you ever experienced a similar issue?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by