Shop OBEX P1 Docs P2 Docs Learn Events
question please help me to solve this problem — Parallax Forums

question please help me to solve this problem

andrewbenimaruandrewbenimaru Posts: 6
edited 2010-08-03 13:25 in BASIC Stamp
hi everyone i was new student here i have few question to ask:

the question is i writting a visual basic 2005·program have a control box need to communicate with parallax bs2.

1. i have finish two control box which have function move forward backward right left and stop.
2. the·second control box·receive is through the internet reading the same ip to makesure that are connect.
3. the second control box is connect directly with the boe-bot car.


i have no idea how to make them work if i press forward the car will receive this message.
is very urgen please help me thanks.

Comments

  • Spiral_72Spiral_72 Posts: 791
    edited 2010-07-27 13:28
    I'm assuming you have the USB->Serial or serial programming cable. You'll send data from your visual basic program via serial connection to the BS2.

    Alternately, if you have a parallel port on your computer you could use four lines of that to four inputs on the BS.

    You could use an Parallax wireless RF modules for no wires.

    Ir would have limited use (line of sight up to ~30ft) but this is also possible. You'd probably need the parallel port to implement this easily.


    I hope this helps!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "puff"...... Smile, there went another one.
  • andrewbenimaruandrewbenimaru Posts: 6
    edited 2010-07-28 06:06
    i have not yet done the convert but i think is like that
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

    Select Case e.KeyChar
    Case "2", "4", "5", "6", "8"
    sendCommandToTrolley(AscW(e.KeyChar))
    End Select
    End Sub

    Sub myMsgbox(ByVal str As String)
    If CheckBox1.Checked Then
    MsgBox(str)
    End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    findPort(ComboBox1)
    lblBaudRate.Text = SerialPort1.BaudRate
    lblPortname.Text = SerialPort1.PortName.ToString
    ComboBox1.Text = SerialPort1.PortName
    Me.KeyPreview = True
    End Sub
    Private Sub sendCommandToTrolley(ByVal s2 As Byte)
    Dim s(0) As Byte
    Dim ex As System.Exception

    Try
    s(0) = s2
    myMsgbox("Data being send : Ascii : " & s(0) & " Char : " & Convert.ToChar(s(0)))
    SerialPort1.WriteTimeout = 500 ' time out if the data is not send in 1/2 a second
    retryPort:
    SerialPort1.Open() ' open port for serial communication
    If SerialPort1.IsOpen Then
    SerialPort1.Write(s, 0, 1) ' send data contained in array s[noparse][[/noparse]0]
    SerialPort1.Close() ' close port
    Else
    Dim result As MsgBoxResult
    result = MsgBox("port not open or unable to open port", MsgBoxStyle.RetryCancel)
    If result = MsgBoxResult.Retry Then
    GoTo retryPort
    Else
    Exit Sub
    End If
    End If


    Catch ex
    MsgBox(ex.Message & " " & Err.Number)
    End Try
    End Sub

    Private Sub findPort(ByRef commPortCombo As ComboBox)
    Dim s As String

    For Each s In SerialPort.GetPortNames()
    commPortCombo.Items.Add(s)
    Next s
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    SerialPort1.PortName = ComboBox1.SelectedItem
    lblPortname.Text = SerialPort1.PortName.ToString
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub SplitContainer1_Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    settings.ShowDialog()
    End Sub

    Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
    sendCommandToTrolley(Asc("8"))
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
    sendCommandToTrolley(Asc("5"))
    End Sub

    Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
    sendCommandToTrolley(Asc("4"))
    End Sub

    Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
    sendCommandToTrolley(Asc("6"))
    End Sub

    Private Sub btnBackward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackward.Click
    sendCommandToTrolley(Asc("2"))
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

    End Sub
    End Class
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-07-28 12:45
    I can't help you troubleshoot VB guy.... sorry [noparse]:)[/noparse] I just don't KNOW it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "puff"...... Smile, there went another one.
  • dandreaedandreae Posts: 1,375
    edited 2010-07-28 13:21
    Have you looked at some of the examples that are on-line?· Here is a link for more information:

    http://www.google.com/search?sourceid=navclient&ie=UTF-8&rlz=1T4GGIH_enUS316US316&q=Visual+BASIC+code+and+the+BASIC+Stamp

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-07-28 16:27
    If you don't set "DTREnable" to false, every time you OPEN the serial port it will reset the BS2.

    Typically, the way you use the serial port, you OPEN it in the 'load', LEAVE IT OPEN, then send bytes and recieve bytes.
    You CLOSE the port when you exit the program.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-07-28 17:07
    Hi , at the following link is a VB template that basically does what you require . The thread has several examples each with a short write up explaining how they work.

    Here is the link http://forums.parallax.com/showthread.php?p=671804

    In particular look at "Com Template.zip"

    Jeff T.
  • andrewbenimaruandrewbenimaru Posts: 6
    edited 2010-07-29 07:29
    thanks spiral_72. i'm sorry what is the com template.zip?
    can you measure how to use it?
    thanks~
  • andrewbenimaruandrewbenimaru Posts: 6
    edited 2010-07-29 13:03
    i have download the folder com but how it works?
    am i need to start the basic stamp program ?
    or i have to do something else?

    i new student please teach me thank you.
  • andrewbenimaruandrewbenimaru Posts: 6
    edited 2010-08-03 04:02
    hi i have some problem about this how can i slove it?
    please give me some clue~thanks!
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    main:
    SEROUT 16,16468,[noparse][[/noparse]"#"]
    SERIN 16,16468,25,timeout ,[noparse][[/noparse]DEC1 x]
    timeout:
    ON x GOSUB Halt,Forward,Back,Right,Left
    GOTO main
    END


    Halt:
    DEBUG "1"
    RETURN

    Forward:
    DEBUG "2"
    RETURN

    Back:
    DEBUG "3"
    RETURN

    Right:
    DEBUG "4"
    RETURN

    Left:
    DEBUG "5"
    RETURN
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-08-03 13:25
    Okay, so what's your problem, that code looks good. Except on timeout it calls "Halt". And there's no "PAUSE 100" in there anywhere, so it's going to run awfully fast.
Sign In or Register to comment.