Shop OBEX P1 Docs P2 Docs Learn Events
BS2p24 SERIN Command — Parallax Forums

BS2p24 SERIN Command

Mike CookMike Cook Posts: 829
edited 2004-08-25 19:23 in BASIC Stamp

Quick Question...

I'm using a BS2p24 (v1.3) to detect the ASCII 'RING' from a modem. I'm using the Timeout, Tlabel , and InputData modifiers with the SERIN command. Below is the exact statement that I'm using:

SERIN ModemXmit, ModemBaud, SerialTimeOut, No_Ring_Detected, [noparse][[/noparse]WAIT("RING")]

I have the SerialTimeOut constant defined for 900, according to the online help file in the Basic Stamp IDE, it states:

"Timeout is an optional variable/constant/expression* (0 - 65535) that tells SERIN how long to wait for incoming data. If data does not arrive in time, the program will jump to the address specified by Tlabel."

Later down in the help file there is an example with the value of 2000 for this Timeout modifier, in the text that explains the example is says:

"If no data arrives within two seconds, the program aborts SERIN and continues at the label No_Data"

According to this statement that would lead me to believe that the Timeout modifier value is x * milliseconds, so in my program I have this modifier set for 900, which leads me to believe this line of code that I've written above should wait for 900 mS, and abort if no serial data is received.

I've attached my code, and I've got a subroutine that counts the number of times that the SERIN "times out". If it "times out" 15 times it clears the debug window and begins to wait for rings again.

While testing this program it seems to me that the debug window should clear about every 13 1/2 seconds, however in practice the debug window will clear every 3 to 4 seconds.

Now for the question(s): Is the Timeout modifier for the SERIN command in milliseconds and the same for all the Basic Stamp 2 Family?

Thanks for your time,

Mike



P.S. It seems that my program is working the way I want it to, however the timeout value to clear the debug window is happening about 1/3 to 1/4 of the time quicker than what I've programmed it for when I'm not receiving anything from the modem.

Comments

  • JonathanJonathan Posts: 1,023
    edited 2004-08-25 01:22
    Mike,

    The 2p uses .75 mS per count on the SERIN timeout. I got nailed by that a while back. The help file with the editor has all the timing specs for the Stamp family.

    Jonathan

    www.madlabs.info



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Mike CookMike Cook Posts: 829
    edited 2004-08-25 01:28
    Thanks,

    I new I must have been missing something! Is that information in the online help file in the Basic Stamp IDE (I can't seem to find it, in the IDE)·or is it in the *.pfd documentation about the Basic Stamp Family?

    I would like to add these differences·to my "Conditional Compilation Directives" section of my program.

    Thanks Again,

    Mike




    Post Edited (Mike Cook) : 8/25/2004 1:44:53 AM GMT
  • Mike CookMike Cook Posts: 829
    edited 2004-08-25 01:50
    I found IT!, Amazing what happens when you actually READ the documentation. It appears to be 400 µs for the BS2p24, makes perfect since now.

    Mike
  • Harry StonerHarry Stoner Posts: 54
    edited 2004-08-25 15:12
    I got burned on this too. Do yourself a favor and create conditional constants for ALL timing parameters that vary, e.g. baud rates, serin wait times, pulsout time units, etc. Otherwise you will forget and get burned again down the road.

    Harry
  • Mike CookMike Cook Posts: 829
    edited 2004-08-25 17:22
    Yup, that's the idea. I normally use a standard program template when I'm coding, to save time, however I got tripped up on that feature of SERIN for the BS2p24. And even after reading the online help file in the IDE, I kept missing the BIG "Quick Facts" box in the SERIN help page! Maybe I shouldn't code after a 12 hour day at work!

    Thanks to everyone!

    Mike
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2004-08-25 19:23
    For the record, I wanted to point out that there is a little bug in the SERIN command that can trip you up if you are doing a tight loop with hardware flow control. This is the SERIN command with flow control:
    SERIN dpin\fpin,baudmode,timeout, [noparse][[/noparse]stuff]

    When the program hits this command, the fpin is supposed to go to the "ready" state, and the SERIN command waits up to the period of "timeout" for a start bit. You might have two Stamps hooked together, one doing a time-critical task, and when it hits the SERIN you only want it to receive data if the other device is there already and responds immediately when fpin goes to "ready". The Stamp is great for that when the other device has its fpin linked to a SEROUT command with a longer timeout.

    You might be tempted to set SERIN timeout=1 to get the fastest possible response.

    However, if you make timeout=1, the fpin _never_ goes to "ready". So you don't get the data from the other device. If you make timeout=2, then the fpin will be at "ready" for one timeout period, etc. That is, there seems to be an off-by-one bug where the timeout and \fpin are combined.

    I had found that after tripping over it a couple of years ago on the BS2. But it is also true on the BS2pe and I presume so on the other Stamps, too.

    Jon, could you check that out and maybe put a note in the online Help file (for people to READ!)

    -- Tracy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.