1 Partial Public Module Examples
2 Public Function Message(gclib As Gclib)
3 Console.WriteLine("***************************************************************")
4 Console.WriteLine("Example GMessage() usage")
5 Console.WriteLine("***************************************************************")
7 gclib.GCommand("TR0") 'Turn off trace
9 'This program will force one message to appear as two separate packets.
10 gclib.GProgramDownload("MG ""HELLO "" {N}" + vbCr +
11 "MG ""WORLD """ + vbCr +
14 gclib.GCommand("XQ") 'Begins execution Of program On controller
19 'It Is important to note that a message can be too large to read in one
20 'GMessage() call. Keep calling GMessage() while there are no errors to
21 'get the full message.
23 'While still receiving messages
24 buf = gclib.GMessage()
26 For b = 0 To buf.Length - 1 'While message characters are in the buffer
28 msg += buf(b) 'Copy chars from buffer To message
30 'If the message ends in "\r\n" it Is ready to be terminated
31 If (msg.Length > 2) AndAlso (msg(msg.Length - 1) = vbLf) AndAlso (msg(msg.Length - 2) = vbCr) Then
32 Console.WriteLine(msg)
33 msg = "" 'Reset message index
37 buf = gclib.GMessage()
41 'Downloads program to the controller
42 gclib.GCommand("TR1") 'Turn On trace
43 gclib.GProgramDownload(
53 gclib.GCommand("XQ") 'Begins execution Of program On controller
55 'Lines returned by GMessage() can be one of three types
56 '1) Standard Lines begin with a space (" ")
57 '2) Crashed code begins with a question mark ("?")
58 '3) Trace Lines begin with a line number ("1,6,15...")
60 'While still receiving messages
61 buf = gclib.GMessage()
63 For b = 0 To buf.Length - 1 'While message characters are in the buffer
65 msg += buf(b) 'Copy chars from buffer To message
67 'If the message ends in "\r\n" its ready to be terminated
68 If (msg.Length > 2) AndAlso (msg(msg.Length - 1) = vbLf) AndAlso (msg(msg.Length - 2) = vbCr) Then
70 If (msg(0) = " ") Then 'Standard Lines begin with a space (" ")
71 Console.Write("Standard Line: ")
72 ElseIf (msg(0) = "?") Then 'Crashed code begins with a question mark ("?")
73 Console.Write("Crashed Code: ")
74 Else 'Trace Lines begin with a line number ("1,6,15...")
75 Console.Write("Trace Line: ")
77 Console.WriteLine(msg)
81 buf = gclib.GMessage()
84 Return Examples.GALIL_EXAMPLE_OK