Shop OBEX P1 Docs P2 Docs Learn Events
Displaying multiple sensors' data on vb2005 — Parallax Forums

Displaying multiple sensors' data on vb2005

niconico Posts: 28
edited 2009-07-07 18:13 in BASIC Stamp
I need some help here please. I have encounter some problems when sending the data from bs2 to display it in my vb's gui. I need to display readings·from several sensors in my com using bs2 and vb. For now, I am able to display 1 reading from 1 sensor·by using the following codes.
bs2 codes:
SEROUT 16,16468,[noparse][[/noparse]DEC cmDistance]
SEROUT 16,16468,[noparse][[/noparse]LF]
vb codes:
TextBox1.Text = SerialPort1.ReadLine
Now lets say I·want to display·another 2 more sensors cmDistance2 and cmDistance3 in TextBox2 and TextBox3. How do I·do it ?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-07-07 14:36
    In your serout send an additional byte that represents the sensor ID and parse this in your VB script.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • niconico Posts: 28
    edited 2009-07-07 15:11
    okay. first, i'm new in both program. so how do i do that ? i would appretciate it very much if u can guide me or reference me to any useful info. thx very much [noparse]:D[/noparse]
  • FranklinFranklin Posts: 4,747
    edited 2009-07-07 17:35
    I have no idea how to do that as I don't use VB at all and have to read the stamp manual if I plan to program anything into the stamp, sorry.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-07-07 18:13
    Hi nico, send the values as a string and parse at VB.

    If the values you send are a fixed length this becomes easy.

    Here's an example of transmitting three values with a fixed length of 4 digits/bytes (total 12 bytes)

    SEROUT tx,baud,[noparse][[/noparse]DEC4 val1,DEC4 val2,DEC4 val3,10]

    Of course 4 digits would mean each value is a word value in this case , adjust to suit your values.

    In Visual Basic you would treat the 12 character string as an array and parse the values using the index of the array and a·member called Substring
    eg
    [color=#0000ff][color=#0000ff]Dim[/color][/color] sData [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color] = SerialPort1.ReadLine
    [color=#0000ff][color=#0000ff]Dim[/color][/color] value_1 [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color]
    [color=#0000ff][color=#0000ff]Dim[/color][/color] value_2 [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color]
    [color=#0000ff][color=#0000ff]Dim[/color][/color] value_3 [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color]
    value_1 = sData.Substring(0, 4)
    value_2 = sData.Substring(4, 4)
    value_3 = sData.Substring(8, 4)
    TextBox1.AppendText(value_1 & [color=#a31515][color=#a31515]" "[/color][/color] & value_2 & [color=#a31515][color=#a31515]" "[/color][/color] & value_3)
    
    

    Jeff T.
Sign In or Register to comment.