wait loop
damion
Posts: 39
Hello out there,
So I'm trying to get a bs2p to wait in a loop until given the signal from another bs2p. Do I need to do this using shiftin/shiftout or...well I'm kind of at a loss. I've tried using serin/serout it didn't seem to work. Any advice?
Thanks
So I'm trying to get a bs2p to wait in a loop until given the signal from another bs2p. Do I need to do this using shiftin/shiftout or...well I'm kind of at a loss. I've tried using serin/serout it didn't seem to work. Any advice?
Thanks
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Stamp1 sends a high pulse or holds the line high for say 10mS giving stamp2 time to read the input if it is only checking the input every 5ms or so. This would allow stamp2 to be processing other data and only check for input at specific times. (Another microprocessor might use interrupts to automatically read the input ans switch to an input routine, still other microprocessors with dedicated hardware serial communications could just process information in the background storing information in a buffer and checking periodically if there was any data to process.)
stamp2 reads the high signal, jumps to the input routine and waits for the signal to go low
stamp1 releases the line by setting its pin back to input and waits for a response from stamp2
stamp2 sends a high pulse and stamp1 initiates serial input while stamp2 initiates serial output
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
DO : LOOP UNTIL IN0 = 1
This waits until P0 goes HIGH. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
The SERIN command can also be configured to wait for specified data before it retrieves any additional input. For example, suppose a device that is attached to the BASIC Stamp is known to send many different sequences of data, but the only data you desire happens to appear right after the unique characters, "XYZ". The BS1 has optional Qualifier arguments for this purpose. On the BS2, BS2e, BS2sx, BS2p, and BS2pe a special formatter called WAIT can be used for this.
sData VAR ByteMain: SERIN 1, 16780, [noparse][[/noparse]WAIT("XYZ"), DEC sData] END
The above code waits for the characters "X", "Y" and "Z" to be received, in that order, and then it looks for a decimal number to follow. If the device in this example were to send the characters "XYZ100" followed by a carriage return or some other non-decimal numeric character, the sData variable would end up with the number 100 after the SERIN line finishes. If the device sent some data other than "XYZ" followed by a number, the BASIC Stamp would continue to wait at the SERIN command.
The method you tried, using SEROUT/SERIN with or without a flow control pin should also work. What did you try with that and what else are the two programs doing in terms of program flow?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Tracy,
I tried using the serout/serin something like this:
this is the waiting stamp as far as program flow it just waits in this loop
DO
'SEROUT txd,bd, [noparse][[/noparse]"Enter password ---> "]
SERIN 2,9600, [noparse][[/noparse]waitSTR userEntry \3] ' Get user input password.
FOR index = 0 TO 3 ' Check array against DATA
READ Password + index, Bytedata1 ' Get next password char
IF Bytedata1 <> userEntry(index) THEN EXIT ' Compare to user input,
NEXT ' exit if not equal.
IF index <> 3 THEN ' If exit, then index not equal to 3
' and pass is not correct.
SEROUT 16,9600, [noparse][[/noparse]CLS,"Password not correct.", CR] ' Clear user input from screen
ENDIF
LOOP UNTIL index = 3
SEROUT 16,9600, [noparse][[/noparse]"Password is correct.", CR]
this is the stamp that gives the command this stamp asks for a user input. Once the input is entered it goes off and runs through other programs.
What I've done so far is send "WCC" as a serout statement. I think propably I need to send [noparse][[/noparse]STR userEntry \3].
Check_Password:
DO
SEROUT txd,bd, [noparse][[/noparse]"Enter password ---> "] ' User instructions.
SERIN 16,bd, [noparse][[/noparse]STR userEntry \3] ' Get user input password.
FOR index = 0 TO 3 ' Check array against DATA
READ Password + index, Bytedata1 ' Get next password char
IF Bytedata1 <> userEntry(index) THEN EXIT ' Compare to user input,
NEXT ' exit if not equal.
IF index <> 3 THEN ' If exit, then index not equal to 3
' and pass is not correct.
SEROUT txd,bd, [noparse][[/noparse]CLS,"Password not correct.", CR] ' Clear user input from screen
ENDIF
LOOP UNTIL index = 3 ' Only get out of loop when index = 3.
' Clear user input from screen
SEROUT txd,bd, [noparse][[/noparse]"Password is correct.", CR] ' Program can move on when
SEROUT 12,bd, [noparse][[/noparse]"WCC"]
PAUSE 500
' GOSUB MissionStart ' password is correct.
RETURN
I think you are using the WAITSTR incorrectly and making unecessary work for yourself. The WAITSTR itself checks the incoming data against an array that already exists, so there is no need for in your program for a loop to "check array against DATA". To start with, try a simple fixed password on the receiving side like this:
That might be sufficient, to have a hard coded password. The program does not get past the SERIN until it receives the WCC. But if your program does nees a variable password, then here is the syntax:
Again, it won't get past the serin until it receives the "WCC". But the password is no longer hard coded and can be changed by changing the contents of the userentry array.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com