Shop OBEX P1 Docs P2 Docs Learn Events
BS2 and Vbasic MSComm — Parallax Forums

BS2 and Vbasic MSComm

ArchiverArchiver Posts: 46,084
edited 2000-07-17 16:53 in General Discussion
I have a keypad sending keypresses to a BS2 through a 16 key encoder chip.
The BS2 sends the keypresses to a PC running a visual basic program. The
PC takes the keypresses, evaluates them and sends the appropriate commands
back to the stamp. The stamp then sets an output or sends an X10 command.
I'm using MSComm's OnComm event to receive the keypresses. The problem is
when I send commands back to the stamp using MSComm's Output statement it
generates an OnComm event in the receive buffer. I'm using the RX and TX
pins on the stamp for communication. I have to clear the input buffer
every time I send to the stamp. Does anyone have an idea why I receive
something every time I send to the stamp?

Thanks

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-07-17 07:49
    At 11:30 PM 7/16/00, you wrote:
    >I have a keypad sending keypresses to a BS2 through a 16 key encoder chip.
    > The BS2 sends the keypresses to a PC running a visual basic program. The
    >PC takes the keypresses, evaluates them and sends the appropriate commands
    >back to the stamp. The stamp then sets an output or sends an X10 command.
    > I'm using MSComm's OnComm event to receive the keypresses. The problem is
    >when I send commands back to the stamp using MSComm's Output statement it
    >generates an OnComm event in the receive buffer. I'm using the RX and TX
    >pins on the stamp for communication. I have to clear the input buffer
    >every time I send to the stamp. Does anyone have an idea why I receive
    >something every time I send to the stamp?


    Just a guess, but it's probably the ECHO from the Stamp.
    The Stamp echos responses sent to it, due to the method the Sein and Serout
    (Pin 16) transistors are configured. Short of trace cutting (which I WOULD
    NOT recommend), I would just ignore it on the PC end <shrug>.

    Hope that helps.


    >Thanks

    Yup

    Regards,

    Bruce Bates
  • ArchiverArchiver Posts: 46,084
    edited 2000-07-17 11:08
    In a message dated 7/16/00 10:36:02 PM Central Daylight Time,
    etech@b... writes:

    > I have a keypad sending keypresses to a BS2 through a 16 key encoder chip.
    > The BS2 sends the keypresses to a PC running a visual basic program. The
    > PC takes the keypresses, evaluates them and sends the appropriate commands
    > back to the stamp. The stamp then sets an output or sends an X10 command.
    > I'm using MSComm's OnComm event to receive the keypresses. The problem
    is
    > when I send commands back to the stamp using MSComm's Output statement it
    > generates an OnComm event in the receive buffer. I'm using the RX and TX
    > pins on the stamp for communication. I have to clear the input buffer
    > every time I send to the stamp. Does anyone have an idea why I receive
    > something every time I send to the stamp?

    You must be using the BS2's programming port for serial comm. If you look at
    the schematic in the manual you'll find that when using this port, the PC's
    RX line gets tied to its TX line. So, everything you send from the PC gets
    echoed right back.

    My August "Stamp Applications" column in Nuts & Volts magazine deals with
    this very subject. In a nutshell:

    * Preface your command string (PC to Stamp) with a control character --
    something you can use with the SERIN "WAIT" modifier.

    * End your command string with a carriage return. Use this as a "flag" for
    your OnComm event to process the recieved characters.

    * When OnComm fires, grab the character and stuff it into a buffer.

    * When you recieve a CR, look at the first character in your buffer. If it's
    your command control character, you can through away the buffer -- it's an
    echoed command. If it's a valid response or message from Stamp, deal with it
    accordingly.

    This method requires you to send short strings (MSComm text mode) to and from
    the Stamp that are terminated with a carriage return. A benefit to this
    method is that you can test your Stamp program with a generic terminal before
    moving on to the VB side of things.

    Hope this helps.

    -- Jon Williams
    -- Dallas, TX
  • ArchiverArchiver Posts: 46,084
    edited 2000-07-17 16:53
    Dean,

    The explanation to this is that you have the SThreshold property set to
    other than '0'. This indicates the control to generate an OnComm event when
    'n' bytes are sent via the port. Then, the CommEvent property is set to
    comEvSend.
    Also, in the OnComm event actions you can insert the code

    If MSComm.CommEvent <> comEvReceive then
    Exit Sub
    End If

    This eliminates all events other than data reception (parity, framing, cts,
    etc...) from getting to your processing code.

    Cheers,

    Mike


    >
    Mensaje original
    > De: Dean Seitz [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=4bdSFdtmsnnk3mzK-8pmPGb_KAQPvhIOr9siUyituxZIpslykHMhcShtY54__h6IUPiGH76Ju7tS]etech@b...[/url
    > Enviado el: lunes, 17 de julio de 2000 5:30
    > Para: 'basicstamps@egroups.com'
    > Asunto: [noparse][[/noparse]basicstamps] BS2 and Vbasic MSComm
    >
    >
    > I have a keypad sending keypresses to a BS2 through a 16 key
    > encoder chip.
    > The BS2 sends the keypresses to a PC running a visual basic
    > program. The
    > PC takes the keypresses, evaluates them and sends the appropriate
    > commands
    > back to the stamp. The stamp then sets an output or sends an X10
    > command.
    > I'm using MSComm's OnComm event to receive the keypresses. The
    > problem is
    > when I send commands back to the stamp using MSComm's Output statement it
    > generates an OnComm event in the receive buffer. I'm using the RX and TX
    > pins on the stamp for communication. I have to clear the input buffer
    > every time I send to the stamp. Does anyone have an idea why I receive
    > something every time I send to the stamp?
    >
    > Thanks
    >
    >
    >
    >
    >
    >
Sign In or Register to comment.