Shop OBEX P1 Docs P2 Docs Learn Events
serial comms BS2 to VB app — Parallax Forums

serial comms BS2 to VB app

realolmanrealolman Posts: 65
edited 2008-03-02 22:05 in BASIC Stamp
I am communicating with a·BS2 from a VB express app using
Seconds VAR Word 
Comms VAR Byte 

LookComm: 
SERIN 16, 16780,500,Counting, [noparse][[/noparse]Comms] 
 

Counting: 

PAUSE 500 

 IF Comms <> 0 THEN 

  SEROUT 16, 16780, [noparse][[/noparse]DEC4 Seconds] 
  Comms =0 

 ENDIF 

Seconds = Seconds+1 

GOTO LookComm: 
 


END

in the BS2

and

·······
·······
SerialPort1.Write("*") 

to send a * character to the BS2 from the VB app·telling it that I want it to·send the value of "Seconds" ·to my app· ...

and using
txtSerialPort.Text = SerialPort1.ReadExisting

to read the BS2 response. I always get the * that I sent to the BS2 as part of txtSerialPort.Text

I don't think the BS2 is doing it , but I don't know.


·I have tried

VB
txtSerialPort.Text = SerialPort1.ReadExisting


again right after writing the star, because it seems that "empties " the buffer after a read... If I read it twice I get nothing on the second try., but it doesn't make any difference right after the write...
·I've tried VB
DiscardOutBuffer

and VB
DiscardInBuffer

but it doesn't seem to help
I suppose I could use some technique in the VB app to strip off the *, but I would llike to make it quit doing that and understand why it's doing it.

Would the BS2 be doing it?

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-02 16:24
    Hi realolman,·anything you write to the BS2 is echoed back and captured by the input buffer of the serial port. Bytes remain in the buffer until they are read somehow. What you need to do is remove the echo before reading your data. There are several ways you can do that, one way that is fairly secure is to have the Stamp send a header before the data and have the PC app read but ignore everything that precedes the header. I also like to use SerialPort1.ReadLine and have the Stamp transmit a newline or carriage return to signal the end of the data.

    BS2...........SEROUT tx,baud,[noparse][[/noparse]"!",10,DEC4 seconds,10]

    VB......

    Do

    in_string=SerialPort1.ReadLine

    Loop Until in_string ="!"

    data_in=SerialPort1.ReadLine

    Jeff T.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-02 16:34
    Folks -

    What was said about the ECHO is correct, but that situation is limited to the use of Pin Port 16. This happens on ANY BS-2 model Stamp, not just the BS-2. If you use any other Pin Port, you will not experience the problem.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming can't be all that difficult, it's nothing but 1's and 0's
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-02 16:40
    Thanks Bruce, I did think of that afterwards, it's certainly worth a mention.

    Jeff T
  • LapueLapue Posts: 1
    edited 2008-03-02 20:48
    nv89 ? in Nuts and volts
  • realolmanrealolman Posts: 65
    edited 2008-03-02 22:05
    thanks

    you guys are really something

    I know the format of what the BS 2 is going to send , so I guess I'll just use the last digits of it and ignore the rest

    thank you
Sign In or Register to comment.