Click here to Skip to main content
14,980,146 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Richard MacCutchan 6-Mar-21 12:00pm
   
Why are you using the loopback address?
Gerry Schmitz 7-Mar-21 14:25pm
   
Use the "Hercules" program. You skipped over that part too cheerily.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900