| gclib 2.0.7 Communications API for Galil controllers and PLCs |

IP_Assigner.vb
Go to the documentation of this file.
1 Partial Public Module Examples
2 Public Function IP_Assigner(gclib As Gclib, serial_num As String, address As Byte) As Integer
3 Dim controller_found As Boolean = False
4 Dim requests() As String
5
6 Do 'Loop while no requests are found.
7 Console.WriteLine("Searching...")
8
9 'Listen for ~5 secods for controllers requesting IP addresses.
10 requests = gclib.GIpRequests()
11
12 For Each request In requests
13 Console.WriteLine(request)
14 Next request
15 Loop While (requests.Count() < 1)
16
17 For Each request In requests
18 Dim controller_params() As String = request.Split({", "}, StringSplitOptions.None)
19
20 'Parameters are ordered as
21 '[Model #], [Serial #], [MAC Address], [Connection Name], [IP Address]
22
23 If (controller_params.Count() < 5) Then
24 Console.WriteLine("Unexpected controller format")
25 Return GALIL_EXAMPLE_ERROR
26 End If
27
28 Dim mac As String = controller_params(2)
29 Dim ip As String = controller_params(4)
30
31 'If controller contains the user entered serial number
32 If (serial_num = controller_params(1)) Then
33 Console.WriteLine("Controller Match Found")
34 controller_found = True
35
36 'Splits the found ip address into individual bytes
37 Dim ip_bytes() As String = ip.Split(".")
38
39 'Rebuild the ip address using the user provided address as the last byte
40 Dim new_ip = $"{ip_bytes(0)}.{ip_bytes(1)}.{ip_bytes(2)}.{address}"
41
42 'Assign the New ip address to the controller
43 gclib.GAssign(new_ip, mac)
44
45 'Open a connection at the New ip address
46 gclib.GOpen(new_ip)
47
48 'Burns the newly assigned ip address to non-volatile EEPROM memory
49 gclib.GCommand("BN")
50
51 Console.WriteLine("IP Address assigned")
52
53 'Write the connection string to the console
54 Console.WriteLine(gclib.GInfo())
55
56 Exit For
57 End If
58 Next request
59
60 If Not controller_found Then
61 Console.Write("No controller matched the entered serial number")
62 End If
63
64 Return GALIL_EXAMPLE_OK
65
66 End Function
67 End Module
gclib
Provides a class that binds to gclib's unmanaged dll. Wraps each call and provides a more user-friend...
Definition: gclib.cs:68
GIpRequests
GCLIB_DLL_EXPORTED GReturn GCALL GIpRequests(GCStringOut requests, GSize requests_len)
Uses GUtility(), G_UTIL_GCAPS_IPREQUEST or G_UTIL_IPREQUEST to provide a list of all Galil controller...
Definition: gclibo.c:106
examples.Examples
﻿partial Module Examples
Definition: Commands.vb:4