Skip to main content

The GalilTools COM library provides event-driven functions for asynchronous controller data. One of the more popular events is the onMessage() function which runs automatically whenever a message is received from the controller. This data usually comes from controller embedded code using the MG command.

There are times, however, when the onMessage() function is not desirable. This can be due to a programming environment's lack of support or inconvenient implementation of events. It can also be due to a programmer's desire to use strictly procedural programming and skip over the use of events.

When using Ethernet-based communications there is a simple method for opening an extra connection and using the read() function to receive messages waiting in the driver's input buffer. The example below takes this approach one step further and opens up yet another connection to the controller to receive a second channel of messages. With the following example there are two streams of messages which can be used, for example, for data collection and for user messages.

The code running on the controller can decide where to send the data with the brace routing notation, for example:

MG"I am G"{EG};' Sends data to channel one (m1)
MG"I am H"{EH};' Sends data to channel two (m2)

The following is the VB code that demonstrates the method for receiving MG messages via read().
Module Module1
    Sub Main()
        'Command and response handle
        Dim g As New Galil.Galil
        g.address = "192.168.1.5 -mg 0 -ei 0 -dr 0"

        'message handle one
        Dim m1 As New Galil.Galil
        m1.address = "192.168.1.5 -s"
        m1.command("HSS=G") 'set this handle to handle G. This object will receive messages of the form MG"The Message"{EG}

        'message handle two
        Dim m2 As New Galil.Galil
        m2.address = "192.168.1.5 -s"
        m2.command("HSS=H") 'set this handle to handle H. This object will receive messages of the form MG"The Message"{EH}

        g.command("CW2") 'Do not set most significant bit of messages. Read() reads raw, so we don't want this flag
        g.programDownload("MG""I am G""{EG};MG""I am H""{EH};WT1000;JP0;EN") 'sample program
        g.command("XQ") 'start the program

        Console.WriteLine(g.connection)
        Dim string1 As String = ""
        Dim string2 As String = ""
        Dim timer As New Stopwatch
        timer.Start()
        While (timer.Elapsed.Seconds < 5)
            string1 = m1.read()
            If string1.Count <> 0 Then
                Console.WriteLine("m1 read " + string1.Count.ToString + " bytes" + vbCrLf + string1)
            End If
            string2 = m2.read()
            If string2.Count <> 0 Then
                Console.WriteLine("m2 read " + string2.Count.ToString + " bytes" + vbCrLf + string2)
            End If
        End While
        timer.Stop()
        g.command("ST")
    End Sub
End Module

Here is the program output
192.168.1.5 -ei 0 -mg 0 -dr 0, DMC4040 Rev 1.1d1, 5254, IHB
m1 read 8 bytes
I am G

m2 read 8 bytes
I am H

m1 read 8 bytes
I am G

m2 read 8 bytes
I am H

m1 read 8 bytes
I am G

m2 read 8 bytes
I am H

m1 read 8 bytes
I am G

m2 read 8 bytes
I am H

m1 read 8 bytes
I am G

m2 read 8 bytes
I am H

m1 read 8 bytes
I am G

m2 read 8 bytes
I am H