How do I send 8-bit data that has null character via the serial port using xPC Target 2.8(R14SP3)?

4 views (last 30 days)
I have to transmit 8-bit data through the serial port on the target using RS232 communications protocol. The data I send does contain the null character and hence I cannot use null-terminated 8-bit transmission to transmit packets of data.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Aug 2011
You can transmit non-null terminated messages across a serial port with the 16-bit or 32-bit data type for the "Transmit FIFO Data Type" parameter of the "RS-232/RS-422/RS-485 Send/Receive" block. Although the parameter name suggests that the size of the data being sent is 16-bit or 32-bit, the 16 or 32 actually refers to the container size for 8-bit data.
For example, in the case of 16-bit data type, with every packet that is sent, the first 16-bit data is a counter value that identifies the number of 8-bit data that is to follow. The counter value is 16-bit (so you can send up to 65,365 long 8-bit character messages). The counter value is not transmitted, it is only used to control the transmission. In each of the 16-bit numbers that follow the counter, only the lower eight bits are transmitted.
The attached example illustrates the use of the 16-bit data type to transmit non-null terminated 8-bit data. Typically in such cases, headers and delimiters indicate the start and end of messages. This helps synchronization at the receiving end of the communication. The example also illustrates the use of headers and delimiters.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!