Shop OBEX P1 Docs P2 Docs Learn Events
Serin Question — Parallax Forums

Serin Question

ArchiverArchiver Posts: 46,084
edited 2004-05-10 16:41 in General Discussion
On 12 Dec 00 at 8:37, daniel.d.dangremond@j... wrote:

>
> ...the timer manufacturer have told me the serial data from the
> timer is:
> 1200 baud
> 8 data bits
> N no parity
> 1 stop bit
> A string of data is sent once every second and should look like:
> # 000000
> # 000100
> # 000200
> The two rightmost digits are left at 00 (tenths and hundredths)
> until a finish time is sent...

Try something like:

seconds VAR WORD
tenths VAR NIB
hundredths VAR NIB

again:
SERIN 0,17197,[noparse][[/noparse]WAIT "# ",DEC4 seconds,DEC1 tenths,DEC1 hundredths]
DEBUG CR,DEC seconds,".",DEC tenths,DEC hundredths
GOTO again

The WAIT modifier gets the SERIN statement sync'ed up with the data
stream. The DECn modifiers tell your Stamp how many ASCII digits to
read and store as values in the respective variables. See the user
manual for more detail on each.


Steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-12-12 13:37
    Here's a question for all you serial experts. I am relatively new to
    stamps and still confused after reading the manual concerning the SERIN
    command. I have a bs2 and am trying to read the serial data from an
    'off-the-shelf' race timer. The nice people from the timer manufacturer
    have told me the serial data from the timer is:
    1200 baud
    8 data bits
    N no parity
    1 stop bit
    A string of data is sent once every second and should look like:
    # 000000
    # 000100
    # 000200
    The two rightmost digits are left at 00 (tenths and hundredths) until a
    finish time is sent.
    The code I have had the most luck with is:

    serData var byte
    again
    Serin 0,17197,[noparse][[/noparse]dec serData]
    debug dec serData
    goto again

    But all I get is a jumble of data in the debug screen. I am getting data
    so I think I have everything hooked up right. Please point me in the
    proper direction. My end goal is to take the data and output it to a large
    led display. For now, I would be happy to get the proper data in. Thanks
    in advance! Dan
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-03 23:36
    Hi,

    Unfortunately there is no OR mechanism in the wait, i.e wait ("1" or "2")
    You need a unique sequence to trigger the serin caption.
    Observing your data you could wait for the 2 leading zero's, i.e wait
    ("0","0")
    and thebn read in 5 digits.
    Test the first digit, if it "1" goto X, if it is "2" goto Y, otherwise do
    nothing.

    Or read in a decimal value and test for <9999, and for >10000 and <19999,
    and for >20000 and <29999, and for >30000

    x var word
    y var word
    value var word

    serin pin,baud,[noparse][[/noparse]dec value]
    branch value/10000,[noparse][[/noparse]nop,label1,label2]
    nop:

    label1: 'read the "1"
    X=value

    label2: 'read the "2"
    Y=value

    Regards peter


    Oorspronkelijk bericht
    Van: daniel.d.dangremond@j... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=3ZLdhqlSl3fwLIJaej-eTT_lQvFnPWftHml7aWkR58ss4HCQR18HG3zGVHW1J43rdFq1fep6EKMPR6kalVBTXlfSLj0]daniel.d.dangremond@j...[/url
    Verzonden: maandag 2 december 2002 18:15
    Aan: basicstamps@yahoogroups.com
    Onderwerp: [noparse][[/noparse]basicstamps] Serin question

    I am trying to filter in serial data using the 'wait' modifier with
    'serin'. Is there a way to look for two possible senarios in a serial
    string?

    i.e. looking for the "1" in <0010034 > then goto "X" or looking for the
    "2" in <0020034> then goto "Y".
    0000032 ignore
    0020034 store value in "Y"
    0000037 ignore
    0010035 store value in "X" ....

    I can't seem to find a way to look for two different variables in a single
    serin command. Any suggestions?


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-19 18:13
    hi, i am new at programing Stamp2sx. i am tring to conect a PC to my BS2sx and
    send ascii characters, but when i debug it its shows strange characters that its
    has nothing to do with ascii. please help.
    thanks
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-19 18:37
    Can you post your code?

    If you are trying to get decimal numbers in ASCII you need the dec
    modifier. So:

    X=7
    Debug x ' prints ASCII 7 which is a bell character
    Debug dec x ' print "7" which is probably what you want.

    That could be your problem.

    Al Williams
    AWC
    * Easy RS-232 Prototyping
    http://www.al-williams.com/awce/rs1.htm



    >
    Original Message
    > From: oscarg@v... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=HJPxYkatuoF_HxdKgMIwC8BNK7AyrxmkBr5wlO8z_BX3xPGeeN2utpMH4fVMPUm-WmkYsNQ]oscarg@v...[/url
    > Sent: Sunday, May 19, 2002 12:13 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] serin question
    >
    >
    > hi, i am new at programing Stamp2sx. i am tring to conect a
    > PC to my BS2sx and send ascii characters, but when i debug it
    > its shows strange characters that its has nothing to do with
    > ascii. please help. thanks
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-19 19:58
    thanks for the tip but unfortunaly that is not my probrem. I am sending a frame
    of data with ascii control characters and open data, but the stamp debugs
    charactes like Ĉ#ĬĂǏ
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-20 06:26
    Are you using the debug screen in the Windows editor to monitor your
    output or some other terminal program? It matters because some terminal
    progs, such as HyperTERMINAL, have an internal setting that changes how it
    deals with ASCII characters.
    Don
    Original Message
    From: <oscarg@v...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, May 19, 2002 11:58 AM
    Subject: Re: RE: [noparse][[/noparse]basicstamps] serin question


    > thanks for the tip but unfortunaly that is not my probrem. I am sending a
    frame of data with ascii control characters and open data, but the stamp
    debugs charactes like Ĉ#ĬĂǏ
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-03 02:15
    I am trying to filter in serial data using the 'wait' modifier with
    'serin'. Is there a way to look for two possible senarios in a serial
    string?

    i.e. looking for the "1" in <0010034 > then goto "X" or looking for the
    "2" in <0020034> then goto "Y".
    0000032 ignore
    0020034 store value in "Y"
    0000037 ignore
    0010035 store value in "X" ....

    I can't seem to find a way to look for two different variables in a single
    serin command. Any suggestions?
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-10 10:53
    Dear all,

    I'm using BS2p, and I've some questions about the following program.


    serSTR VAR Byte(10) 'Make a 10-byte array
    Main:
    serSTR(9)=0 'Put 0 in last byte
    SERIN 16, 16468, [noparse][[/noparse]STR serSTR\9]
    DEBUG STR serSTR
    GOTO Main

    May I know that what is the use of putting "0" in the last byte of
    the 10-byte array. If I delete this line "serSTR(9)=0", the programm
    still work. There is no difference. Thus what's the use of this line?
    Thank you very much!!
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-10 16:41
    The command that prints out the received string,
    DEBUG STR serSTR
    knows when to stop printing when it encounters a zero in the array of
    bytes. The program puts an 0 in the tenth byte so that it will be
    sure to encounter a zero at the end of the nine byte received string.
    The program works without line "serSTR(9)=0", because the Stamp
    initializes all of the locations in RAM to zero at the start of the
    program anyway. They did it for illustration of the prinicple.

    There is a good explanation of this in the BASIC Stamp manual version
    2.0. Definitely get it or download it!

    -- Tracy


    >Dear all,
    >
    >I'm using BS2p, and I've some questions about the following program.
    >
    >
    >serSTR VAR Byte(10) 'Make a 10-byte array
    >Main:
    > serSTR(9)=0 'Put 0 in last byte
    > SERIN 16, 16468, [noparse][[/noparse]STR serSTR\9]
    > DEBUG STR serSTR
    >GOTO Main
    >
    >May I know that what is the use of putting "0" in the last byte of
    >the 10-byte array. If I delete this line "serSTR(9)=0", the programm
    >still work. There is no difference. Thus what's the use of this line?
    >Thank you very much!!
Sign In or Register to comment.