Author Topic: TCP Client Socket  (Read 7677 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
TCP Client Socket
« on: January 21, 2018, 12:45:54 PM »
The attached component is a group of files that will add a generic TCP client. After adding the files and building the solution, you will get a new component in the Toolbox. Add this to your form, set the IPAddress and port number, then double click the component to get back to the code that will receive the data from the server.

An example of its use would be an Serial to Ethernet converter with a barcode scanner hooked up to the serial port. This component will receive the data from the scanner.

Installation and use:

- Download and unzip the files
- Open your AdvancedHMI solution in Visual Studio
- In Solution Explorer, expand down the AdvancedHMIControls project
- Right click the PurchasedControls folder and select Add-Existing Items
- Browse to the extracted files and select all 4 files
- Build the solution
- Open the Mainform
- From the ToolBox, add a GenericTCPClient to your form
- Set the IPAddress and port to that of your TCP server
- Double click the GenericTcpClient1 component which will take you back to the code
- Enter this code:

MsgBox ("Received: " & e.DataAsString)

- Run the application and have your server send data


It also has the capability to send data back to the server like this:

GenericTCPClient1.SendString("MyDataString")
« Last Edit: January 21, 2018, 12:50:09 PM by Archie »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: TCP Client Socket
« Reply #1 on: January 21, 2018, 02:12:02 PM »
This is a software tool that can be used for testing the GenericTCPClient. Use the TCP Server tab

https://www.hw-group.com//products/hercules/index_en.html

seth350

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: TCP Client Socket
« Reply #2 on: January 25, 2018, 09:35:41 PM »
Now this is something I could use. Thank you Archie!
I need to send a String to a Domino DSeries laser marker and I think this will do the trick.

Definitely easier to do it in AHMI than in the plc, in my case that is.

Holmux

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: TCP Client Socket
« Reply #3 on: December 17, 2020, 01:03:23 PM »
Thanks Archie

I know this is an old post, but You just saved this Christmas for me :)

/Holmux 

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: TCP Client Socket
« Reply #4 on: November 13, 2024, 08:10:33 PM »
I tested the GenericTCPClient.zip file shared by Archie and verified its functionality in both directions using Hercules.

Configuration: Set to localhost 127.0.0.1, Port=7001
TerminatingByteValue (not TerminatingCharacters) is set to 10 (LF).

Client to Server Communication:
The client sent "1234" & <CR> using TCPClient.SendString(TxtSend.Text & vbCr).
Observed that a <LF> was automatically appended at the end.

Server to Client Communication:
The server sent "test from server$0D$0A", and the client successfully received it, stripping the <LF> terminating character. The <CR> is in the data , but not display in the text box.

« Last Edit: November 13, 2024, 08:19:42 PM by bachphi »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: TCP Client Socket
« Reply #5 on: November 16, 2024, 04:01:03 PM »
This version replaces TerminatingByteValue with TerminatingCharacters, enabling it to check for 0, 1, or multiple terminating characters.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================