Shop OBEX P1 Docs P2 Docs Learn Events
interfacing BS2 to C++ app — Parallax Forums

interfacing BS2 to C++ app

ArchiverArchiver Posts: 46,084
edited 2003-06-27 16:24 in General Discussion
I have been working on interfacing a C++ application to a BS2. I am able to
successfully send a single byte both to and from the stamp using SERIN and
SEROUT, but am having problems when sending multiple bytes as a string.
Basically, the stamp is sending out the data, but my C++ app is having
trouble parsing it. I am basically getting the value of the last byte sent
for both indices of my array. I'm sure it has to do with the way I am
reading in the data off the serial port, but am a newbie to this so bear
with me. I am using UserPort (a kernel mode driver) to access the I/O ports
in Win2k. Is there an easy way to "sync" the communication so I can store
each incoming byte as a seperate index in an array in my C++ app? Thanks in
advance,
Keith

'segment from Stamp code
stampOut var byte(3)
. . .
stampOut(0) = "5" 'junk test data
stampOut(1) = "6"
. . .
debug "stampOut(0) = ",stampOut(0), cr
debug "stampOut(1) = ",stampOut(1), cr
Serout 16,16468, [noparse][[/noparse]STR stampOut\2]

//code segment from C++ app
C_stampOut[noparse][[/noparse]0] = inportb(0x3F8);
printf("\nC_stampOut[noparse][[/noparse]0] = 0x%02X \n",C_stampOut[noparse][[/noparse]0]);
C_stampOut[noparse][[/noparse]1] = inportb(0x3F8);
printf("\nC_stampOut[noparse][[/noparse]1] = 0x%02X \n",C_stampOut[noparse][[/noparse]1]);

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-06-27 00:10
    You might enjoy http://www.al-williams.com/stampcom.zip -- this is an
    example that uses VB or VC++ to read from a Stamp.

    Al Williams
    AWC
    * Floating point A/D
    http://www.al-williams.com/awce/pak9.htm


    >
    Original Message
    > From: Keith Miller [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ANaAHEJbEsiiJb82Eqb48kM1jdMSsrs6IgVeDlYphwePpa0QXSxLN-z-gVHnn3nb51aIHykBxprh]keith@a...[/url
    > Sent: Thursday, June 26, 2003 4:42 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] interfacing BS2 to C++ app
    >
    >
    > I have been working on interfacing a C++ application to a
    > BS2. I am able to successfully send a single byte both to
    > and from the stamp using SERIN and SEROUT, but am having
    > problems when sending multiple bytes as a string. Basically,
    > the stamp is sending out the data, but my C++ app is having
    > trouble parsing it. I am basically getting the value of the
    > last byte sent for both indices of my array. I'm sure it has
    > to do with the way I am reading in the data off the serial
    > port, but am a newbie to this so bear with me. I am using
    > UserPort (a kernel mode driver) to access the I/O ports in
    > Win2k. Is there an easy way to "sync" the communication so I
    > can store each incoming byte as a seperate index in an array
    > in my C++ app? Thanks in advance, Keith
    >
    > 'segment from Stamp code
    > stampOut var byte(3)
    > . . .
    > stampOut(0) = "5" 'junk test data
    > stampOut(1) = "6"
    > . . .
    > debug "stampOut(0) = ",stampOut(0), cr
    > debug "stampOut(1) = ",stampOut(1), cr
    > Serout 16,16468, [noparse][[/noparse]STR stampOut\2]
    >
    > //code segment from C++ app
    > C_stampOut[noparse][[/noparse]0] = inportb(0x3F8);
    > printf("\nC_stampOut[noparse][[/noparse]0] = 0x%02X \n",C_stampOut[noparse][[/noparse]0]);
    > C_stampOut[noparse][[/noparse]1] = inportb(0x3F8); printf("\nC_stampOut[noparse][[/noparse]1] =
    > 0x%02X \n",C_stampOut[noparse][[/noparse]1]);
    >
    >
    >
    > 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 2003-06-27 09:45
    Hi

    Your problem rises from the fact that the stamp's serial port is
    echoing whatever character it receives. This is an inherent feature
    of the stamp's serial line driver circuitry. You have to overcome
    this by your software. Have your program prepared to receive (and
    ignore) all characters it previously sent to the stamp before
    receiving the rest of the reply. Furthermore, watch out to have
    turned off local echo on the PC side (this would lead to infinite
    bouncing of the characters).

    PC
    "xxx"
    > stamp, replies with "yyy"
    PC <
    "xxxyyy"
    stamp

    Hope this helps
    Adrian
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-27 16:24
    If you are using 'inportb', you are bypassing
    all the Win buffering stuff.

    You can do this, but you'll need to read the
    8251 docs for the status register, to know when
    a byte is ready. Then you'll have to grab the
    byte before the next byte comes in.

    You can dynamically set the FIFO level of your
    serial chips, which should make this easier, as
    the chip can then buffer up more than one byte.

    Microsoft knows this is difficult, so they have
    an MSCOMM control, which does all of this for
    you. Interfacing the MSCOMM control in VB is
    very straightforward -- I'm sure its similar
    in C++, but I havn't done this yet personally.

    If you're curious, you can search the Posts for
    MSCOMM, or ask about using MSCOMM in VC++.

    --- In basicstamps@yahoogroups.com, "Keith Miller" <keith@a...> wrote:
    > I have been working on interfacing a C++ application to a BS2. I
    am able to
    > successfully send a single byte both to and from the stamp using
    SERIN and
    > SEROUT, but am having problems when sending multiple bytes as a
    string.
    > Basically, the stamp is sending out the data, but my C++ app is
    having
    > trouble parsing it. I am basically getting the value of the last
    byte sent
    > for both indices of my array. I'm sure it has to do with the way I
    am
    > reading in the data off the serial port, but am a newbie to this so
    bear
    > with me. I am using UserPort (a kernel mode driver) to access the
    I/O ports
    > in Win2k. Is there an easy way to "sync" the communication so I
    can store
    > each incoming byte as a seperate index in an array in my C++ app?
    Thanks in
    > advance,
    > Keith
    >
    > 'segment from Stamp code
    > stampOut var byte(3)
    > . . .
    > stampOut(0) = "5" 'junk test data
    > stampOut(1) = "6"
    > . . .
    > debug "stampOut(0) = ",stampOut(0), cr
    > debug "stampOut(1) = ",stampOut(1), cr
    > Serout 16,16468, [noparse][[/noparse]STR stampOut\2]
    >
    > //code segment from C++ app
    > C_stampOut[noparse][[/noparse]0] = inportb(0x3F8);
    > printf("\nC_stampOut[noparse][[/noparse]0] = 0x%02X \n",C_stampOut[noparse][[/noparse]0]);
    > C_stampOut[noparse][[/noparse]1] = inportb(0x3F8);
    > printf("\nC_stampOut[noparse][[/noparse]1] = 0x%02X \n",C_stampOut[noparse][[/noparse]1]);
Sign In or Register to comment.