Sending data from 3 sensors via RS-232 to a BS2P
Archiver
Posts: 46,084
PART 1:
I'm looking to setup communications between two BS2P stamps using an
RS-232 connection (SERIN and SEROUT commands). The first Stamp will have
3 sensors connected to it and use something like the RCTIME command to
digitize the analog input. The first Stamp then needs to send a serial
string via the RS-232 connection to the Second Stamp. The second stamp
needs to display the values of the 3 variables (3 sensor readings) using
something such as DEBUG.
I've been reading through the SERIN portion of the Basic Manual but it
only seems to cover sending a single variable at a time. I would
appreciate it if someone would show me a sample piece of code that would
send the values of the 3 variables in a single SEROUT command, if this is
possible (and advisable). Would this operation be called sending a
variable as an array or a string? Book recommendations are also
welcome.
Thanks,
Chris Dundorf
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
http://dl.www.juno.com/get/web/.
I'm looking to setup communications between two BS2P stamps using an
RS-232 connection (SERIN and SEROUT commands). The first Stamp will have
3 sensors connected to it and use something like the RCTIME command to
digitize the analog input. The first Stamp then needs to send a serial
string via the RS-232 connection to the Second Stamp. The second stamp
needs to display the values of the 3 variables (3 sensor readings) using
something such as DEBUG.
I've been reading through the SERIN portion of the Basic Manual but it
only seems to cover sending a single variable at a time. I would
appreciate it if someone would show me a sample piece of code that would
send the values of the 3 variables in a single SEROUT command, if this is
possible (and advisable). Would this operation be called sending a
variable as an array or a string? Book recommendations are also
welcome.
Thanks,
Chris Dundorf
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
http://dl.www.juno.com/get/web/.
Comments
your variables with commas -- and make sure your RX side matches your TX side
or use the timeout value so you don't get stuck. Another thing: make sure
that if you're sending words that you are set to receive words.
[noparse][[/noparse]Simplified] Examples:
SEROUT pin, baud, [noparse][[/noparse]txVar1, txVar2, txVar3]
SERIN pin, baud, [noparse][[/noparse]rxVar1, rxVar2, rxVar3]
You might also consider flow control between the two Stamps.
-- Jon Williams
-- Parallax
In a message dated 4/13/02 9:55:08 PM Central Daylight Time,
cdundorf@j... writes:
> I've been reading through the SERIN portion of the Basic Manual but it
> only seems to cover sending a single variable at a time. I would
> appreciate it if someone would show me a sample piece of code that would
> send the values of the 3 variables in a single SEROUT command, if this is
> possible (and advisable). Would this operation be called sending a
> variable as an array or a string? Book recommendations are also
> welcome.
>
[noparse][[/noparse]Non-text portions of this message have been removed]
http://www.emesystems.com/BS2rs232.htm#MasterSlave
To send data that is a full 16 bits twos complement, you can either
send two bytes per data point, or you ca use the modifiers like dec
or hex:
Using bytes
x1 var word
x2 var word
on the transmitter
loop:
gosub getx1x2 ' not shown
serout 15\14,baudmode,600,bailout,[noparse][[/noparse]x1.byte0,x1.byte1,x2.byte0,x2.byte1]
goto loop
and on the receiver
loop:
serin 15\14,baudmode,600,bailout,[noparse][[/noparse]x1.byte0,x1.byte1,x2.byte0,x2.byte1]
debug
goto loop
Using hex modifier (which xmts/rcvs 4 ascii hex bytes per variable)
loop:
gosub getx1x2 ' not shown
serout 15\14,baudmode,600,bailout,[noparse][[/noparse]hex4 x1, hex4 x2]
goto loop
and on the receiver
loop:
serin 15\14,baudmode,600,bailout,[noparse][[/noparse]hex4 x1, hex4 x2]
debug dec x1,tab,dec x2,cr
goto loop
You can get by without the bailouts, but they become necessary if
your program has to do other tasks in addition to the serial data, or
you cannot tolerate a program lockup if the communication fails for
some reason. You can also dispense with the flow control, if the
timing is predictable or the receiver won't have to do anything but
wait for the incoming data to display.
regards,
-- Tracy
>PART 1:
>I'm looking to setup communications between two BS2P stamps using an
>RS-232 connection (SERIN and SEROUT commands). The first Stamp will have
>3 sensors connected to it and use something like the RCTIME command to
>digitize the analog input. The first Stamp then needs to send a serial
>string via the RS-232 connection to the Second Stamp. The second stamp
>needs to display the values of the 3 variables (3 sensor readings) using
>something such as DEBUG.
>
>I've been reading through the SERIN portion of the Basic Manual but it
>only seems to cover sending a single variable at a time. I would
>appreciate it if someone would show me a sample piece of code that would
>send the values of the 3 variables in a single SEROUT command, if this is
>possible (and advisable). Would this operation be called sending a
>variable as an array or a string? Book recommendations are also
>welcome.
>
>Thanks,
>Chris Dundorf
>
>
>________________________________________________________________
>GET INTERNET ACCESS FROM JUNO!
>Juno offers FREE or PREMIUM Internet access for less!
>Join Juno today! For your FREE software, visit:
>http://dl.www.juno.com/get/web/.
>
>To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
>from the same email address that you subscribed. Text in the
>Subject and Body of the message will be ignored.
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Thank you for the reply. I'm begining to follow your approach, but have
a ways to go. I'm still pretty new at the Stamp in general. Ypur
website link discusses senting P14 to high or low as for signaling
whether or not the stamps are ready to receive data. Can this scenario
work on a 3 wire RS-232 cable or on a twisted pair using RS-485?
Chris
<<>>
Date: Sat, 13 Apr 2002 21:07:19 -0700
From: Tracy Allen <tracy@e...>
Subject: Re: Sending data from 3 sensors via RS-232 to a BS2P
Here is some info on a master-slave setup using flow control:
http://www.emesystems.com/BS2rs232.htm#MasterSlave
To send data that is a full 16 bits twos complement, you can either
send two bytes per data point, or you ca use the modifiers like dec
or hex:
Using bytes
x1 var word
x2 var word
on the transmitter
loop:
gosub getx1x2 ' not shown
serout
15\14,baudmode,600,bailout,[noparse][[/noparse]x1.byte0,x1.byte1,x2.byte0,x2.byte1]
goto loop
and on the receiver
loop:
serin
15\14,baudmode,600,bailout,[noparse][[/noparse]x1.byte0,x1.byte1,x2.byte0,x2.byte1]
debug
goto loop
Using hex modifier (which xmts/rcvs 4 ascii hex bytes per variable)
loop:
gosub getx1x2 ' not shown
serout 15\14,baudmode,600,bailout,[noparse][[/noparse]hex4 x1, hex4 x2]
goto loop
and on the receiver
loop:
serin 15\14,baudmode,600,bailout,[noparse][[/noparse]hex4 x1, hex4 x2]
debug dec x1,tab,dec x2,cr
goto loop
You can get by without the bailouts, but they become necessary if
your program has to do other tasks in addition to the serial data, or
you cannot tolerate a program lockup if the communication fails for
some reason. You can also dispense with the flow control, if the
timing is predictable or the receiver won't have to do anything but
wait for the incoming data to display.
regards,
-- Tracy
>PART 1:
>I'm looking to setup communications between two BS2P stamps using an
>RS-232 connection (SERIN and SEROUT commands). The first Stamp will
have
>3 sensors connected to it and use something like the RCTIME command to
>digitize the analog input. The first Stamp then needs to send a serial
>string via the RS-232 connection to the Second Stamp. The second stamp
>needs to display the values of the 3 variables (3 sensor readings) using
>something such as DEBUG.
>
>I've been reading through the SERIN portion of the Basic Manual but it
>only seems to cover sending a single variable at a time. I would
>appreciate it if someone would show me a sample piece of code that would
>send the values of the 3 variables in a single SEROUT command, if this
is
>possible (and advisable). Would this operation be called sending a
>variable as an array or a string? Book recommendations are also
>welcome.
>
>Thanks,
>Chris Dundorf
>
>
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
http://dl.www.juno.com/get/web/.
>Thank you for the reply. I'm begining to follow your approach, but have
>a ways to go. I'm still pretty new at the Stamp in general. Ypur
>website link discusses senting P14 to high or low as for signaling
>whether or not the stamps are ready to receive data. Can this scenario
>work on a 3 wire RS-232 cable or on a twisted pair using RS-485?
>Chris
Hi Chris,
The handshake capability is built into the serin and serout command,
and that is what makes it so smooth to implement when you are trying
to make two stamps talk to one another. Be sure to read the Stamp
manual about it too, along with all the other modifiers and
capabilities of the serin and serout commands, including the "wait"
modifier.
Yes, you can do it over a 3-wire RS232 cable (common, signal1 and
signal2) between two stamps. You have great flexibility in the stamp
as to how you define signal1 and signal2 at different times. As to
RS485, you will need two twisted pairs to handle two signals.
The handshaking becomes most important when both stamps have a lot to
do besides the inter-communication.
-- Tracy