Hi;
I think i can help, however you need to be more clear about your issue.
I I'll put here some code,
VB2008 Net Code;
First you need to add the serilport class to your project.
Then, at Form Load, you need to configure and open your SerialPort;Code:Public Class Form1 Dim WithEvents SerialPort1 As New IO.Ports.SerialPort
This handles the recetion from the buffer of the com port, and then i have a If statment to do the actions that need to be perfomed acording with the received data.Code:Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load SerialPort1.PortName = "COM1" SerialPort1.Parity = IO.Ports.Parity.None SerialPort1.BaudRate = 19200 SerialPort1.DataBits = 8 SerialPort1.StopBits = 1 SerialPort1.Open() SerialPort1.Write(Chr(13) & "Hugo Oliveira" & Chr(13)) End Sub
Code:Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Dim recepcao As String recepcao = SerialPort1.ReadExisting If recepcao = "%TE" Then GetCursorPos(rect) SetCursorPos(rect.X - 1, rect.Y) ElseIf recepcao = "%TD" Then GetCursorPos(rect) SetCursorPos(rect.X + 1, rect.Y) ElseIf recepcao = "%TC" Then GetCursorPos(rect) SetCursorPos(rect.X, rect.Y - 1) ElseIf recepcao = "%TB" Then GetCursorPos(rect) SetCursorPos(rect.X, rect.Y + 1) ElseIf recepcao = "%TE1" Then GetCursorPos(rect) SetCursorPos(rect.X - 10, rect.Y) ElseIf recepcao = "%TD1" Then GetCursorPos(rect) SetCursorPos(rect.X + 10, rect.Y) ElseIf recepcao = "%TC1" Then GetCursorPos(rect) SetCursorPos(rect.X, rect.Y - 10) ElseIf recepcao = "%TB1" Then GetCursorPos(rect) SetCursorPos(rect.X, rect.Y + 10) ElseIf recepcao = "%TE2" Then GetCursorPos(rect) SetCursorPos(rect.X - 20, rect.Y) ElseIf recepcao = "%TD2" Then GetCursorPos(rect) SetCursorPos(rect.X + 20, rect.Y) ElseIf recepcao = "%TC2" Then GetCursorPos(rect) SetCursorPos(rect.X, rect.Y - 20) ElseIf recepcao = "%TB2" Then GetCursorPos(rect) SetCursorPos(rect.X, rect.Y + 20) End If End Sub
With this piece of code in VB, you must with 100% sure, receive data from Com Port.
Where is a part of code, from sendinf the data out of the pic, in PBP. I use the Debug command, but you can use Hserout, if you are using te Uart of the PIC, or Serout, Serout2 command.
Hope it can hep.Code:Main: if JX>70 and JX<=100 then DEBUG "%TE" pause 20 endif if JX>0 and JX<=70 then DEBUG "%TE1" pause 20 endif if Jx>180 and Jx<210 then DEBUG "%TD" pause 20 endif if Jx>=210 then DEBUG "%TD1" pause 20 endif ' JoyStick Eixo Y ' ==================================================================== if JY>70 and JY<=100 then DEBUG "%TB" pause 20 endif if JY>0 and JY<=70 then DEBUG "%TB1" pause 20 endif if Jy>180 and Jy<210 then DEBUG "%TC" pause 20 endif if Jy>=210 then DEBUG "%TC1" pause 20 endif ' Axis - Eixo X ' ==================================================================== if Ax<100 then DEBUG "%TE2" pause 20 endif if Ax>140 then DEBUG "%TD2" pause 20 endif ' Axis - Eixo Y ' ==================================================================== if Ay<110 then DEBUG "%TB2" pause 20 endif if Ay>140 then DEBUG "%TC2" pause 20 endif ' Botões ' ==================================================================== IF BE = 0 then DEBUG "%RL1" pause 80 endif IF BD = 0 then DEBUG "%RD1" pause 80 endif goto Main





Bookmarks