Click here to Skip to main content
15,881,803 members
Articles / Desktop Programming / Win32
Tip/Trick

Communication Library Files - TCP Client/Server

Rate me:
Please Sign up or sign in to vote.
4.40/5 (4 votes)
2 Apr 2015GPL34 min read 27.6K   888   12   15
Source code and demo on general TCP client & server library mainly usable for / tested on SICK lidar devices

Introduction

This example shows how to use the TCP part of the communication library that a colleague and myself made for demonstration purposes on SICK A.G. Lidar devices (F.i. LMS5xx).

The total library itself enables the user to generate a 3D on screen Lidar image within 15 lines of code (without error handling, etc.) The total library will be posted on a general download page for easy maintenance.

This tip will handle the TCP client and server part of the library showing a simple client and server screen on the loop-back interface of the PC.

Why am I posting this? My goal is to create an easy, open platform for Lidar devices as they are more commonly used. If you see anything that should be different, feel free to change the source code and post the result as comment.

Background

Library representation

As mentioned, this tip only describes part of the total communication library (green block) which in its turn is part of a bigger framework (all blocks together) of libraries I internally use to demonstrate Lidar devices. The library is used for approximately 2 years now and works perfectly for our demos and field tests.

All the smaller individual parts that can be used to convert SICK Lidar data into 3D pointclouds, LAS, CSV, bitmap or 3D pointclouds with the least amount of effort giving you the power to generate awesome pointclouddata, 3D representation or bitmaps out of these devices.

This example shows you how to connect to a server or set up a server to let devices connect to you, read their data and respond to their incoming requests.

Later articles will describe the use of the UDP, Serial and USB part of the library. Also, I will post an article on the NetTools class which will enable you to match IPs to subnetmask, check out what's on your network and retrieve MAC-adresses of connected devices.

Example of a 3D Lidar distance scan (extracted pointcloud viewed with CloudCompare):

3D example scan of a Lidar device

Using the Code

A new instance can be made to the SICK_communication.TCP.Client or SICK_communication.Server class. All classes are setup to have the same look and feel so getting the hang of the Serial class shouldn't be a big problem. The reference files are added; these are the pre-build project files.

After instantiation, the connection can be made, or the server can be started.

VB.NET
'Client connection
Private Myclient As SICK_Communication.Ethernet.TCP_client
Myclient.Client_Connect("127.0.0.1", <portnr>)

After that, simply send data, check if any response is there and then read out (client example).

VB.NET
Myclient.SendString("Hello World!")

Dim mystring as string

If Myclient.Available > 0 Then
   mystring =Myclient.Readavailable_string
End If

If you want to read out the response as bytes, that's also possible. The underlaying .NET TCP class handles the start/stop of the telegrams by looking at the TCP framing.
NOTE: The class cannot be used for streams (as this would require different handling)!!!!!

Other Examples

Checking Connection Status

VB.NET
If Myclient.ConnectionActive = False Then
     'No connection
End If

Disconnecting

VB.NET
Myclient.Client_Disconnect()

Framing Types

VB.NET
 'Default <STX>/<ETX> framing enabled
 Myclient.SendString("Hello STX-ETX world!", SICK_Communication.Ethernet.TCP_client.FramingTypes.Stx_Etx)

'Special Framing for LMS400 (<STX><STX><STX><STX><4 bytes frame length>MESSAGE<CRC>
Myclient.SendString("Hello LMS400", SICK_Communication.Ethernet.TCP_client.FramingTypes.ColaB_Binairy)

 'No Framing
 Myclient.SendString("Hello Unframed World", SICK_Communication.Ethernet.TCP_client.FramingTypes.none)

Check the number of frames (NOT BYTES!!!) stored in the buffer

VB.NET
Dim FramesAvailable As Integer = Myclient.Available

Points of Interest

In the communication class, there is a reference to the structure library SICK_Work. This library is just a bunch of classes with little functionality but they form the pillar for a complete application (as the illustration shows). Because of this library, it's possible to use each library as an individual part as the interconnection between those libraries is not implemented within that same library itself.

The USB class makes use of a second library and is limited to communication with a SICK TiM3xx scanner (just because) which is a non documented feature of the device. Preferably, use the TiM35x type scanner as they are equipped with a documented TCP connection.

The communication class is also usable as a simple terminal program (like hercules setup from HW group, which I think is a very great tool) where you can set your own limitations. And with a little effort, you can make a keyboard-wedge program out of it. All in all, I think it's nice to make this publicly available.

Remember to share!!

History

The program itself is licensed as GPL software. So far, this is the latest adaptation to the library by myself and my colleague referred to as the V4-library. Improvements are always welcome, hope you enjoy using it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Help desk / Support
Netherlands Netherlands
Working at a help desk for more then 10 years now, last few years being more into programming examples for industrial sensors and camera's. Expertise Vision sensors and camera's, last two years trying to explore the possibilities of laser scanning devices in industrial applications.

Comments and Discussions

 
QuestionBarcode Scanner Sick clv62 Pin
mauricio tapia23-May-22 11:57
mauricio tapia23-May-22 11:57 
AnswerRe: Barcode Scanner Sick clv62 Pin
Chris Jorna24-May-22 9:07
Chris Jorna24-May-22 9:07 
GeneralRe: Barcode Scanner Sick clv62 Pin
mauricio tapia27-Jun-22 9:31
mauricio tapia27-Jun-22 9:31 
GeneralRe: Barcode Scanner Sick clv62 Pin
Chris Jorna27-Jun-22 9:37
Chris Jorna27-Jun-22 9:37 
GeneralRe: Barcode Scanner Sick clv62 Pin
mauricio tapia28-Jun-22 2:50
mauricio tapia28-Jun-22 2:50 
QuestionCommunication Library for Sick Pin
Member 149856516-Nov-20 8:20
Member 149856516-Nov-20 8:20 
QuestionSick 3D visual Block lib is missing Pin
sandeepdhank2-Jul-18 2:02
sandeepdhank2-Jul-18 2:02 
QuestionIs there a full release of the Library that you have been mentioning ? Pin
ED GIRARDI10-Jul-17 8:04
ED GIRARDI10-Jul-17 8:04 
QuestionUsing Communication Library files Pin
Member 1240690522-Mar-16 5:30
Member 1240690522-Mar-16 5:30 
QuestionProblem with files...? Pin
Jyri Peltola17-Apr-15 3:01
Jyri Peltola17-Apr-15 3:01 
AnswerRe: Problem with files...? Pin
Chris Jorna17-Apr-15 22:33
Chris Jorna17-Apr-15 22:33 
QuestionWhre the zip file ?? Pin
SANJAY DUSANE17-Apr-15 1:35
professionalSANJAY DUSANE17-Apr-15 1:35 
AnswerRe: Whre the zip file ?? Pin
Chris Jorna17-Apr-15 22:34
Chris Jorna17-Apr-15 22:34 
Questionplease remove VS artifacts from your zip files Pin
sx20083-Apr-15 11:30
sx20083-Apr-15 11:30 
AnswerRe: please remove VS artifacts from your zip files Pin
Mehdi Gholam5-Apr-15 20:12
Mehdi Gholam5-Apr-15 20:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.