MATLAB Answers

Serial protocol: How to interpret command structure?

1 view (last 30 days)
Christian on 4 Feb 2016
Answered: Guillaume on 4 Feb 2016
I am trying to communicate with a serial device (via a virtual COM port). My problem is that I do not know how to turn the commands given in the reference (e.g. the one in the image below) into the correct message to be sent via fwrite(). The simple code as I have it is
o = serial('COM4','BaudRate',115200,'DataBits',8,'Stopbits',1)
o.FlowControl = 'hardware';
I have tried this with different destination (d) bytes corresponding to the different possibilities that make sense, but nothing works - no response from the hardware. I am sure that the COMport is the correct one. I have also done this with the tmtool and changed through the different formats (binary or ASCII). I feel like most likely, the message I am sending is not what I think it is - how do I convert the "TX 23,02,00,00,21,01" into something to send to the serial port? Do I need to send the bytes individually, or as a string, or...?
Many thanks!

Answers (1)

Guillaume on 4 Feb 2016
In your documentation, there should be an introduction that explains the general format of the commands. It' not clear from the image you've posted what that format is. What does 'TX' stands for in their example?
Going on the fact that it says that the command structure is 6 bytes, this may work:
fwrite(o, [23 02 00 00 21 01]);


Community Treasure Hunt

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

Start Hunting!