| gclib 1.34.15 Communications API for Galil controllers and PLCs |

Remote_Client.vb
1 Partial Public Module Examples
2 ''' <summary>
3 ''' Demonstrates various uses of GListServers() and GSetServer()
4 ''' </summary>
5 ''' <returns>The success status Or error code of the function.</returns>
6 ''' <remarks>See remote_client_example.cs for an example.</remarks>
7 Function Remote_Client() As Integer
8 Dim gclib = New Gclib()
9
10 Console.WriteLine("<s> List available servers on the network" + vbNewLine +
11 "<h> List available hardware on currently connected server" + vbNewLine +
12 "<0-9> Enter numbers 0-9 to connect to a server by index" + vbNewLine +
13 "<l> Set active server back to local server" + vbNewLine +
14 "<q> Quit")
15
16 Dim loop_bool = True
17 Dim servers_list As String() = Array.Empty(Of String)
18
19 While loop_bool
20 Dim input As Char = Console.ReadKey(True).KeyChar
21
22 If input = "q" Then
23 loop_bool = False
24 ElseIf input = "s" Then
25 Console.WriteLine("Available Servers:")
26 servers_list = gclib.GListServers()
27 Print_Servers_List(servers_list)
28 ElseIf input >= "0" And input <= "9" Then
29 Dim index As Integer = Convert.ToInt16(input) - Convert.ToInt16("0"c)
30 If servers_list.Length > 0 And index < servers_list.Length Then
31 gclib.GSetServer(servers_list(index))
32 Console.WriteLine("Server set to: " + servers_list(index))
33 End If
34 ElseIf input = "l" Then
35 gclib.GSetServer("Local")
36 Console.WriteLine("Server set to: Local")
37 ElseIf input = "h" Then
38 Dim addresses As String() = gclib.GAddresses()
39
40 For Each address As String In addresses
41 Console.WriteLine(address)
42 Next
43 End If
44 End While
45
46 Return Examples.GALIL_EXAMPLE_OK
47 End Function
48
49 Private Sub Print_Servers_List(servers_list As String())
50 If servers_list.Length = 0 Then
51 Console.WriteLine("none")
52 Else
53 For i As Integer = 0 To servers_list.Length - 1
54 Console.WriteLine("<" + i.ToString() + "> " + servers_list(i))
55 Next
56 End If
57
58 End Sub
59 End Module