Shop OBEX P1 Docs P2 Docs Learn Events
Serial Input Weirdness — Parallax Forums

Serial Input Weirdness

ArchiverArchiver Posts: 46,084
edited 2002-01-11 23:21 in General Discussion
I'm wondering if anyone could help me with some code. I am trying to send
serial data to my BS2 from my PC. My program waits for the ASCII string qwerty
then saves the following 8 bytes and debugs their values. When I send
qwerty12345678 from the PC, the debug shows garbage. But if I send qwerty, then
send 12345678 seperatly it works. Why?
here's my program:


begin:
serString var byte(8)
serString(7) = 0
serin 15,16468,[noparse][[/noparse]wait ("qwerty"),str serString\8]
debug str serString
goto begin

Thanks for any help.

-Dan



[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-01-11 01:33
    Remember that using the SERIN modifiers (like WAIT and SKIP) requires a bit
    of processing time. When you're sending the packets separately, SERIN has
    time enough to get ready to receive the "12345678" part. You might want to
    adjust your PC end to add a bit of pacing between characters.

    -- Jon Williams
    -- Parallax


    In a message dated 1/10/02 6:17:41 PM Central Standard Time,
    gliebetronics@h... writes:


    > I'm wondering if anyone could help me with some code. I am trying to send
    > serial data to my BS2 from my PC. My program waits for the ASCII string
    > qwerty then saves the following 8 bytes and debugs their values. When I
    > send qwerty12345678 from the PC, the debug shows garbage. But if I send
    > qwerty, then send 12345678 seperatly it works. Why?
    > here's my program:
    >
    >
    > begin:
    > serString var byte(8)
    > serString(7) = 0
    > serin 15,16468,[noparse][[/noparse]wait ("qwerty"),str serString\8]
    > debug str serString
    > goto begin
    >
    > Thanks for any help.
    >
    > -Dan
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-01-11 06:39
    Hi. I posted earlier and I did get a reply but it didn't really help me out
    so I think I'll explain my whole situation and hopefully someone out there
    will have some brilliant idea which I have not thought of yet. What I'm
    trying to do is send 8 numbers from a PC to the BS2. Each number is between
    0 and 255. The format in which I have been trying to send the numbers is
    A#B#C#D#E#F#G#H#. So a sample of potential data is like
    A1B40C255D0E30F100G1H255. I was trying to use a serin command with Wait's
    in it to wait for each Letter then save the numbers in appropreatly named
    byte size variables, A, B, C... I keep getting weird results like having
    to resend the data many times or at least twice to successfully recieve all
    the data. I've tried Strings and Sending the data seperatly and lower Baud
    rates, All woth no luck. :-/ Anybody know any tried and true methods of
    programming for such a situation as this? Some examples would be greatly
    appreciated. thanks.

    -Dan
  • ArchiverArchiver Posts: 46,084
    edited 2002-01-11 13:28
    If you're always sending eight bytes, send them in the same order and remove
    any serial modifiers (like WAIT and SKIP) since they require extra processing
    time. You might find something helpful in a project I did called EEMOVER.
    It allowed me to use VB to change a big block of data in the Stamp's EE. You
    can find it at:

    http://members.aol.com/jonwms/stamps/eemover.zip

    -- Jon Williams
    -- Parallax


    In a message dated 1/11/02 12:42:44 AM Central Standard Time,
    gliebetronics@h... writes:


    > Hi. I posted earlier and I did get a reply but it didn't really help me out
    > so I think I'll explain my whole situation and hopefully someone out there
    > will have some brilliant idea which I have not thought of yet. What I'm
    > trying to do is send 8 numbers from a PC to the BS2. Each number is between
    > 0 and 255. The format in which I have been trying to send the numbers is
    > A#B#C#D#E#F#G#H#. So a sample of potential data is like
    > A1B40C255D0E30F100G1H255. I was trying to use a serin command with Wait's
    > in it to wait for each Letter then save the numbers in appropreatly named
    > byte size variables, A, B, C... I keep getting weird results like having
    > to resend the data many times or at least twice to successfully recieve all
    > the data. I've tried Strings and Sending the data seperatly and lower Baud
    > rates, All woth no luck. :-/ Anybody know any tried and true methods of
    > programming for such a situation as this? Some examples would be greatly
    > appreciated. thanks.
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-01-11 16:19
    Hi,

    You should be able to read binary numbers directly.
    Take some trigger value to wait for, like a '*' then

    A var byte
    B var byte
    etc.

    Serin pin,baud,[noparse][[/noparse]wait "*",dec A, dec B, dec C, dec D, dec E, dec F, dec G,
    dec H]

    Send your data like

    "*,001,002,003,004,005,006,007,008" with comma's as seperators (without the
    quotes of course)
    If you use fixed length numbers (like always 3 digits) you can use dec3
    instead of dec in serin.
    That should work.

    Regards peter


    Oorspronkelijk bericht
    Van: Daniel Gliebe [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=StD_lnTX7mhrRK5hbETw2VoJkOmMZhMzqEV3sVB1Y7h2XgB51OZgpHHFY9lFgNopKRXpXP2rScYLjS2Xz844nzwq]gliebetronics@h...[/url
    Verzonden: donderdag 10 januari 2002 22:39
    Aan: basicstamps@yahoogroups.com
    Onderwerp: [noparse][[/noparse]basicstamps] Serial Input Weirdness

    Hi. I posted earlier and I did get a reply but it didn't really help me out
    so I think I'll explain my whole situation and hopefully someone out there
    will have some brilliant idea which I have not thought of yet. What I'm
    trying to do is send 8 numbers from a PC to the BS2. Each number is between
    0 and 255. The format in which I have been trying to send the numbers is
    A#B#C#D#E#F#G#H#. So a sample of potential data is like
    A1B40C255D0E30F100G1H255. I was trying to use a serin command with Wait's
    in it to wait for each Letter then save the numbers in appropreatly named
    byte size variables, A, B, C... I keep getting weird results like having
    to resend the data many times or at least twice to successfully recieve all
    the data. I've tried Strings and Sending the data seperatly and lower Baud
    rates, All woth no luck. :-/ Anybody know any tried and true methods of
    programming for such a situation as this? Some examples would be greatly
    appreciated. thanks.

    -Dan

    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-01-11 18:36
    The strange part that I don't understand is that if I use this:

    serin 15,16780, [noparse][[/noparse]Wait ("start"), A, B]

    I can send from the PC (without quotes) "start26".
    I debug A and B and they are indeed 2 and 6. However, if I use this line
    with the DEC before each variable:

    serin 15,16780, [noparse][[/noparse]Wait ("start"), dec A, dec B]

    If I send (without quotes) "start123,456" I MUST send the serial string
    TWICE for some odd reason for the BS2 to continue on and debug the values.
    Without the DEC there, I can't have #s larger than one digit, I can't have A
    = 255 for instance. Why does it always seem to get hung up when I use DEC?

    -Dan

    Original Message
    From: "peter verkaik" <peterverkaik@b...>
    To: <basicstamps@yahoogroups.com>
    Sent: Friday, January 11, 2002 8:19 AM
    Subject: RE: [noparse][[/noparse]basicstamps] Serial Input Weirdness


    > Hi,
    >
    > You should be able to read binary numbers directly.
    > Take some trigger value to wait for, like a '*' then
    >
    > A var byte
    > B var byte
    > etc.
    >
    > Serin pin,baud,[noparse][[/noparse]wait "*",dec A, dec B, dec C, dec D, dec E, dec F, dec G,
    > dec H]
    >
    > Send your data like
    >
    > "*,001,002,003,004,005,006,007,008" with comma's as seperators (without
    the
    > quotes of course)
    > If you use fixed length numbers (like always 3 digits) you can use dec3
    > instead of dec in serin.
    > That should work.
    >
    > Regards peter
    >
    >
    >
    Oorspronkelijk bericht
    > Van: Daniel Gliebe [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=dX0GM-jHD6OiKetyxuM3JUiZvH_Dd9xZV68-7H1gZ0dNPCFGJsj5FTV1HTc0SilIt21vxgMgtY-yptSF6Jc7aF-G7A]gliebetronics@h...[/url
    > Verzonden: donderdag 10 januari 2002 22:39
    > Aan: basicstamps@yahoogroups.com
    > Onderwerp: [noparse][[/noparse]basicstamps] Serial Input Weirdness
    >
    > Hi. I posted earlier and I did get a reply but it didn't really help me
    out
    > so I think I'll explain my whole situation and hopefully someone out there
    > will have some brilliant idea which I have not thought of yet. What I'm
    > trying to do is send 8 numbers from a PC to the BS2. Each number is
    between
    > 0 and 255. The format in which I have been trying to send the numbers is
    > A#B#C#D#E#F#G#H#. So a sample of potential data is like
    > A1B40C255D0E30F100G1H255. I was trying to use a serin command with Wait's
    > in it to wait for each Letter then save the numbers in appropreatly named
    > byte size variables, A, B, C... I keep getting weird results like having
    > to resend the data many times or at least twice to successfully recieve
    all
    > the data. I've tried Strings and Sending the data seperatly and lower
    Baud
    > rates, All woth no luck. :-/ Anybody know any tried and true methods of
    > programming for such a situation as this? Some examples would be greatly
    > appreciated. thanks.
    >
    > -Dan
    >
    > 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/
    >
    >
    >
    > 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-01-11 18:42
    oops, I made a small typO. Where I say "start123,456" it should be
    "start123,255" since my variables are bytes.

    -Dan

    Original Message
    From: "Daniel Gliebe" <gliebetronics@h...>
    To: <basicstamps@yahoogroups.com>
    Sent: Friday, January 11, 2002 10:36 AM
    Subject: Re: [noparse][[/noparse]basicstamps] Serial Input Weirdness


    > The strange part that I don't understand is that if I use this:
    >
    > serin 15,16780, [noparse][[/noparse]Wait ("start"), A, B]
    >
    > I can send from the PC (without quotes) "start26".
    > I debug A and B and they are indeed 2 and 6. However, if I use this line
    > with the DEC before each variable:
    >
    > serin 15,16780, [noparse][[/noparse]Wait ("start"), dec A, dec B]
    >
    > If I send (without quotes) "start123,456" I MUST send the serial string
    > TWICE for some odd reason for the BS2 to continue on and debug the values.
    > Without the DEC there, I can't have #s larger than one digit, I can't have
    A
    > = 255 for instance. Why does it always seem to get hung up when I use
    DEC?
    >
    > -Dan
    >
    >
    Original Message
    > From: "peter verkaik" <peterverkaik@b...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Friday, January 11, 2002 8:19 AM
    > Subject: RE: [noparse][[/noparse]basicstamps] Serial Input Weirdness
    >
    >
    > > Hi,
    > >
    > > You should be able to read binary numbers directly.
    > > Take some trigger value to wait for, like a '*' then
    > >
    > > A var byte
    > > B var byte
    > > etc.
    > >
    > > Serin pin,baud,[noparse][[/noparse]wait "*",dec A, dec B, dec C, dec D, dec E, dec F, dec
    G,
    > > dec H]
    > >
    > > Send your data like
    > >
    > > "*,001,002,003,004,005,006,007,008" with comma's as seperators (without
    > the
    > > quotes of course)
    > > If you use fixed length numbers (like always 3 digits) you can use dec3
    > > instead of dec in serin.
    > > That should work.
    > >
    > > Regards peter
    > >
    > >
    > >
    Oorspronkelijk bericht
    > > Van: Daniel Gliebe [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ss5IoKPmAVFl9H4MH3F0gnwxI7UsEtMKymEi_frYuL3eekHPTza4Csp3AaDzTn9ZiRvJLPzidefwOmxokpskxXrH]gliebetronics@h...[/url
    > > Verzonden: donderdag 10 januari 2002 22:39
    > > Aan: basicstamps@yahoogroups.com
    > > Onderwerp: [noparse][[/noparse]basicstamps] Serial Input Weirdness
    > >
    > > Hi. I posted earlier and I did get a reply but it didn't really help me
    > out
    > > so I think I'll explain my whole situation and hopefully someone out
    there
    > > will have some brilliant idea which I have not thought of yet. What I'm
    > > trying to do is send 8 numbers from a PC to the BS2. Each number is
    > between
    > > 0 and 255. The format in which I have been trying to send the numbers
    is
    > > A#B#C#D#E#F#G#H#. So a sample of potential data is like
    > > A1B40C255D0E30F100G1H255. I was trying to use a serin command with
    Wait's
    > > in it to wait for each Letter then save the numbers in appropreatly
    named
    > > byte size variables, A, B, C... I keep getting weird results like
    having
    > > to resend the data many times or at least twice to successfully recieve
    > all
    > > the data. I've tried Strings and Sending the data seperatly and lower
    > Baud
    > > rates, All woth no luck. :-/ Anybody know any tried and true methods of
    > > programming for such a situation as this? Some examples would be
    greatly
    > > appreciated. thanks.
    > >
    > > -Dan
    > >
    > > 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/
    > >
    > >
    > >
    > > 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/
    > >
    > >
    > >
    >
    > 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-01-11 18:48
    Hi Dan,

    I do a similar thing with a series of numbers, some of different lengths as:

    GetData:
    Serin 15, 84, [noparse][[/noparse]wait("U"), dec1 Tr, dec4 Size, dec4 Mask, dec5 LCD,
    dec5 Lens, dec4 Pre, dec4 Post]
    Debug cls
    Debug cr, "Transport ", dec1 Tr
    Debug cr, "Size ", dec4 Size
    Debug cr, "Mask ", dec4 Mask
    Debug cr, "LCD ", dec5 LCD
    Debug cr, "Lens ", dec5 Lens
    Debug cr, "Pre ", dec4 Pre
    Debug cr, "Post ", dec4 Post

    snip.....

    As you can see, each piece of data is predefined as to how long it is expected
    to be. If you know all of your
    data is within 255, then of course you can just set them up as byte variables,
    but in my case, several of
    them need 5 bytes, and as in the case of the Tr variable, I did that to save
    space.

    The debug list simply prints them all out so that I can see them whilst
    debugging.
    This has worked very solidly for me.
    Good luck
    Russ


    | > Van: Daniel Gliebe [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=062lYUmhBQmsAh31-imgdYqjLHw1cm84HWFW_03yDj0vNwmmDgJabR1N2KF08Xfq3SJtsGcrZnuXFp82ZgN-ElP6]gliebetronics@h...[/url
    | > Verzonden: donderdag 10 januari 2002 22:39
    | > Aan: basicstamps@yahoogroups.com
    | > Onderwerp: [noparse][[/noparse]basicstamps] Serial Input Weirdness
    | >
    | > Hi. I posted earlier and I did get a reply but it didn't really help me
    | out
    | > so I think I'll explain my whole situation and hopefully someone out there
    | > will have some brilliant idea which I have not thought of yet. What I'm
    | > trying to do is send 8 numbers from a PC to the BS2. Each number is
    | between
    | > 0 and 255. The format in which I have been trying to send the numbers is

    snip...
  • ArchiverArchiver Posts: 46,084
    edited 2002-01-11 19:12
    DEC is another modifier -- it converts string dat to numeric data, so it
    takes additional processing overhead.

    Another note is that you must send a non-numeric character between each
    number when using DEC. In your first example, the Stamp saw "start" then but
    the next byte into "A" and the second byte into "B." If you check carefully,
    what you actually received was "2" and "6" (characters, not numbers).

    On your second example, try sending the string "start 123,456<CR>" (note that
    <CR> is meant to be #13 [noparse][[/noparse]carriage return]) and put some pacing between the
    characters (see Jan Axelson's book 'Serial Port Complete' for VB code to do
    this).

    -- Jon Williams
    -- Parallax

    In a message dated 1/11/02 12:41:33 PM Central Standard Time,
    gliebetronics@h... writes:


    > The strange part that I don't understand is that if I use this:
    >
    > serin 15,16780, [noparse][[/noparse]Wait ("start"), A, B]
    >
    > I can send from the PC (without quotes) "start26".
    > I debug A and B and they are indeed 2 and 6. However, if I use this line
    > with the DEC before each variable:
    >
    > serin 15,16780, [noparse][[/noparse]Wait ("start"), dec A, dec B]
    >
    > If I send (without quotes) "start123,456" I MUST send the serial string
    > TWICE for some odd reason for the BS2 to continue on and debug the values.
    > Without the DEC there, I can't have #s larger than one digit, I can't have A
    > = 255 for instance. Why does it always seem to get hung up when I use DEC?
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-01-11 23:21
    Try slowing down the baud rate, it may be too fast for the bs2 to receive
    the data.
    Chris

    Original Message
    From: "Daniel Gliebe" <gliebetronics@h...>
    To: <basicstamps@yahoogroups.com>
    Sent: Saturday, January 12, 2002 2:36 AM
    Subject: Re: [noparse][[/noparse]basicstamps] Serial Input Weirdness


    > The strange part that I don't understand is that if I use this:
    >
    > serin 15,16780, [noparse][[/noparse]Wait ("start"), A, B]
    >
    > I can send from the PC (without quotes) "start26".
    > I debug A and B and they are indeed 2 and 6. However, if I use this line
    > with the DEC before each variable:
    >
    > serin 15,16780, [noparse][[/noparse]Wait ("start"), dec A, dec B]
    >
    > If I send (without quotes) "start123,456" I MUST send the serial string
    > TWICE for some odd reason for the BS2 to continue on and debug the values.
    > Without the DEC there, I can't have #s larger than one digit, I can't have
    A
    > = 255 for instance. Why does it always seem to get hung up when I use
    DEC?
    >
    > -Dan
    >
    >
    Original Message
    > From: "peter verkaik" <peterverkaik@b...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Friday, January 11, 2002 8:19 AM
    > Subject: RE: [noparse][[/noparse]basicstamps] Serial Input Weirdness
    >
    >
    > > Hi,
    > >
    > > You should be able to read binary numbers directly.
    > > Take some trigger value to wait for, like a '*' then
    > >
    > > A var byte
    > > B var byte
    > > etc.
    > >
    > > Serin pin,baud,[noparse][[/noparse]wait "*",dec A, dec B, dec C, dec D, dec E, dec F, dec
    G,
    > > dec H]
    > >
    > > Send your data like
    > >
    > > "*,001,002,003,004,005,006,007,008" with comma's as seperators (without
    > the
    > > quotes of course)
    > > If you use fixed length numbers (like always 3 digits) you can use dec3
    > > instead of dec in serin.
    > > That should work.
    > >
    > > Regards peter
    > >
    > >
    > >
    Oorspronkelijk bericht
    > > Van: Daniel Gliebe [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Zgj5cbKpwEbScwms0TQFQavYYAGinZTag3Wx8gOcsp-LD9L8MH-OptmwL-XORCVZeZeGtzSjrlnmm6o-IqNg]gliebetronics@h...[/url
    > > Verzonden: donderdag 10 januari 2002 22:39
    > > Aan: basicstamps@yahoogroups.com
    > > Onderwerp: [noparse][[/noparse]basicstamps] Serial Input Weirdness
    > >
    > > Hi. I posted earlier and I did get a reply but it didn't really help me
    > out
    > > so I think I'll explain my whole situation and hopefully someone out
    there
    > > will have some brilliant idea which I have not thought of yet. What I'm
    > > trying to do is send 8 numbers from a PC to the BS2. Each number is
    > between
    > > 0 and 255. The format in which I have been trying to send the numbers
    is
    > > A#B#C#D#E#F#G#H#. So a sample of potential data is like
    > > A1B40C255D0E30F100G1H255. I was trying to use a serin command with
    Wait's
    > > in it to wait for each Letter then save the numbers in appropreatly
    named
    > > byte size variables, A, B, C... I keep getting weird results like
    having
    > > to resend the data many times or at least twice to successfully recieve
    > all
    > > the data. I've tried Strings and Sending the data seperatly and lower
    > Baud
    > > rates, All woth no luck. :-/ Anybody know any tried and true methods of
    > > programming for such a situation as this? Some examples would be
    greatly
    > > appreciated. thanks.
    > >
    > > -Dan
    > >
    > > 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/
    > >
    > >
    > >
    > > 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/
    > >
    > >
    > >
    >
    > 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/
    >
    >
Sign In or Register to comment.