How do I change Simulink xPC target serial comm speed on the fly

884 views Asked by At

I have an xPC target application that talks to a device over RS-232. I am using the xPC serial block for this.
To talk to this device I first have to start at a default speed, say, 9600 bps, request a change of speed to, say 57600 bps, then change the speed on my side to match it.
The problem with the xPC block is that it forces you to choose a specific speed before running, and can't change it at run time. Is there a way/trick/hack to do this?

3

There are 3 answers

0
AudioBubble On

Here is my take so far. I don't think it can be done using existing Simulink blocks. I think I am going to have to take the xpcserial C code that comes with Matlab, take the code that sets the RS-232 speed, and wrap it in my own S-function.

0
Will Robertson On

I agree with you: I don't think it can be done, I'm afraid.

On further reflection, I've realised that in my xPC system, I get a compilation warning telling me that the blocks I'm using don't support sample time changes during runtime; this implies that it's not impossible in general…

0
XPav On

Ian,

What I've done before on this stuff is just modify the registers behind XPC target's back. It's ugly, but xPCTarget is ugly in the first place.

Try modify Line Control Register and set the divisors directly -- all you need is the serial port IO address, and you know that.

It's worth a shot anyway, you're going to have to do it anyway.