我正在尝试使用Visual Basic编写的应用程序进行通信。当我从应用程序向板发送数据时,一切都很完美,但在其他方向上它并不起作用。我确实通过wireshark跟踪网络流量,一切似乎都可以。当从带有PIC的电路板向应用程序(PC)发送数据时,我可以在wireshark中看到它,但是我无法检测到应用程序内部的任何数据我认为我的问题在于应用程序,我不是很擅长VB编程,一点也不好......这是我的第一个程序..我已经附上了代码,所以你可以看到我做了什么。应用程序(PC)IP地址192.168.1.11,pic ip地址192.168.1.10(掩码255.255.255.0)。所以,如果有人能给我建议,我将非常感激.. PS。抱歉我的英语不好。
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.Encoding
Imports System.Text
Public Class Form1
Dim controlData() As Byte = {&H55, &H55, &H55, &H55, &H55}
Const portTo As Integer = 5000
Const portFrom As Integer = 5001
Dim udpTransmit As New Sockets.UdpClient(portFrom)
Dim udpReceive As New Sockets.UdpClient(portTo)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnTo.Click
udpTransmit.Connect(tbToIp.Text, portTo)
udpTransmit.Send(controlData, controlData.Length)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Dim ep As New IPEndPoint(tbToIp.Text, portTo)
Do
Dim receiveData() As Byte = udpReceive.Receive(ep)
text1.Text = ASCII.GetString(receiveData)
Loop
Catch ex As Exception
End Try
End Sub
End Class
[PIC到PC的数据表格] [从PC到PIC的数据] 1