Hello, I need to get data from a matrix code reader connected to a PC through the ethernet port and a TCP IP address.
I set everything up and tried to see if the device works with the Hercules program, and in fact I see the data read,
But I should build an application in vb.net that uses this data, so when a code passes under the laser I should intercept it in my application.
I tried with various sockets but I can't, as long as it is chat it works but capturing the data from the device nothing.
Below is the code of the client which, however, sends what is in the textbox. Instead I would like it to send what I read from the 2D code reader which is always active.
What I have tried:
Imports System.Net, System.Net.Sockets
Imports System.Text.ASCIIEncoding
Public Class frm_Client
Dim client As Socket
Dim host As String = "127.0.0.1" '"192.168.3.100"
'Dim port As Integer = "6969" '"51236"
Dim port As Integer = "51236"
Private Sub frm_Client_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
client = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim IP As IPAddress = IPAddress.Parse(host)
Dim xIpEndPoint As IPEndPoint = New IPEndPoint(IP, port)
client.BeginConnect(xIpEndPoint, New AsyncCallback(AddressOf OnConnect), Nothing)
btnConnect.Enabled = False
End Sub
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Dim bytes As Byte() = ASCII.GetBytes(txtMessage.Text)
client.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, New AsyncCallback(AddressOf OnSend), client)
End Sub
Private Sub OnConnect(ByVal ar As IAsyncResult)
client.EndConnect(ar)
MessageBox.Show("Connected")
End Sub
Private Sub OnSend(ByVal ar As IAsyncResult)
client.EndSend(ar)
End Sub
End Class