Home/Support/Support Forum/Send API frame through MATLAB serial
New and improved user forum site going live on 12/6 (All users will need to reset their password when the new forum is active)

Send API frame through MATLAB serial

0 votes
Hi,

I have a transmitting xBee and a receiving one (both S6B series). I want to send an API frame to my xBee transmitter using MATLAB serial port. The frame is a simple Tx64 request sent to the receiving module. Both xBee settings and frame should be ok because I can successfully send the request using XCTU. The basic code I'm using is:

s = serial('/dev/tty...','BaudRate',57600);
set(s,'DataBits' , 8 );
set(s,'StopBits' , 1 );
set(s,'Terminator' , '' )

fopen(s);

APIframe = '7E length 00 frameID IPaddress 00 message checksum';

fwrite(s, APIframe)


I believe the problem is the format I use for the frame, because I don't have any errors from Matlab and RSS led on the receiving Xbee doesn't turn on. It looks like the transmitting Xbee does not recognize the message as an API frame. I tried to convert it as decimal but still nothing.

Thank you for your help,

Pietro.
asked Oct 17, 2014 in RF Solutions and XBee by pietropier New to the Community (1 point)
edited Oct 16, 2014 by pietropier
Hi Pietro,

Just a quick doubt about the APIframe message.
Does the characters of the message must be sent with separate by spaces, as you did?
'7E length 00 frameID IPaddress 00 message checksum'

Or the can be sent together?
'7Elength00frameIDIPaddress00messagechecksum'
Sorry for the late replay, I temporarily lost access to my code. The way I'm constructing the frame with Matlab is by filling a vector element by element with desired hex values expressed as char, for example:

frame(1,:) = '7E';                                      % Frame Class Name for reading only
frame(2,:) = '00';                                     % length 1
frame(3,:) = num2str(frmLgt);                % length 2
frame(4:5,:) = ['00';'00'];                        % type & ID
frame(6:12,:) = ['00';'00';'00';'00';'C0';'A8';'01'];
frame(13,:) = address;  
frame(14,:) = '00';
...
frame = hex2dec(frame);
fwrite(ssCOM, frame, 'uint8')

Hope this help, let me know if you need more info.

Please log in or register to answer this question.

2 Answers

0 votes
After several trials I found the correct form for the outgoing message. As supposed, the error was in the format of the string which as to be converted to decimal. If anyone else is interested here is my solution:

APIframe = ;
APIframe = hex2dec(APIframe);
fwrite = (serial,APIframe,'uint8');

Have fun!

Pietro.
answered Oct 17, 2014 by pietropier New to the Community (1 point)
Hy!It's bit late for a question but i'll try anyway...
I am facing the same problem. i am reading an API frame in Matlab but does't seem to work. I have tried your solution and same result. could you pls provide more matlab code so i can try understand how you solved it?
Thank you very much!
I replied to a comment to my first post, hope you get some insight from it. Let me know.
0 votes
Hi Pietro,

Thanks a lot for your collaboration :)
I followed this path and it works pretty good.

The current issue I'm facing now is how to read on MATLAb the messages sent over by the remote XBEE.

I tried to use fread() and fscanf() functions in MATLAB but I still haven't had a successful outcome.

Do you have any hints?

Best regards,

Alexandre
answered Oct 13, 2016 by all.martins076 New to the Community (1 point)
...