views:

341

answers:

3

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?

+1  A: 

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.

A: 

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…

Will Robertson
A: 

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.

XPav