Re: xPC Serial Communication Problems
- From: "Walter Collins" <myrddhin393@xxxxxxxxxxx>
- Date: Fri, 19 May 2006 12:28:48 -0400
Gordon,
I had looked into the possibility of upgrading to the newer blocks,
but I'm a bit lost. We're running version 2006a and all of the actual
serial communication blocks (that aren't marked "not for new models")
seem to be written for specific add-on serial port/communications
boards. I don't see a single one for using the serial ports that come
on a CPU card. We're using the serial ports that come on the CPU
board since we don't have room to add an extra PC-104 card to the
stack (and it has 2 ports on it, which is all we need). Did I miss
some documentation somewhere on how to upgrade from the older blocks
to the newer ones in the instance we're in? Looking over the FIFOs
with the advice you posted makes me think I can use those just fine
to implement what we're doing in the old code, but I'm stumped as to
what I should be doing as far as connecting those FIFOs to the
onboard serial ports.
Thanks for all the help you've given.
Walter
Gordon Weast wrote:
the
Walter,
The older serial block you're using uses the kernel resident driver
and I don't have much control of that.
The newer component version runs entirely in Simulink code. I've
never seen bytes get wrapped like you're seeing with the new
driver.
The data you send needs to be formatted slightly different for the
new driver. Since you have data bytes that have the value 0, you
need to present the data as a vector of 16 bit values. Only the
bottom 8 bits are sent, just leave the upper 8 bits empty. The
first element is the number of values to follow. So, with the
old driver you would have the vector:
[0xBA 0xBD 0xBD 0xBA 0xBA 0xBD 0 7 255 7 255 7 255 0 0] as a uint8
vector,
with the new driver you would change this to:
[15 0xBA 0xBD 0xBD 0xBA 0xBA 0xBD 0 7 255 7 255 7 255 0 0] as a
uint16
vector.
The new driver interprets a uint8 vector as a null terminated
string,
so it would take the first vector and just send the 6 byte header
and
stop before sending the 0. The uint8 vector format is therefore
only
useful for true ascii strings that don't contain 0 data bytes.
You will get a lot more control with the new driver. I've never
seen
it send bytes out of order or a message get rotated like you're
seeing.
Gordon Weast
xPC Target Development
The Mathworks
Walter Collins wrote:
I'll start with the oscilloscope, since that's what we used to
discover this problem and because the only reason I mentioned
thereceiving system was that that system can't handle the packetsdetail
becoming lopsided like this. I'll describe that system in more
later, just in case you think it might be useful.
We did hook an o'scope up to the transmit line coming out of
bytestarget PC. This confirmed that when we saw strange behavior onthe
console, the packets coming from the target PC are still 15
we'dlong, 115.2 kbps, etc. The only difference is that it was if
bytesrotated the packet structure so that we had 1, 2 or 3 data
atbytes.
the beginning of it, then the 6 synch bytes, then the remainderof
the data bytes. Everything about the packet looks just fine,other
than being "rotated" like this. That's why I put forth my guessthat
somehow we either lose a byte or add a byte or something in thepacket
serial routines on the target computer. The "beginning" of the
doesn't always look the same due to this packet rotation. Theonly
other thing I can think to add is that the CPU uses a 16550 (orsome
reasonable facsimile) so the hardware buffer should be 16
byteswe're
Packet should be:
BA BD BD BA BA BD 0 7 255 7 255 7 255 0 0
Packet ends up something like:
255 0 0 BA BD BD BA BA BD 0 7 255 7 255 7
(with very large gaps between packets so it's easy to see that
looking at a packet)code.
The console is an embedded microcontroller running homebrew C
The serial port doesn't have any hardware buffer so I have anenough
interrupt reading it after every byte and the interrupt's high
priority that it doesn't get interrupted itself. I drop the
synchinto a ring buffer and then "look backwards" to see if the
getbytes are "in position" and if they are, then I know I'vereceived
the whole packet and I pass it along to the main loop. The ring
buffer's currently 16 bytes and we've verified that it can't
aavoid
false positive on the synch byte check. I could modify its code
slightly so as to double buffer the data and this *should*
theit
console going crazy when this packet shifting takes place, but
guessdoesn't solve the source of the packet shifting. It would,however,
mean that we might be lagging by 50 ms as we wait for the tailend of
a packet to come in. In the current use, that 50 ms is probably
acceptable, but this may not always be the case. Hopefully this
answers all of your questions.
Walter
Gordon Weast wrote:
Walter,
I'll ask a few questions about your system before making a
resultabout what's going on here.
Is the receiving machine executing at the 'same' 50 ms rate?
I quote the word 'same' since any such attempt will always
themin drift between the two machines unless something forces
that canto stay synchronized.
Is the receiving machine using a read call to its system
Thatreturn exactly 15, or merely up to 15 characters at a time?
syncreceiveis,
does it wait until there are at least 15 characters in the
buffer, then return exactly the first 15, or does it return
whatever
is in it's buffer, up to 15 characters?
Does the receiver throw away characters until it sees the
beencharacters,
then read the fixed message length? This will force
synchronization,
even when the reader executes when a partial message has
bufferreceived.
A partial message could be in the receive buffer if the two
machines
execute with the right phase shift (receiver looks at the
bewhen
a message is partially done).
I suspect you're seeing a timing drift problem, but I can't
With 8sure.
If you connect an oscilloscope to the transmit data wire and
measure
the data burst, is it 15 characters long at 115200 baud?
sodata
bits, plus start and stop, there are 10 bits per character
thislength
data rate is 15*10/115200 = 1.302 ms. Is it always this
awith the
beginning always looking the same? If so, then you're seeing
targetreceive
synchronization problem.
Gordon Weast
xPC Target Development
The Mathworks
Walter Collins wrote:
I'm using RTW with the xPC target to send data from the
andcomputer to a control console. The data is 15 bytes long
computer
gets
sent every 50 ms (20Hz). The model on the target
lines)
currently
consists of 5 constant source blocks (split off into 15
is fed
going
into a pack block that's expecting 15 uint8's and this
message width
into a
binary serial send block. The serial send block's
the
is 15
with a sample time of 0.05. The rs232 set-up block sets
works
port
up
to be 115.2 kbps with Tx and Rx buffer sizes of 1024, no
parity,
8
data, 1 stop, no protocol.
With that out of the way, the problem is this. The code
the
just
fine for a while. The packet has 6 "synch" bytes at the
beginning,
followed by a combination of 0, 255 and 7. Monitoring
see each
serial
stream coming from the target computer, we can clearly
time,
of
these where we expect them. After some random amount of
thehowever, the serial stream changes. The bytes seem to be
some
right
bytes, but now they're out of order. It's as if we lost
data bytes
bytes or
added some at some point. Now we'll have some of the
followed by
(the
0, 255, 7) at the beginning of the 15 byte packets,
causing
the
sync bytes, follewed by the rest of the data. This is
of
havoc
on the receiving end, which relies on there being a bit
split
breathing
room at the end of a packet. Since the packets are now
how to
between
packet trasmissions, we don't have that breathing room.
Has anyone else seen this or have any recommendations on
serial
fix
it? I've tried looking through the Simulink code for the
theblocks, but they just refer to "functions imported from
.
kernel"
so I can't see how they're actually handling the serial
communication
on a low level.
Thanks in advance for any help,
Walter
- Follow-Ups:
- Re: xPC Serial Communication Problems
- From: Gordon Weast
- Re: xPC Serial Communication Problems
- References:
- xPC Serial Communication Problems
- From: Walter Collins
- Re: xPC Serial Communication Problems
- From: Gordon Weast
- Re: xPC Serial Communication Problems
- From: Walter Collins
- Re: xPC Serial Communication Problems
- From: Gordon Weast
- xPC Serial Communication Problems
- Prev by Date: Re: Writing an image gallery with GUIDE
- Next by Date: Re: monotically increasing values
- Previous by thread: Re: xPC Serial Communication Problems
- Next by thread: Re: xPC Serial Communication Problems
- Index(es):
Relevant Pages
|