Shop OBEX P1 Docs P2 Docs Learn Events
Byte comparisons — Parallax Forums

Byte comparisons

ArchiverArchiver Posts: 46,084
edited 2000-05-23 02:25 in General Discussion
Hi List members,

I've written a program and am wondering if there is another way to compare
some ascii serial strings in order to determine values are larger or not
(for logging maximum/minimum temperatures). Typical incoming ascii serial
data for the temperature section would look like 1234 representing 12.34
degrees C. Code snippet below:

AirT var byte (4) ' air temp variable.
AtMax var byte (4) ' air temp Maximum.
AtMin var byte (4) ' air temp Minimum.
T_AtMax var byte (4) ' time for AtMax.
T_AtMin var byte (4) ' time for AtMin.

Start:
Serin 0,b24,[noparse][[/noparse]WAIT ("FF01"),STR Date\4,STR Time\4,SKIP 4,STR AirT\4]

Next1: ' Comparison routine for AtMax. Note byte 0 not used for comparison.
IF AirT(1)<AtMax(1) THEN Next2
IF AirT(1)>AtMax(1) THEN Update_AtMax
IF AirT(2)<AtMax(2) THEN Next2
IF AirT(2)>AtMax(2) OR AirT(3)>AtMax(3) THEN Update_AtMax
Goto Next2 ' This stops update if AirT(3)<AtMax(3).

Update_AtMax:
For key=0 to 3
AtMax(key)=AirT(key) ' Update temp Max.
T_AtMax(key)=Time(key) ' and time occurred.
Next

Next2: ' Comparison routine for AtMin.
IF AirT(1)>AtMin(1) THEN Next3
IF AirT(1)<AtMin(1) THEN Update_AtMin
IF AirT(2)>AtMin(2) THEN Next3
IF AirT(2)<AtMin(2) OR AirT(3)<AtMin(3) THEN Update_AtMin
Goto Next3 ' As above.

Update_AtMin:
For key=0 to 3
AtMin(key)=AirT(key)
T_AtMin(key)=Time(key)
Next


Any suggestions are welcome as always.
Regards,
Bill
W J Sherwood

\|/ ____ \|/
~@-/ oO \-@~
/_( \__/ )_\
\__U_/

Senior Technical Officer

WNI Science & Engineering
31 Bishop Street
JOLIMONT WA 6014
AUSTRALIA

http://www.wnise.com

Phone: +61 8 9387 7955 Fax: +61 8 9387 6686
E-mail: bill.sherwood@p...

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-05-23 02:25
    >I've written a program and am wondering if there is another way to compare
    >some ascii serial strings in order to determine values are larger or not
    >(for logging maximum/minimum temperatures). Typical incoming ascii serial
    >data for the temperature section would look like 1234 representing 12.34
    >degrees C. Code snippet below:
    >
    >.. snip
    > AirT var byte (4) ' air temp variable.
    > Start:
    > Serin 0,b24,[noparse][[/noparse]WAIT ("FF01"),STR Date\4,STR Time\4,SKIP 4,STR AirT\4]


    Hi Bill,

    It might work better to use the DEC4 modifier, instead of STR, to read in
    the air temperature:

    AirT var word ' air temp variable WORD.
    Serin 0,b24,[noparse][[/noparse]WAIT ("FF01"),STR Date\4,STR Time\4,SKIP 4,DEC4 AirT]
    ^^^^^^^^^

    That gives a word variable that is easy to work with. Also define the
    T_Amin and T_Amax as word variables. Then

    ' having started with T_Amin=9999 and T_Amax=0
    T_Amin=AirT max T_Amin ' update minimum
    T_Amax=AirT min T_Amax ' update maximum

    Mudh faster and shorter than updating the variables in the form of strings.

    Use the DEC4 modifier to reconstruct a string output if needed later point
    in the program.

    I hope that helps
    --Tracyu Allen
    Electronically Monitored Ecosystems
    http://www.emesystems.com
Sign In or Register to comment.