Communication Library Files - TCP Client/Server - CodeProject


: 4


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.


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.

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

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

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

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



Framing Types

 '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

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!!


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.