只要我的Kinect应用程序开始发送串行数据,用户界面就会在Visual Basic中冻结

时间:2012-11-18 22:09:45

标签: vb.net arduino kinect

我在Visual Basic中编写了这个程序来控制一个小机器人。程序本身只是将我的手的X和Y坐标发送到控制机器人的Arduino微处理器。

由于某种原因,当我使用的arduino蓝牙板所需的波特率设置为115200时,应用程序会在开始发送串行数据时立即冻结。然而,当我将它设置为9200,并使用我的arduino diecimilia时,应用程序不会冻结。

我需要波特率为115200,因为我想使用我的arduino蓝牙与我的机器人进行无线通信。如何阻止它冻结?

将数据发送到Arduino的代码

Private Sub ArduinoSetSerial()
     Dim ArduinoCom As String = ComPort.text
     _serialPort = New SerialPort()
     _serialPort.PortName = "COM" + Trim(ComPort.Text) 'Gets the ComPort from the Text box in the GUI of the App
     _serialPort.BaudRate = 9200 'When using any other Arduino PLC, this should be set to 9600. In this case, it is set to 115200 as the specififc Arduino PLC we are using requires it.
     _serialPort.DataBits = 8
     _serialPort.Handshake = 0
     _serialPort.ReadTimeout = 500
     _serialPort.WriteTimeout = 500

End Sub

Private Sub ArduinoOpenSerial()
     If Not _serialPort.IsOpen Then 'Opens the serial port if it isn't already open.
          _serialPort.Open()
     Else
          MsgBox("ARDUINO: SERIAL PORT CANNOT BE OPENED")
     End If
     _continue = True
End Sub

Private Sub ArduinoCloseSerial() 'Defines the CloseSerial Action executed on shutdown
     If _serialPort.IsOpen Then
          _serialPort.Close()
     End If
End Sub

Private Sub ArduinoSendByte(ByVal kinect_x As Single, ByVal kinect_y As Single, ByVal kinect_z As Single, ByVal kinect_j As Integer)
     Dim x, y, z, j As Byte
     Dim sx, sy As Single
     Dim HowOften As Integer
     ComStatus.Text = "NA" 'Set ComStatus Text to NA when not sending data

     x = Math.Abs(CByte(kinect_x)) 'The X co-ordinate of the requested JointID
     y = Math.Abs(CByte(kinect_y)) 'The Y co-ordinate of the requested JointID
     z = CByte(kinect_z) 'The Z co-ordinate of the requested JointID (Not used in this particular application)
     j = CByte(kinect_j) 'JointID
     x = x
     Dim ArduinoBuffer() As Byte = {x, y, z, j}
     If _serialPort.IsOpen Then
          ComStatus.Text = "OK" 'Write OK inthe ComStatus text box in the GUI
          _serialPort.Write(ArduinoBuffer, 0, ArduinoBuffer.Length) 'Actually sends all the information to the Arduino on the specified Serial Port
     End If
End Sub

0 个答案:

没有答案