Navic
01-25-2010, 11:51 PM
I have a BS2px hooked up to 3 sets of IR TX/RX's that work just fine. I'm transmitting data via a serial connection to another device, and after that data is sent the BS2px waits for a received byte. Everything seems to work just fine until two of my four conditionals repeat instantly every time for no apparent reason. Here is my code:
IRL VAR Byte
IRR VAR Byte
IRF VAR Byte
ard VAR Byte
DO
GOSUB IR_Left
GOSUB IR_Right
GOSUB IR_Front
IF IRL = 0 THEN
DEBUG "Left", CR
SEROUT 0, 396, ["2"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Left", CR
ELSEIF IRR = 0 THEN
DEBUG "Right", CR
SEROUT 0, 396, ["3"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Right", CR
ELSEIF IRF = 0 THEN
DEBUG "Front", CR
SEROUT 0, 396, ["4"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Front", CR
ELSEIF (IRL = 0) AND (IRR = 0) THEN
DEBUG "Both", CR
SEROUT 0, 396, ["1"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Both", CR
ENDIF
IRF = 1
IRL = 1
IRR = 1
LOOP
END
IR_Left:
FREQOUT 7,6,6385
IRL = IN6
RETURN
IR_Right:
FREQOUT 5,6,6385
IRR = IN4
RETURN
IR_Front:
FREQOUT 15,6,6385
IRF = IN14
RETURN
Here's what I get in my debug window when this is running and the 'front' condition is met:
Front
Front
Response from Front
This happens with the 'both' condition also:
Both
Both
Response from Both
But when 'left' or 'right' conditions are met, everything works as I envisioned:
Left
Response from Left
Right
Response from Right
I've tried reordering the IF statements, setting IRR, IRL, IRF to 1 before looping (as you can see), tried adding timeout to the SERIN to jump to a label that pauses for 5 seconds, pausing randomly during the code, changing the GOSUB orders, I just can't see why 'front' and 'both' repeat readings! Every time it should wait for a response, 'left' and 'right' work fine, what is going on here??
Thanks for your help, I'm not a master programmer but I think my code is correct.... this is driving me crazy!!
IRL VAR Byte
IRR VAR Byte
IRF VAR Byte
ard VAR Byte
DO
GOSUB IR_Left
GOSUB IR_Right
GOSUB IR_Front
IF IRL = 0 THEN
DEBUG "Left", CR
SEROUT 0, 396, ["2"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Left", CR
ELSEIF IRR = 0 THEN
DEBUG "Right", CR
SEROUT 0, 396, ["3"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Right", CR
ELSEIF IRF = 0 THEN
DEBUG "Front", CR
SEROUT 0, 396, ["4"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Front", CR
ELSEIF (IRL = 0) AND (IRR = 0) THEN
DEBUG "Both", CR
SEROUT 0, 396, ["1"]
PAUSE 50
SERIN 1, 396, [WAIT("@"), ard]
DEBUG "Response from Both", CR
ENDIF
IRF = 1
IRL = 1
IRR = 1
LOOP
END
IR_Left:
FREQOUT 7,6,6385
IRL = IN6
RETURN
IR_Right:
FREQOUT 5,6,6385
IRR = IN4
RETURN
IR_Front:
FREQOUT 15,6,6385
IRF = IN14
RETURN
Here's what I get in my debug window when this is running and the 'front' condition is met:
Front
Front
Response from Front
This happens with the 'both' condition also:
Both
Both
Response from Both
But when 'left' or 'right' conditions are met, everything works as I envisioned:
Left
Response from Left
Right
Response from Right
I've tried reordering the IF statements, setting IRR, IRL, IRF to 1 before looping (as you can see), tried adding timeout to the SERIN to jump to a label that pauses for 5 seconds, pausing randomly during the code, changing the GOSUB orders, I just can't see why 'front' and 'both' repeat readings! Every time it should wait for a response, 'left' and 'right' work fine, what is going on here??
Thanks for your help, I'm not a master programmer but I think my code is correct.... this is driving me crazy!!