Shop OBEX P1 Docs P2 Docs Learn Events
VB6 to BS2 serin woes — Parallax Forums

VB6 to BS2 serin woes

ArchiverArchiver Posts: 46,084
edited 2001-05-18 16:12 in General Discussion
[font=arial,helvetica]Hi everyone. I've been pulling my hair out on this problem
for the last couple of hours. I'm finally giving in and hope that
the "collective" can show me the error of my ways.

I'll bet it is something embarrassingly simple, but even after
going through the Stamp manual and two Stamp books, I
just can't see the solution, even though it's probably right in
front of me. ·:-(

I'm receiving data from a PC through pin0 on the Stamp 2.
The sample string is "@62409". The BS2 waits for the "@",
then places each of the following bytes into it's own variable
(char1, char2, etc). So far so good, the data is received and
debugged to a second PC. ·From there I want to convert the
five char variables into a single word. The code works fine if I
hardcode the variables (char1=6, char2=2, etc) - total will equal
62409. But the way this code is written, total equals 5913.

I imagine the problem might have something to do with receiving
the ASCII values for 6,2,4,0, and 9 instead of the actual number. (?)
Is there some sort of modifier that I may be overlooking?

char1 var byte
char2 var byte
char3 var byte
char4 var byte
char5 var byte
total var word

total=0
serin 0,16468,[noparse][[/noparse]wait("@"),char1,char2,char3,char4,char5]
total=char1*10000
total=total+(char2*1000)
total=total+(char3*100)
total=total+(char4*10)
total=total+char5

debug "Char1 = ",char1,13
debug "Char2 = ",char2,13
debug "Char3 = ",char3,13
debug "Char4 = ",char4,13
debug "Char5 = ",char5,13
debug "Total = ",dec total,13,10

Thanks guys!

Steve[/font]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-05-17 20:42
    Well, you could make the Stamp do it for you:


    Serin 0,16468,[noparse][[/noparse] wait("@"),dec total]
    debug ?total

    Or you could subtract "0" from each digit:
    char1=char1-"0"
    char2=char2-"0"

    Yet another way would be to use an array, so you could write:

    total=0
    for i=0 to 5· ' 6 digits
    · total=total*10
    · total=total+char(i)-"0"
    next
    debug ?total

    How's that?

    Al Williams
    AWC
    * Connect your Stamp to the Internet.
    http://www.al-williams.com/awce/netporter.htm



    Original Message
    From: PicProgrammer@aol.com [noparse][[/noparse]mailto:PicProgrammer@aol.com]
    Sent: Thursday, May 17, 2001 2:21 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] VB6 to BS2 serin woes

    [font=arial,helvetica]Hi everyone. I've been pulling my hair out on this problem
    for the last couple of hours. I'm finally giving in and hope that
    the "collective" can show me the error of my ways.

    I'll bet it is something embarrassingly simple, but even after
    going through the Stamp manual and two Stamp books, I
    just can't see the solution, even though it's probably right in
    front of me. ·:-(

    I'm receiving data from a PC through pin0 on the Stamp 2.
    The sample string is "@62409". The BS2 waits for the "@",
    then places each of the following bytes into it's own variable
    (char1, char2, etc). So far so good, the data is received and
    debugged to a second PC. ·From there I want to convert the
    five char variables into a single word. The code works fine if I
    hardcode the variables (char1=6, char2=2, etc) - total will equal
    62409. But the way this code is written, total equals 5913.

    I imagine the problem might have something to do with receiving
    the ASCII values for 6,2,4,0, and 9 instead of the actual number. (?)
    Is there some sort of modifier that I may be overlooking?

    char1 var byte
    char2 var byte
    char3 var byte
    char4 var byte
    char5 var byte
    total var word

    total=0
    serin 0,16468,[noparse][[/noparse]wait("@"),char1,char2,char3,char4,char5]
    total=char1*10000
    total=total+(char2*1000)
    total=total+(char3*100)
    total=total+(char4*10)
    total=total+char5

    debug "Char1 = ",char1,13
    debug "Char2 = ",char2,13
    debug "Char3 = ",char3,13
    debug "Char4 = ",char4,13
    debug "Char5 = ",char5,13
    debug "Total = ",dec total,13,10

    Thanks guys!

    Steve
    Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

    [/font]
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-18 01:30
    [font=arial,helvetica]In a message dated 5/17/01 3:50:23 PM Eastern Daylight Time,
    alw@al-williams.com writes:

    <<Well, you could make the Stamp do it for you:

    Serin 0,16468,[noparse][[/noparse] wait("@"),dec total]>>

    As usual, you are correct Al. ·This was how I tried it the
    first time around (dec5 total), but it wouldn't work. The BS2
    and PC were communicating at 9600N81, with a dead simple
    VB6 program (using MSCOMM) sending the string. I just tried
    it without the WAIT modifier, and it works as it should. Looks
    like the BS2 is just a bit too slow when using WAIT at 9600 with VB?
    Oddly enough, when using WAIT, if I sent the string twice in a
    row, it would work! Strange though that the BS2 would correctly
    receive the data at the same rate when using 5 byte variables instead
    of dec5.

    When bumping the rate down to 2400, everything is just peachy.
    Would you know if there is some sort of automagical intercharacter
    pacing property available with the MSCOMM control?

    <<Or you could subtract "0" from each digit:
    char1=char1-"0"
    char2=char2-"0">>

    Doh!!!! (slapping forehead) ·See, I told you I would wind up
    being embarrassed. LOL

    Thanks Al! ···BTW, love the book. Any more titles on the horizon? :-)

    Steve
    [/font]
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-18 01:49
    Could you just slip a blank or a NUL after the @ to fix it?

    Glad you've enjoyed the book. Yes a couple of new books coming out within
    the next few months. Probably see the first of them after the summer.

    Regards,

    Al Williams
    AWC
    * Connect your Stamp to the Internet:
    http://www.al-williams.com/awce/netporter.htm


    Original Message
    From: PicProgrammer@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=IKNJhjb8N9EUiS1lWLP3QBEKNd2Hi5WttTW95AGk6hEXJiIB6CWHj5OQcXU3iCasJ7pn8jzJp83G9QwQ2w]PicProgrammer@a...[/url
    Sent: Thursday, May 17, 2001 7:30 PM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] VB6 to BS2 serin woes


    In a message dated 5/17/01 3:50:23 PM Eastern Daylight Time,
    alw@a... writes:

    <<Well, you could make the Stamp do it for you:

    Serin 0,16468,[noparse][[/noparse] wait("@"),dec total]>>

    As usual, you are correct Al. This was how I tried it the
    first time around (dec5 total), but it wouldn't work. The BS2
    and PC were communicating at 9600N81, with a dead simple
    VB6 program (using MSCOMM) sending the string. I just tried
    it without the WAIT modifier, and it works as it should. Looks
    like the BS2 is just a bit too slow when using WAIT at 9600 with VB?
    Oddly enough, when using WAIT, if I sent the string twice in a
    row, it would work! Strange though that the BS2 would correctly
    receive the data at the same rate when using 5 byte variables instead
    of dec5.

    When bumping the rate down to 2400, everything is just peachy.
    Would you know if there is some sort of automagical intercharacter
    pacing property available with the MSCOMM control?

    <<Or you could subtract "0" from each digit:
    char1=char1-"0"
    char2=char2-"0">>

    Doh!!!! (slapping forehead) See, I told you I would wind up
    being embarrassed. LOL

    Thanks Al! BTW, love the book. Any more titles on the horizon? :-)

    Steve

    Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-18 02:46
    [font=arial,helvetica]<<Could you just slip a blank or a NUL after the @ to fix it?>>

    Thanks Al, I'll give that a shot.

    Serial BS2 comms just got a bit more interesting. Same hardware
    setup as before - BS2 debugging to my desktop, and receiving data
    on Pin 0 from a laptop). The laptop side is running W95 and Hyperterminal
    (v. 595160). Connected at 2400N81. I was just using this setup to confirm
    that the serial link was working, running this snippet of code:

    loop:
    serin 0,16780,[noparse][[/noparse]b1]
    debug dec b1,13
    goto loop

    Should be simple enough, right? Not today it isn't. LOL

    As long as I don't repeat any character more than twice in a row, all
    is fine.

    Pressing "ABBCDEFFG" correctly returns:

    65
    66
    66
    67
    68
    69
    70
    70
    71


    But on the third repetition of a character, b1 suddenly grows by 128.
    Further repetitions of the same character alternate between b1 and b1+128.

    Example, typing "AAAAAAA" results in:

    65
    65
    193
    65
    193
    65
    193
    etc.

    Am I going nuts here??? :-(

    <<Glad you've enjoyed the book. Yes a couple of new books coming out within
    the next few months. Probably see the first of them after the summer.>>

    Are any of these books stamp related? (hint, hint, hint)

    Best regards,

    Steve[/font]
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-18 16:10
    Greetings all,

    I've been following this and would like to add a question. I
    have a VB6 to BS2 program that sends single byte instructions to the BS2
    board. Setup is serin 16, 84, [noparse][[/noparse]SerData].

    Everything appears to be working except it doesn't appear that I
    can send a hex 0, or NULL byte to the BS2. Anyone else have this
    experience. Does this have something to do with the bit 16 setup to use
    the same interface as the stampw.exe software uses for loading the
    program in the BS2?

    Thanks, Theron
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-18 16:12
    I expect you have to use binary mode on the MSCOMM control to get that to
    work. If you are sending text, it won't work. That's a guess, but I'd bet a
    few dollars on it.

    Al Williams
    AWC
    * Connect your Stamp to the Net (or any serial device):
    http://www.al-williams.com/awce/netporter.htm


    >
    Original Message
    > From: Theron Wierenga [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=MK-9MJH5b_96iF-YCTvWverrnWeGFY3PY0DOF-WHRk5pEXKoMI0iZyNLzxhHm5ANVP4U-gj29AgVz0cZS5JlXYlwg6T0fQ]twiereng@m...[/url
    > Sent: Friday, May 18, 2001 10:10 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] VB6 to BS2 serin woes
    >
    >
    > Greetings all,
    >
    > I've been following this and would like to add a question. I
    > have a VB6 to BS2 program that sends single byte instructions to the BS2
    > board. Setup is serin 16, 84, [noparse][[/noparse]SerData].
    >
    > Everything appears to be working except it doesn't appear that I
    > can send a hex 0, or NULL byte to the BS2. Anyone else have this
    > experience. Does this have something to do with the bit 16 setup to use
    > the same interface as the stampw.exe software uses for loading the
    > program in the BS2?
    >
    > Thanks, Theron
    >
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
Sign In or Register to comment.