Handling Serial Strings
Archiver
Posts: 46,084
I have a serial string that I want to test (IF..Then) and then light
a led.
The strings are obtainied via a looped serial request ('serout' from
the STAMP chip) to a radio receiver and read into a variable by the
STAMP 'serin' command resulting, for example, in the data
string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
tuned to differnt frequencies the looped serial request obtains the
next frequency string. The second string may be "FA0000299900"
(corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
(Variable Frequency Oscillator)in the receiver thus plays no role in
the data evaluation. My code apparently sends the right request and
captures the serial data from the radio as it matches the data format
as seen in the receiver specification.
I would like to test these continuous strings as they're being
generated by the VFO every 100 milliseconds. I will only need to
sample every 2 seconds. I need to know when the frequency is in
between 2.8MHZ and 2.999MHZ to light a led. If the string test fails
(below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
I just don't know how to handle strings (and any conversions) to test
them for a lower and upper limit.
Thanks in advance
Jay
a led.
The strings are obtainied via a looped serial request ('serout' from
the STAMP chip) to a radio receiver and read into a variable by the
STAMP 'serin' command resulting, for example, in the data
string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
tuned to differnt frequencies the looped serial request obtains the
next frequency string. The second string may be "FA0000299900"
(corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
(Variable Frequency Oscillator)in the receiver thus plays no role in
the data evaluation. My code apparently sends the right request and
captures the serial data from the radio as it matches the data format
as seen in the receiver specification.
I would like to test these continuous strings as they're being
generated by the VFO every 100 milliseconds. I will only need to
sample every 2 seconds. I need to know when the frequency is in
between 2.8MHZ and 2.999MHZ to light a led. If the string test fails
(below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
I just don't know how to handle strings (and any conversions) to test
them for a lower and upper limit.
Thanks in advance
Jay
Comments
data var byte(6)
by doing this you can check byte(1) would be 00
byte(2) would be 99
byte(3) would be 29
ect
byte (6) would be FA
now you can check each byte as needed
Jay Kobelin wrote:
>
> I have a serial string that I want to test (IF..Then) and then light
> a led.
>
> The strings are obtainied via a looped serial request ('serout' from
> the STAMP chip) to a radio receiver and read into a variable by the
> STAMP 'serin' command resulting, for example, in the data
> string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
> tuned to differnt frequencies the looped serial request obtains the
> next frequency string. The second string may be "FA0000299900"
> (corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
> (Variable Frequency Oscillator)in the receiver thus plays no role in
> the data evaluation. My code apparently sends the right request and
> captures the serial data from the radio as it matches the data format
> as seen in the receiver specification.
>
> I would like to test these continuous strings as they're being
> generated by the VFO every 100 milliseconds. I will only need to
> sample every 2 seconds. I need to know when the frequency is in
> between 2.8MHZ and 2.999MHZ to light a led. If the string test fails
> (below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
>
> I just don't know how to handle strings (and any conversions) to test
> them for a lower and upper limit.
>
> Thanks in advance
>
> Jay
data var byte(5)
AND START WITH 0 THEN GOES TO 5
LarryGaminde wrote:
>
> try using a variable like
> data var byte(6)
> by doing this you can check byte(1) would be 00
> byte(2) would be 99
> byte(3) would be 29
> ect
> byte (6) would be FA
> now you can check each byte as needed
>
> Jay Kobelin wrote:
> >
> > I have a serial string that I want to test (IF..Then) and then light
> > a led.
> >
> > The strings are obtainied via a looped serial request ('serout' from
> > the STAMP chip) to a radio receiver and read into a variable by the
> > STAMP 'serin' command resulting, for example, in the data
> > string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
> > tuned to differnt frequencies the looped serial request obtains the
> > next frequency string. The second string may be "FA0000299900"
> > (corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
> > (Variable Frequency Oscillator)in the receiver thus plays no role in
> > the data evaluation. My code apparently sends the right request and
> > captures the serial data from the radio as it matches the data format
> > as seen in the receiver specification.
> >
> > I would like to test these continuous strings as they're being
> > generated by the VFO every 100 milliseconds. I will only need to
> > sample every 2 seconds. I need to know when the frequency is in
> > between 2.8MHZ and 2.999MHZ to light a led. If the string test fails
> > (below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
> >
> > I just don't know how to handle strings (and any conversions) to test
> > them for a lower and upper limit.
> >
> > Thanks in advance
> >
> > Jay
I retrieve the data from the radio via "serin" as follows:
====================================
DATA1 VAR BYTE(14)
DATA1(13)=0
SERIN 1, 16572,[noparse][[/noparse]STR DATA1\13\"*"]
DEBUG STR DATA1
=====================================
..and the value 'FA00002999000' is streamed out every .2 to .5 secs
When I reduced DATA1 in 'serin' to BYTE(10),
I get the value 'FA00002999'
So it looks like I can trim the data in DATA1 but it trims from right to
left
How do I read each individual byte so I can see it via debug and use it
later for limit comparisons?
How would I get rid of the FA leader? I am thinking of trying the SKIP in
'serin' by looking for 'FA'
I'm not a programmer so bear with me...
Thanks
Jay
Original Message
From: LarryGaminde <lgaminde@t...>
To: <basicstamps@egroups.com>
Sent: Monday, October 02, 2000 2:30 AM
Subject: Re: [noparse][[/noparse]basicstamps] Handling Serial Strings
> I made a booboo
>
> data var byte(5)
>
> AND START WITH 0 THEN GOES TO 5
>
> LarryGaminde wrote:
> >
> > try using a variable like
> > data var byte(6)
> > by doing this you can check byte(1) would be 00
> > byte(2) would be 99
> > byte(3) would be 29
> > ect
> > byte (6) would be FA
> > now you can check each byte as needed
> >
> > Jay Kobelin wrote:
> > >
> > > I have a serial string that I want to test (IF..Then) and then light
> > > a led.
> > >
> > > The strings are obtainied via a looped serial request ('serout' from
> > > the STAMP chip) to a radio receiver and read into a variable by the
> > > STAMP 'serin' command resulting, for example, in the data
> > > string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
> > > tuned to differnt frequencies the looped serial request obtains the
> > > next frequency string. The second string may be "FA0000299900"
> > > (corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
> > > (Variable Frequency Oscillator)in the receiver thus plays no role in
> > > the data evaluation. My code apparently sends the right request and
> > > captures the serial data from the radio as it matches the data format
> > > as seen in the receiver specification.
> > >
> > > I would like to test these continuous strings as they're being
> > > generated by the VFO every 100 milliseconds. I will only need to
> > > sample every 2 seconds. I need to know when the frequency is in
> > > between 2.8MHZ and 2.999MHZ to light a led. If the string test fails
> > > (below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
> > >
> > > I just don't know how to handle strings (and any conversions) to test
> > > them for a lower and upper limit.
> > >
> > > Thanks in advance
> > >
> > > Jay
>
>
>
>
what each byte is
debug data1(0)
through
debug data1(13)
this will show each byte and then you can see what you can use
Jay Kay wrote:
>
> Thanks Larry..but I'm really thick about doing some of this.
> I retrieve the data from the radio via "serin" as follows:
> ====================================
> DATA1 VAR BYTE(14)
> DATA1(13)=0
> SERIN 1, 16572,[noparse][[/noparse]STR DATA1\13\"*"]
> DEBUG STR DATA1
> =====================================
> ..and the value 'FA00002999000' is streamed out every .2 to .5 secs
>
> When I reduced DATA1 in 'serin' to BYTE(10),
> I get the value 'FA00002999'
>
> So it looks like I can trim the data in DATA1 but it trims from right to
> left
> How do I read each individual byte so I can see it via debug and use it
> later for limit comparisons?
> How would I get rid of the FA leader? I am thinking of trying the SKIP in
> 'serin' by looking for 'FA'
>
> I'm not a programmer so bear with me...
> Thanks
> Jay
>
>
Original Message
> From: LarryGaminde <lgaminde@t...>
> To: <basicstamps@egroups.com>
> Sent: Monday, October 02, 2000 2:30 AM
> Subject: Re: [noparse][[/noparse]basicstamps] Handling Serial Strings
>
> > I made a booboo
> >
> > data var byte(5)
> >
> > AND START WITH 0 THEN GOES TO 5
> >
> > LarryGaminde wrote:
> > >
> > > try using a variable like
> > > data var byte(6)
> > > by doing this you can check byte(1) would be 00
> > > byte(2) would be 99
> > > byte(3) would be 29
> > > ect
> > > byte (6) would be FA
> > > now you can check each byte as needed
> > >
> > > Jay Kobelin wrote:
> > > >
> > > > I have a serial string that I want to test (IF..Then) and then light
> > > > a led.
> > > >
> > > > The strings are obtainied via a looped serial request ('serout' from
> > > > the STAMP chip) to a radio receiver and read into a variable by the
> > > > STAMP 'serin' command resulting, for example, in the data
> > > > string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
> > > > tuned to differnt frequencies the looped serial request obtains the
> > > > next frequency string. The second string may be "FA0000299900"
> > > > (corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
> > > > (Variable Frequency Oscillator)in the receiver thus plays no role in
> > > > the data evaluation. My code apparently sends the right request and
> > > > captures the serial data from the radio as it matches the data format
> > > > as seen in the receiver specification.
> > > >
> > > > I would like to test these continuous strings as they're being
> > > > generated by the VFO every 100 milliseconds. I will only need to
> > > > sample every 2 seconds. I need to know when the frequency is in
> > > > between 2.8MHZ and 2.999MHZ to light a led. If the string test fails
> > > > (below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
> > > >
> > > > I just don't know how to handle strings (and any conversions) to test
> > > > them for a lower and upper limit.
> > > >
> > > > Thanks in advance
> > > >
> > > > Jay
> >
> >
> >
> >
After about 8 hours I got the program doing what is needed..once I got going
it started making sense.
When I got done I needed only to look at 2 bytes to guide the control
circuitry...neat little device this stamp..and it handles serial data pretty
darn good
Thanks for your support
Jay
Original Message
From: LarryGaminde <lgaminde@t...>
To: <basicstamps@egroups.com>
Sent: Tuesday, October 03, 2000 8:19 AM
Subject: Re: [noparse][[/noparse]basicstamps] Handling Serial Strings
> What you are doing is good now put 13 debugs in your program and see
> what each byte is
>
> debug data1(0)
> through
> debug data1(13)
> this will show each byte and then you can see what you can use
>
> Jay Kay wrote:
> >
> > Thanks Larry..but I'm really thick about doing some of this.
> > I retrieve the data from the radio via "serin" as follows:
> > ====================================
> > DATA1 VAR BYTE(14)
> > DATA1(13)=0
> > SERIN 1, 16572,[noparse][[/noparse]STR DATA1\13\"*"]
> > DEBUG STR DATA1
> > =====================================
> > ..and the value 'FA00002999000' is streamed out every .2 to .5 secs
> >
> > When I reduced DATA1 in 'serin' to BYTE(10),
> > I get the value 'FA00002999'
> >
> > So it looks like I can trim the data in DATA1 but it trims from right to
> > left
> > How do I read each individual byte so I can see it via debug and use it
> > later for limit comparisons?
> > How would I get rid of the FA leader? I am thinking of trying the SKIP
in
> > 'serin' by looking for 'FA'
> >
> > I'm not a programmer so bear with me...
> > Thanks
> > Jay
> >
> >
Original Message
> > From: LarryGaminde <lgaminde@t...>
> > To: <basicstamps@egroups.com>
> > Sent: Monday, October 02, 2000 2:30 AM
> > Subject: Re: [noparse][[/noparse]basicstamps] Handling Serial Strings
> >
> > > I made a booboo
> > >
> > > data var byte(5)
> > >
> > > AND START WITH 0 THEN GOES TO 5
> > >
> > > LarryGaminde wrote:
> > > >
> > > > try using a variable like
> > > > data var byte(6)
> > > > by doing this you can check byte(1) would be 00
> > > > byte(2) would be 99
> > > > byte(3) would be 29
> > > > ect
> > > > byte (6) would be FA
> > > > now you can check each byte as needed
> > > >
> > > > Jay Kobelin wrote:
> > > > >
> > > > > I have a serial string that I want to test (IF..Then) and then
light
> > > > > a led.
> > > > >
> > > > > The strings are obtainied via a looped serial request ('serout'
from
> > > > > the STAMP chip) to a radio receiver and read into a variable by
the
> > > > > STAMP 'serin' command resulting, for example, in the data
> > > > > string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
> > > > > tuned to differnt frequencies the looped serial request obtains
the
> > > > > next frequency string. The second string may be "FA0000299900"
> > > > > (corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
> > > > > (Variable Frequency Oscillator)in the receiver thus plays no role
in
> > > > > the data evaluation. My code apparently sends the right request
and
> > > > > captures the serial data from the radio as it matches the data
format
> > > > > as seen in the receiver specification.
> > > > >
> > > > > I would like to test these continuous strings as they're being
> > > > > generated by the VFO every 100 milliseconds. I will only need to
> > > > > sample every 2 seconds. I need to know when the frequency is in
> > > > > between 2.8MHZ and 2.999MHZ to light a led. If the string test
fails
> > > > > (below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
> > > > >
> > > > > I just don't know how to handle strings (and any conversions) to
test
> > > > > them for a lower and upper limit.
> > > > >
> > > > > Thanks in advance
> > > > >
> > > > > Jay
> > >
> > >
> > >
> > >
>
>
>
>
Is there a way to evaluate 2 bytes at a time?
If data(1) =53 and data(2)=55, is there a way to evaluate the 2 data words
in one step and, without using the 'IF..Then', logically compare the
"combined" 2 bytes?
There are math limits when one does it one byte at a time
Example
data(1)= 53 (5 ASCII)
data(2)=55 (7 ASCII)
Is there a way to do something like either the following
a) if data(1,2)=57 Then RUNSUB
a) if data(1,2)=(dec 57) Then RUNSUB
or something in that light. Evaluating 2 bytes at a time would be much
better and more significant than the broad math inference of using one byte
at a time
Thanks in advance
Jay
aWord var word
byte1 var aWord.highbyte
byte0 var aWord.lowbyte
Serin xx,yy,[noparse][[/noparse]byte1,byte0]
if aWord=$4142 then gotAB ' got AB input
There are a few things to look at though. Your example is 57. If you write:
byte1 var byte
serin xx,yy,[noparse][[/noparse]dec byte1]
if byte1=57 then do57
byte1 can hold from 0 to 255. If you really want 2 digits, use dec2 instead
of dec.
If you want more, use a word:
word1 var word
serin xx,yy,[noparse][[/noparse]dec word1]
if word1=57 then fly
word1 can go from 0 to 65K.
So there are several answers to your question. Use the dec modifier to
convert the ASCII characters into binary within the SERIN command, or read
two bytes into 1 word and compare the word. The dec trick won't work if you
want to look at two letters (XY, etc.) but it will work with numbers.
Does that help?
Regards,
Al Williams
AWC
*Floating point math for the Stamp, PIC, SX, or any microcontroller
http://www.al-williams.com/awce/pak1.htm
>
Original Message
> From: Jay Kay [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=6wdP1djPx36VV4Ab7YKbEW3CDUfge_iwBb_dR-ybEsqjHGFHdFlZjFDy12gdx1xNmn6PxbyfjvcA0n6MUcc]pcb4u@e...[/url
> Sent: Wednesday, October 04, 2000 9:51 AM
> To: basicstamps@egroups.com
> Subject: Re: [noparse][[/noparse]basicstamps] Handling Serial Strings
>
>
> One last question....this could really cut down on my code.
>
> Is there a way to evaluate 2 bytes at a time?
> If data(1) =53 and data(2)=55, is there a way to evaluate the 2 data words
> in one step and, without using the 'IF..Then', logically compare the
> "combined" 2 bytes?
> There are math limits when one does it one byte at a time
>
>One last question....this could really cut down on my code.
>
>Is there a way to evaluate 2 bytes at a time?
>If data(1) =53 and data(2)=55, is there a way to evaluate the 2 data words
>in one step and, without using the 'IF..Then', logically compare the
>"combined" 2 bytes?
>There are math limits when one does it one byte at a time
>
>Example
>
>data(1)= 53 (5 ASCII)
>data(2)=55 (7 ASCII)
>
>Is there a way to do something like either the following
>
>a) if data(1,2)=57 Then RUNSUB
>a) if data(1,2)=(dec 57) Then RUNSUB
>
>or something in that light. Evaluating 2 bytes at a time would be much
>better and more significant than the broad math inference of using one byte
>at a time
Try something like this:
work var word
work = 0
work = work + data(1) 'Load first byte (work = 0)
work = work+work<<8 'Shift to high byte
work = work+data(2) 'Add in low byte
IF work = whatever then go_some_where
>Thanks in advance
Yup
>Jay
Bruce Bates
hours is quick work.
Jay Kay wrote:
>
> Larry,
>
> After about 8 hours I got the program doing what is needed..once I got going
> it started making sense.
> When I got done I needed only to look at 2 bytes to guide the control
> circuitry...neat little device this stamp..and it handles serial data pretty
> darn good
>
> Thanks for your support
>
> Jay
>
>
Original Message
> From: LarryGaminde <lgaminde@t...>
> To: <basicstamps@egroups.com>
> Sent: Tuesday, October 03, 2000 8:19 AM
> Subject: Re: [noparse][[/noparse]basicstamps] Handling Serial Strings
>
> > What you are doing is good now put 13 debugs in your program and see
> > what each byte is
> >
> > debug data1(0)
> > through
> > debug data1(13)
> > this will show each byte and then you can see what you can use
> >
> > Jay Kay wrote:
> > >
> > > Thanks Larry..but I'm really thick about doing some of this.
> > > I retrieve the data from the radio via "serin" as follows:
> > > ====================================
> > > DATA1 VAR BYTE(14)
> > > DATA1(13)=0
> > > SERIN 1, 16572,[noparse][[/noparse]STR DATA1\13\"*"]
> > > DEBUG STR DATA1
> > > =====================================
> > > ..and the value 'FA00002999000' is streamed out every .2 to .5 secs
> > >
> > > When I reduced DATA1 in 'serin' to BYTE(10),
> > > I get the value 'FA00002999'
> > >
> > > So it looks like I can trim the data in DATA1 but it trims from right to
> > > left
> > > How do I read each individual byte so I can see it via debug and use it
> > > later for limit comparisons?
> > > How would I get rid of the FA leader? I am thinking of trying the SKIP
> in
> > > 'serin' by looking for 'FA'
> > >
> > > I'm not a programmer so bear with me...
> > > Thanks
> > > Jay
> > >
> > >
Original Message
> > > From: LarryGaminde <lgaminde@t...>
> > > To: <basicstamps@egroups.com>
> > > Sent: Monday, October 02, 2000 2:30 AM
> > > Subject: Re: [noparse][[/noparse]basicstamps] Handling Serial Strings
> > >
> > > > I made a booboo
> > > >
> > > > data var byte(5)
> > > >
> > > > AND START WITH 0 THEN GOES TO 5
> > > >
> > > > LarryGaminde wrote:
> > > > >
> > > > > try using a variable like
> > > > > data var byte(6)
> > > > > by doing this you can check byte(1) would be 00
> > > > > byte(2) would be 99
> > > > > byte(3) would be 29
> > > > > ect
> > > > > byte (6) would be FA
> > > > > now you can check each byte as needed
> > > > >
> > > > > Jay Kobelin wrote:
> > > > > >
> > > > > > I have a serial string that I want to test (IF..Then) and then
> light
> > > > > > a led.
> > > > > >
> > > > > > The strings are obtainied via a looped serial request ('serout'
> from
> > > > > > the STAMP chip) to a radio receiver and read into a variable by
> the
> > > > > > STAMP 'serin' command resulting, for example, in the data
> > > > > > string "FA0000280000" corresponding to 2.8MHZ. As the receiver is
> > > > > > tuned to differnt frequencies the looped serial request obtains
> the
> > > > > > next frequency string. The second string may be "FA0000299900"
> > > > > > (corresponding to 2.999MHZ). The "FA" indicates it's from VFO A
> > > > > > (Variable Frequency Oscillator)in the receiver thus plays no role
> in
> > > > > > the data evaluation. My code apparently sends the right request
> and
> > > > > > captures the serial data from the radio as it matches the data
> format
> > > > > > as seen in the receiver specification.
> > > > > >
> > > > > > I would like to test these continuous strings as they're being
> > > > > > generated by the VFO every 100 milliseconds. I will only need to
> > > > > > sample every 2 seconds. I need to know when the frequency is in
> > > > > > between 2.8MHZ and 2.999MHZ to light a led. If the string test
> fails
> > > > > > (below 2.8MHZ or above 2.999MHZ), the LED will be shut off.
> > > > > >
> > > > > > I just don't know how to handle strings (and any conversions) to
> test
> > > > > > them for a lower and upper limit.
> > > > > >
> > > > > > Thanks in advance
> > > > > >
> > > > > > Jay
> > > >
> > > >
> > > >
> > > >
> >
> >
> >
> >