I have a simple vb.net program that i'm trying to send a FINS Command and receive the response using UDP. I've been using the following question as a reference point FINS Commands C#, but believe I've got something wrong with my Packet, or perhaps I just don't have something quite right.
My current program has 4 text boxes (TBIP
, TBPORT
, TBSEND
, TBReceive
). When I run the program, I type in the IP, Port, Packet info to send, and click a button. What i'd like to have happen is the received information sesnt to TBReceive
.
My Form Load code looks like this:
Dim publisher As New Sockets.UdpClient(0)
Dim Subsriber As New Sockets.UdpClient(9600)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Subsriber.Client.ReceiveTimeout = 5000
Subsriber.Client.Blocking = False
End Sub
My Button Click:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
publisher.Connect(TBIP.Text, TBPort.Text)
Dim Sendbytes() As Byte = ASCII.GetBytes(TBSend.Text)
publisher.Send(Sendbytes, Sendbytes.Length)
Subsriber.Client.Blocking = True
Timer1.Start()
End Sub
My Timer:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Dim ep As IPEndPoint = New IPEndPoint(IPAddress.Any, 0)
Dim rcvbytes As [Byte]() = Subsriber.Receive(ep)
Dim returndata As String = ASCII.GetString(rcvbytes)
TBReceive.Text = returndata.ToString
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
On the Omron PLC, I'm trying to read CIO 100. My ip address is 10.0.1.91 so my string is below. (5B is the last octet):
80 00 02 01 02 00 01 5B 00 12 01 01 00 00 12 34
I have added spaces above between the HEX bits for easy reading.
Could the first problem be i'm converting to or trying to send the info as ASCII? Any help would be appreciated.