For Ethernet-based communication, GalilTools will configure two Ethernet handles by default. One TCP handle is used for command-and-response traffic, and one UDP handle is used for all asynchronous data coming off of the motion controller. Asynchronous data consists of Unsolicited Messages (either MG commands or error text), Ethernet Interrupts, and Data Record packets (via DR).
Unsolicited messages can also be transmitted over a TCP handle for better transport reliability. In order to do this, a second connection is established and the CF command is used to set the unsolicited message handle. Below is a simple Visual Basic console application which demonstrates this operation.
'Add a reference to 'System.Windows.Forms.dll'
Imports System.Windows.Forms 'allows for more event-friendly code in console apps
Module Module1
WithEvents g As Galil.Galil 'main connection
WithEvents m As Galil.Galil 'messages handle
Sub Main()
Try
g = New Galil.Galil
m = New Galil.Galil
'-MG 0 means don't set up for unsolicited messages
g.address = "192.168.1.12 -MG 0" 'main command and response handle (TCP) -- also fields Interrupts and Records over secondary UDP handle
'-S means connect silently. Just make the TCP connection and that's all. No extra discovery or configuration
m.address = "192.168.1.12 -S" 'TCP unsolicited messages handle.
m.command("CFI") 'Send messages to m handle (TCP). This connection should usually NOT be used for commands.
Console.WriteLine("Connected to main command handle " + g.connection())
Console.WriteLine("Connected to unsolicited messages handle " + m.command("WH")) 'note, m.connection() is blank because of -S
Console.WriteLine(g.command("TH"))
g.programDownload("MG""Hello from DMC "",TIME{N};WT5000;JP0") 'sample code to generate messages
g.command("XQ")
While (1) 'spin forever -- dummy code for this example
Application.DoEvents() 'service message event
Threading.Thread.Sleep(5000) 'sleep for a while
Console.WriteLine("Command Response: " + g.command("MGTIME")) 'send a command over the main connection (TCP)
End While
Catch ex As Exception
Console.WriteLine(ex.Message) 'if error occurs
End Try
End Sub
Sub g_onMessages(ByVal message As String) Handles m.onMessage 'message event
Console.WriteLine("Message Received: " + message)
End Sub
End Module