40x2 If-Then query

Hooter

Senior Member
Folks - Daft question time - I'm pulling my remaining hair out.
I have a 40x2 receiving serial in data from a proxcard reader.
This data is being received and displayed correctly using sertxd.
What I am having trouble with is the following:

Main:SERIN d.4, T9600_8, b0
if b0 = 5 then goto sendout
goto main

sendout:
sertxd (b0,13,10)
goto main

I know the first digit to be received is 5 - therefore you would expect the program to move on to sendout routine but alas it doesn't.
if I change line 2 to
if b0 <> 5 then goto sendout
it works as expected by displaying the digit 5 in the terminal screen.
So it does actually work but just in reverse order as in 'equal to' and 'not equal to'.
I have spent two nights trying to figure out what I have done wrong.
Any help would be appreciated.
Hooter
 

westaust55

Moderator
is the prox card reader wireless or hard wired?

what value are you recievnbg in variable b0?
must be something otherwise the serin will wait forever if you have no timeout parameter.

sometime you may receive some "garbage" that will be accepted as the first byte.

Consider sending some characters with a qualifier.

eg serout pin, baud rate, ("abcdef", b0)

you could even try

serout pin, baud rate, ("xxx", "abcdef", b0)

then wait for the qualifer

SERIN d.4, T9600_8, ("abcdef"), b0
 

hippy

Technical Support
Staff member
I know the first digit to be received is 5...

if I change line 2 to
if b0 <> 5 then goto sendout
it works as expected by displaying the digit 5 in the terminal screen.
It would seem that the first digit is the ASCII character "5" ( value 53, $35 ), not the binary value 5. This matches with your SERTXD of 'b0' rather than '#b0' and result seen.

Change to IF b0 = "5" THEN and I would expect everything to then work.
 

Hooter

Senior Member
Hippy - Thanks - that was indeed the problem. The sample program was different to that which I was actually using but the problem was the same. I recall making the same mistake a while back - Rem - give myself a slap.
WestAust - It was hard wired and working correctly apart from the logic reversal issue.
The module is from SonMicro
http://www.sonmicro.com/en/index.php?option=com_content&view=article&id=46&Itemid=64
RS232/Wiegand/I2c comms and realistically priced too.
Thanks again guys.
Hooter
 

hippy

Technical Support
Staff member
Not being able to see the wood for the trees is not uncommon and when hindsight shows what's wrong and how one misled themself it's a familiar D'Oh! moment.

Best way to approach these issues is to put a SERTXD(#b0) immediately after a command which receives input, or show all bits of the received value SERTXD(#bit7,...,#bit0).

My most common mistake ( though I usually remember to check for it now ) is to use -

SerIn pin, baud, ( b0 )
 
Top