Izzo
Izzo

Reputation: 4928

MATLAB/SIMULINK - Serial Receive Block

I'm currently working on a project within Simulink. I'm attempting to have Simulink communicate with motor controller via serial. However, I'm struggling very much.

I believe I have found out how to send commands with the Serial Command block. However, I'm struggling attempting to the use the Serial Receive block and am struggling very much. The help document for Serial Receive can be found here. http://www.mathworks.com/help/instrument/serialreceive.html

There are several issues: - I don't know how this block buffers the incoming data. Does it just keep filling its buffer until the terminate signal is received? What happens if it keeps receiving data with no terminate signal?

Here's specifically what I expected to receive.

I will send an ASCII command '0000IP'.

I expect to receive back 'IP=0000FFFF'. This is a total of 11 ASCII characters. These ASCII characters require 8*11 = 88 bits. I am attempting to get 0000FFFF into Simulink as an integer value.

How do I break up this message? And does Simulink offer any type of ASCII converter? I appreciate any help!

Upvotes: 0

Views: 5302

Answers (1)

50k4
50k4

Reputation: 251

You can set a number of terminator characters in the blocks property page, I assume in your case the terminator will be 'none' and you will have a constant byte length that you want to read. Set the data type to byte (uint8) and connect the output of the serial recv block to a Matlab Function Block, there you can do Ascii checking.

char(block_input_signal) will return your ascii string and you can do what you want with it.

Enable blocking mode is the setting that set async/sync mode. If it is enabled the simulation will wait for the number of bytes specified at each simulation step. If not, it will not block your simulation ant put out the new values as soon as the data is available.The status port of the block will let you know if new data is received, it will be active for 1 cycle (when the data is new).

Upvotes: 0

Related Questions