Introduction
This example shows how to use the NetTools 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 NetTools NetPopulation
part of the library showing a simple way to get your network information. The tools show you which NICs your PC has (IP address, MAC address, connection speed, DHCP enabled (bool
), on/off, etc.). It also shows you what IP-address (that matches the subnet of your NICs, so are TCP connectable) your network has and what the MAC addresses of these IPs are.
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
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 can be used to convert SICK Lidar data into 3D pointclouds, LAS, CSV, bitmap or 3D pointclouds with the least of effort giving you the power to generate awesome pointclouddata, 3D representation or bitmaps out of these devices.
This example shows you how to find devices in a network that are connectable. The ideal bonus on this part is that from the online IPs the MAC-addresses are resolved using ARP (basically this class asynchronous pings all possible IPs, checks whether they return information and then checks the ARP-table of the PC to find out the MAC-address). Also, the tool retrieves your network card information hassle free.
In my other tips, I will describe the use of the Serial and TCP part of the library. Later on, these connections will be used to retrieve the LIDAR data and convert it to something useful.
Using the Code
The attached example is made up of smaller pieces, the example retrieves your network card information and checks the online and offline IPs. All is done just by instantiating the class itself (which will start a multithreaded process in the background) and monitor its process:
Public Mynetwork As SICK_Communication.NetTools.NetPopulation
Public Sub Populate()
Mynetwork = New SICK_Communication.NetTools.NetPopulation
Do While Mynetwork.Busy = True
Me.Text = String.Format("Probing network {0}% complete", Mynetwork.PercentCompleted)
Application.DoEvents()
Loop
Me.Text = String.Format("Done - {0} online | {1} Offline", _
Mynetwork.OnlineIPs.Count, Mynetwork.OfflineIPs.Count)
End Sub
Once the class is done populating, read out all the found information.
Example of a listbox
that will be filled with the Network Card information:
Public Sub NICtoList()
Dim MyNics() As SICK_Communication.Ethernet.NICinfo = Mynetwork.MyNICs
ListBox1.Items.Clear()
For Each Adapter As SICK_Communication.Ethernet.NICinfo In MyNics
ListBox1.Items.Add(String.Format("{0} : {1} :{2} (status {3})", _
Adapter.MACaddress, Adapter.IPaddress, Adapter.Adaptername, Adapter.AdapterActive))
Next
End Sub
Adding the Online IPs info (IP-address and MAC address) to a listbox
:
Public Sub OnlineToList()
ListBox2.Items.Clear()
For Each ST As SICK_Work.SICK_NetTools.NetInfo In Mynetwork.OnlineIPClass
ListBox2.Items.Add(String.Format("{0} : {1}", ST.IPaddress, ST.MACaddress))
Next
End Sub
To have easy sorting, I decided to change the MAC-address for the target devices to our company name instead our full MAC-range. This will make it easier to find these specific devices (you don't need to know the MAC range for the LIDAR devices).
And the offline IP-address (which is only string
as nothing is connected and no further information is available).
Public Sub OffLineToList()
ListBox3.Items.Clear()
For Each ST As String In Mynetwork.OfflineIPs
ListBox3.Items.Add(ST)
Next
End Sub
Screenshot of the example code is as shown below:
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 reference files are a pre-build library distribution which are needed for the example to be build.
The idea of this class was to make finding devices easier. Although now a days, I'm not using it much, I still think it's worth posting.
Note that IP addresses 255 and 0 are not checked as these are primarily broadcast addresses and not suitable for use (in case you haven't noticed that the example code finds 31 online and 222 offline (together 253 instead of 255) IP addresses)
Remember to share!!
History
The program itself is licensed as GPL software. Some examples were picked from the internet. If I accidentally used anything without permission or overlooked anything, please let me know and I'll correct my errors.
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.
Other Tips