PDA

View Full Version : Serial Communication with Isopod


udayakumar
06-18-04, 12:22 PM
Hi,

I have developed a C++ program to communcate with Isopod using RS232. The requirement is to recieve sensor data from the isopod and be able to send commands to the isopod.

I have all the sensor data stored in a string and I use TYPE command to send the string to the serial port.

The problem comes when i am trying to send commands to the isopod when various state machines are simultaneously trying to send the string to the pc.. The sensor data and the response to my commands are all getting mixed up.

For example, I am trying to send the command 2 2 + . and at the same time the isopod is sending me string 307 297 310 308...
but this is what i am able to read from the port
307 296 2 2 + . 310 308 4 OK

How can I solve this problem? Is there some way to ensure that my messages dont get mixed up.
Thank You.

RMDumse
06-18-04, 02:36 PM
Well, there may be many ways... but first, since there are two serial channels on the IsoPod(TM) why not use SCI0 for interactive communications, and SCI1 for reports?

If both have to be on the same serial channel, I suppose you could use some locking variable where the one wouldn't print while the other has control of the serial channel.

Then use a simple word to replace the " . " in your example, that waits for the other channel to finish before taking over, locking out the other, and then calling the regular print " . ". Likewise, you'd need to make a similar replacement for TYPE which would first check the locking variable to see if it could print, and if not, wait state-machine style, until it was okay to print.

udayakumar
06-21-04, 02:49 PM
Thanks for the help. I think i am going to use the SCI1.
Could you please tell me how i can send the sensor report through SCI1.
Thanks again.

RMDumse
06-21-04, 09:36 PM
Unfortunately, the serial channels are not vectored where they can be intercepted. I think we might want to look at that as an addition to the language.

I think I've re-invented TYPE before to use SCI1.

Here's an example of how I put out a string I knew was 10 hex characters long:

( OUTPUT THE STRING
0
BEGIN
DUP MBUFF + @ SCI1 TX
1+ DUP 10 =
UNTIL
DROP


Well, let's see if I can make something. Here's a version of TYPE made for an LCD

: LCD-TYPE
BEGIN
DUP 0= NOT
WHILE
1- SWAP DUP @ LCD-EMIT 1+ SWAP
REPEAT
2DROP
; EEWORD

So it could be modified to use SCI1

: SCI1-TYPE
BEGIN
DUP 0= NOT
WHILE
1- SWAP DUP @ SCI1 TX 1+ SWAP
REPEAT
2DROP
; EEWORD

Think that would work, but it's not tested.


Now, I don't know how you're generating the strings you showed in your example, but it looks like your printing numbers with " . " perhaps. Here are some more LCD examples, modified with SCI1 TX in place of LCD-EMIT. Hope these help, but again, no garauntee, cause I haven't tested them.


: SCI1-SPACE BL SCI1 TX ; EEWORD
: SCI1-SPACES 0 MAX BEGIN ?DUP WHILE 1- SCI1-SPACE REPEAT ; EEWORD

: SCI1-TYPE
BEGIN
DUP 0= NOT
WHILE
1- SWAP DUP @ SCI1 TX 1+ SWAP
REPEAT
2DROP
; EEWORD

: SCI1-PTYPE
BEGIN
DUP 0= NOT
WHILE
1- SWAP DUP P@ SCI1 TX 1+ SWAP
REPEAT
2DROP
; EEWORD

: D.RSCI1 ( d \ n -- )
>R SWAP OVER DABS <# #S SIGN #> R> OVER - SCI1-SPACES SCI1-TYPE
; EEWORD

: .SCI1 ( n -- ) DUP ABS 0 <# #S SIGN #> SCI1-TYPE ; EEWORD

: $>P
<BUILDS
CR KEY DROP
PHERE 1 PALLOT
0
BEGIN
KEY DUP D = NOT ( NOT A CR, D = CR IN HEX, 13 = CR IN DEC
WHILE
P, 1+
REPEAT
DROP
0 P,
SWAP P!
DOES>
; EEWORD

$>P S1$
This is a sample
( ***16**LONG***
EEWORD

$>P S2$
Make string here
( ***16**LONG***
EEWORD


: TEST1
S1$ PCOUNT SCI1-PTYPE
CRLF
S2$ PCOUNT SCI1-PTYPE
; EEWORD

HERE 20 ALLOT CONSTANT S3$ ( STRING SPACE IN RAM
HERE 20 ALLOT CONSTANT S4$ ( STRING SPACE IN RAM

: TEST2
." Type in a string to store in S3$ RAM now:"
S3$ 10 EXPECT CR
." Type in a string to store in S4$ RAM now:"
S4$ 10 EXPECT CR
CLEAR
HOME
S3$ 10 SCI1-TYPE
CRLF
S4$ 10 SCI1-TYPE
; EEWORD

udayakumar
06-23-04, 10:59 AM
Thank you very much for the help sir. I will check your code out.
Yes, I did use the "." for displaying those numbers. I was using that to help me develop and test my serial communication code. I still havent figured out a way to pack all the sensor values in a single string.

Thank You