Shop OBEX P1 Docs P2 Docs Learn Events
Looping serin — Parallax Forums

Looping serin

leshea2leshea2 Posts: 83
edited 2006-02-18 00:04 in BASIC Stamp
Can the serin command be used in a code that loops forever ? Because this code works fine until I try to include serin in the goto forever statement.


' {$STAMP BS2sx}
' {$PBASIC 2.5}
 
YMTU    VAR     Word
GJH     VAR     Word
TGM    DATA "God Bless The World !", 0
 

Main:
SERIN 16, 16624, [noparse][[/noparse]WAIT("ready")]
GOSUB Main2
END
Main2:
YMTU = TGM
GOSUB Main3
END
Main3:
  PAUSE 20
  READ YMTU, GJH
  YMTU = YMTU + 1
  IF (GJH = 0) THEN GOTO Main2 ELSE SEROUT 16, 16624, 10, [noparse][[/noparse]GJH]
GOTO Main3
END



Thanks !

Comments

  • SteelSteel Posts: 313
    edited 2006-02-17 00:12
    It can...But the program will stop if it doesn't recieve the "ready" from the SERIN. (unless you add a timeout)

    The program will pause on that statement every loop until it recieves the "ready" string.

    ....But in your code, you are not looping the SERIN command. It looks like you are looping through Main2 and Main3 routine.

    Also... The "End" statement tells the program to end. You don't need those, since you are just going to a different sub just before it.
  • leshea2leshea2 Posts: 83
    edited 2006-02-17 00:46
    Changing [noparse][[/noparse]GOTO Main3] to [noparse][[/noparse]GOTO Main], will make the code loop the serin part forever, but then it won't execute the program even once, until I take serin out of the loop, even though my PC software is programed to send the "ready" signal every time the serin statement waits for it.

    Thanks !
  • Tom WalkerTom Walker Posts: 509
    edited 2006-02-17 14:08
    Leshea2,
    It appears that you have been working on this particular idea for a while. From reading you past posts, it appears that your Stamp is not seeing the "ready" that you believe your PC is sending...not even once...and it looks like your proposed solution is to keep looping through the SERIN hoping to "catch" it, somehow. It would probably be more productive to diagnose WHY the PC to Stamp communication is not acting why it should. It SHOULD be as simple as a simple SERIN statement that WAITs for "ready" on the Stamp side and a PC program that loops through sending "ready"...but apparently your stamp is never seeing it. The pin that you are using and the baudmode would be the first things that I would look at. After all, PC to Stamp communication is occurring millions of times daily (I exaggerate to make a point).

    In short, if it doesn't hapen the first time, it generally won't happen the billionth time if you don't change something...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-17 14:17
    Let's see:

    Apparently, you have a BS2sx (because you have that selected in your code).

    Now, the 'baudmode' value you are using is 16624. (which is $4000 + 240, or Inverted 9600 for the BS2sx).
    From the manual, that looks correct.

    It might be easier to have your BS2sx transmit every 5 seconds (with a SEROUT) to your PC, and use your PC to see that signal. That will validate that you have it connected properly.

    The problem with the SERIN is that the BS2 WILL wait forever until it gets EXACTLY what you've told it to wait for, and that can be unhelpful.

    Oh, and note you MUST put a "CR" after the 'ready' (a vbCRLF) , or the BS2 doesn't know the string has ended.
  • leshea2leshea2 Posts: 83
    edited 2006-02-18 00:04
    Can anyone give me an example of a code that loops serin endlessly, that has been tested and works ?

    The only problem I still have is that serin works by itself, but not in a loop. My PC to stamp communication works too, until I try to loop the serin statement forever.

    Thanks !
Sign In or Register to comment.