Basic stamp - serial comms
Zetsu
Posts: 186
Anyone have a good amount of experience, with the serial communications ? I am trying to get a basic stamp to receive a non terminated string ( not on a clock as well ) via rs-232 and preform an action biased on current data sent... ( its a simple fix to a very convoluted fire alarm ).
Currently I can see that the basic stamp receives my single character, but yet it doesn't close the buffer, it just sets in a wait state waiting for any non numerical character to terminate the string with.
Did this make sense how I explained it ?
Currently I can see that the basic stamp receives my single character, but yet it doesn't close the buffer, it just sets in a wait state waiting for any non numerical character to terminate the string with.
Did this make sense how I explained it ?
Comments
Or are you using DEBUG and DEBUGIN? These are really intended to be used with Parallax's Debug Terminal in the IDE and that may be where you are finding some feature that is not working for you.
If all else fails, the Propeller is really much superior for RS232 as it can be customized to anything you want.
yeah their is a async mode and a sync mode both i referenced out of the manual the problem is one expects a clock signal ( which I don't have ) and the other expects a terminator ( which i also don't have :x )
I just want it to listen dumbly on the line and as soon as it gets any data at all it quits the listen state and then goes on into execution....
also forgot, no I am not using DEBUG and DEBUGIN
Then don't use the DEC formatter.
You are correct that the Stamp will wait indefinitely in some circumstances. It relates to not having any serial comm buffer.
Can you give us more detail on the expected serial string? It'll make any suggestions more applicable.
Cheers,
I'd been wondering about this for some time (and yes, I will reread the manual). So it seems that the BasicStamp is only going to respond as it expects a response. It can be one character at a time, or it can be waiting for a string or number of some sort. Is that correct?
Loopy - yes, correct.
In my experience, the BS needs to sit in a tight SERIN loop awaiting input, and once receiving the expected character or string, there would be code to have it hop out of the loop and service whatever the input required...then, back into the loop waiting for the next valid input.
Thanks so far for the direction.
If you're running the BASIC Stamp IDE editor v2.5.2:
- pull down the Help menu at the top of the editor
- click on the Search button in the lower left corner (don't use the "Quick Search" feature)
- enter serin and press the "Search" button (or hit the enter key)
- click on the SERIN entry
...the discussion on SERIN will be opened
- click on the SERIN Examples in the upper right corner
...some useful information resides here
The first example is basically what I was talking about. The BS sits in a tight loop, interrogating SERIN for the sting "ABCD" at every pass through the loop. When "ABCD" is recognized, the next value will be dumped into the 'result' variable.
Make sense?
Thanks by the way
Good luck.
If you want to trap specific known integers, you are going to have to do it one at a time in ASCII. The DEC format is not going to properly respond as it filters numbers out of a string of other text.
If you have a large range of numbers with different responses, it will require more code than if you are recognizing just one.
Of course, if it is a range of number with one response, that might not required too much effort.
The SERIN does provide a "timeout" value which will break the waiting cycle. But, in order to work, the serial line must stay silent. Otherwise, any activity on the serial line will keep resetting the timeout value and you'll see the endless loop feature.
Secondly, if there's any doubt as to the makeup of the expected serial string coming to the Stamp, it is often very useful to observe the incoming string using a terminal program (Hyperterminal, Procomm, etc) on the PC to be able to set the Stamp's SERIN parameters quickly and accurately.
Heres a few lines of code from my truck scale controller, showing a SERIN command:
onscal_in:
' truck is on scale waiting for one of 4 possibilities.
HIGH aldata ' turn on data to aldata
IF IN10=0 THEN printgo_in ' manual print button
IF IN12=0 OR IN13=0 THEN leave_in ' either road loop active again
IF IN11=0 THEN ok2go_in ' manual exit button
'SERIN 8, cominv,3000,onscal_in,[WAIT ("A001"),STR test\5\CR] 'wait for EOT from Scaleboss
SERIN 8, comparm,3000,onscal_out,[WAIT ("A001"),STR test\5\CR]
IF test(2)="*" THEN ok2go_in
GOTO onscal_in
Cheers,
stamp on dev board, no comms... Homework board i get comms, ;x stamp went bad I guess or something.