Shop OBEX P1 Docs P2 Docs Learn Events
Basic stamp - serial comms — Parallax Forums

Basic stamp - serial comms

ZetsuZetsu Posts: 186
edited 2012-07-08 13:07 in BASIC Stamp
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 ?

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-06 07:43
    I think I understand what your saying. The BasicStamp Syntax and Referance Manual has a rather large section on SERIN and SEROUT, that may help.

    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.
  • ZetsuZetsu Posts: 186
    edited 2012-07-06 08:04
    Yeah i thought about running with the prop, but i dont have the time constraints to pick up the tools i need for it. I have to get this working like a month ago lol ;x

    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
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-07-06 08:31
    Zetsu wrote: »
    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.

    Then don't use the DEC formatter.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-07-06 08:40
    If you look at the chapter on the SERIN statement, you'll see that you can receive individual characters and strings as arrays of characters. The "formatters" like DEC also have fixed length versions that don't use a terminator (like DEC3 for example).
  • stamptrolstamptrol Posts: 1,731
    edited 2012-07-06 09:10
    Provided you're not trying to work with long strings at 9600 baud or greater, the Stamp should be adaptable to your application.

    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,
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-06 09:33
    stamptrol wrote: »
    You are correct that the Stamp will wait indefinitely in some circumstances. It relates to not having any serial comm buffer.

    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?
  • davejamesdavejames Posts: 4,047
    edited 2012-07-06 11:35
    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.
  • ZetsuZetsu Posts: 186
    edited 2012-07-06 12:08
    All I am trying to do is capture a interger value from the rs-232 port of a dumb terminal... depending on integer recieved, bstamp cycles alarm buzzer on and off.. I am trying to replace some old zylog chips that were doing just this, and the guy that designed the orgional setup died. ;x So now I have to get it under control so to speak. ( we don't have orgional source etc.. etc.. )

    Thanks so far for the direction.
  • davejamesdavejames Posts: 4,047
    edited 2012-07-06 13:37
    Hey Zetsu,

    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?
  • ZetsuZetsu Posts: 186
    edited 2012-07-06 13:43
    Totally, unfortunately I cant devote any time to this for another hour. ;x I will try it out and let you know, the problem i was having though was when i would make the calls for the serin it would just set there never moving past that line of execution in the program. But I will read what you pointed out and let you guys know.

    Thanks by the way ;)
  • davejamesdavejames Posts: 4,047
    edited 2012-07-06 14:11
    ...welcome and definitely report back!

    Good luck.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-07 03:18
    Firstly, SERIN has the in depth discussion, DEBUGIN follows the same formatting rules.

    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.
  • stamptrolstamptrol Posts: 1,731
    edited 2012-07-07 04:24
    A couple of quick points.

    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,
  • ZetsuZetsu Posts: 186
    edited 2012-07-08 13:07
    Well, I might have to do this in spin with a prop after all, for some reason my windows 7 VM refuses to communicate with my stamp. ;x

    stamp on dev board, no comms... Homework board i get comms, ;x stamp went bad I guess or something.
Sign In or Register to comment.