serial communication device without driver

I want to send a signal or generate a signal for a serial control device connecting via RS232.
point to point link, Baud rate 38400, data bits 8, parity none, stop bits 1, CRC 16.
I want to generate or use matlab function or simulink to get a signal of fixed length of 6 bytes. The massage are transfered in 15ms cycle.
Example signal : AA ID AA 02 IC IE.
I want to generate or send a signal (AA ID AA 02 IC IE) keeping in mind all the parameters.

Respuestas (1)

Walter Roberson
Walter Roberson el 2 de Mzo. de 2022

0 votos

That uses the Instrument Control Toolbox.
You could also use MATLAB Function Block, and code in calls to serialport() and related functions; https://www.mathworks.com/help/matlab/ref/serialport.html

6 comentarios

Do the ICtoolbox support the signal of fixed length of 6 bytes to send?
I also tried the ''serial explorer''. It connects the device but the signal I want to generate is not correct.
Walter Roberson
Walter Roberson el 2 de Mzo. de 2022
For the Serial Send block in Simulink, the input port can be a vector of uint8. It also supports fixed header or fixed terminator. For example if your 6 bytes are always SOH followed by 4 data bytes followed by a checksum byte then your Signal could omit the SOH and you could configure that as a header.
At the MATLAB level, the write() method is for binary data.
https://www.mathworks.com/help/matlab/ref/serialport.write.html
I am trying to send a message from matlab
Fixed length of 6 bytes
1st Command Byte
2nd Data Byte 1
3rd Data Byte 2
4th Communication Byte1
5th Communication Byte 2
6th Checksum
The transmitted data is encapsulated into a data frame.
STX ... ... ... ETX
Start character user data Stop character
So If I want to send A0 IC ID 02 AA 33
How do I configure this message?
For serial send block Terminator has (none CR LF CR/LF null and Custom). Do I need to select STX and ETX for the Terminator?
Thank You
Walter Roberson
Walter Roberson el 3 de Mzo. de 2022
If you are using the serial send block in Simulink, you have two choices:
  1. Create a Simulink signal vector of length 6, that already has the STX and ETX in place, and have the block send it exactly as is. Configure the Header empty and the Terminator 'none'; OR
  2. Create a Simulink signal vector of length 4, that does not have the STX or ETX inside it. Configure the header to STX and the terminator to ETX; that would involve configuring the terminator as Custom and then filling in the Custom Terminator property.
To create the Signal Vector which blocks can I use? Is their any signal block in matlab to send fixed length data or I have to build one? A demo or a link will be very helpful.
Also is it possible to send the Signal Vector through "write();" command if I want to use "serialportObj" with STX...Data...ETX?
Thank You
Walter Roberson
Walter Roberson el 3 de Mzo. de 2022
There is no particular block in Simulink to send fixed length signals. The serial send block will send whatever shows up on its input port. Most signals in Simulink are fixed-length signals.
In theory you could be feeding the output of a triggered system or an if/then block into the serial send block. It will not care: it will send whatever is in the input port when it gets triggered (it only makes sense to use such a block with a discrete section rather than a continuous section.)
Generally speaking if you were wanting to send a block of calculated results not all created at the same time, and it was important that they be transferred at regular times or with a regular header for the block, then you could use a buffer block.

Iniciar sesión para comentar.

Preguntada:

el 2 de Mzo. de 2022

Comentada:

el 3 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by