gclib  2.0.8
Communications API for Galil controllers and PLCs
Message.vb
Go to the documentation of this file.
1 Partial Public Module Examples
2  Public Function Message(gclib As Gclib)
3  Console.WriteLine("***************************************************************")
4  Console.WriteLine("Example GMessage() usage")
5  Console.WriteLine("***************************************************************")
6 
7  gclib.GCommand("TR0") 'Turn off trace
8 
9  'This program will force one message to appear as two separate packets.
10  gclib.GProgramDownload("MG ""HELLO "" {N}" + vbCr +
11  "MG ""WORLD """ + vbCr +
12  "EN")
13 
14  gclib.GCommand("XQ") 'Begins execution Of program On controller
15 
16  Dim buf = ""
17  Dim msg = ""
18 
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.
22 
23  'While still receiving messages
24  buf = gclib.GMessage()
25  While buf <> ""
26  For b = 0 To buf.Length - 1 'While message characters are in the buffer
27 
28  msg += buf(b) 'Copy chars from buffer To message
29 
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
34  Exit While
35  End If
36  Next
37  buf = gclib.GMessage()
38  End While
39 
40 
41  'Downloads program to the controller
42  gclib.GCommand("TR1") 'Turn On trace
44  "i=0" + vbCr +
45  "#A" + vbCr +
46  "MGi" + vbCr +
47  "i=i+1" + vbCr +
48  "WT100" + vbCr +
49  "JP#A,i<1" + vbCr +
50  "i=i/0" + vbCr +
51  "EN")
52 
53  gclib.GCommand("XQ") 'Begins execution Of program On controller
54 
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...")
59 
60  'While still receiving messages
61  buf = gclib.GMessage()
62  While buf <> ""
63  For b = 0 To buf.Length - 1 'While message characters are in the buffer
64 
65  msg += buf(b) 'Copy chars from buffer To message
66 
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
69 
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: ")
76  End If
77  Console.WriteLine(msg)
78  msg = ""
79  End If
80  Next
81  buf = gclib.GMessage()
82  End While
83 
84  Return Examples.GALIL_EXAMPLE_OK
85  End Function
86 End Module
string GCommand(string Command, bool Trim=true)
Used for command-and-response transactions.
Definition: gclib.cs:257
void GProgramDownload(string program, string preprocessor="")
Allows downloading of a DMC program from a string buffer.
Definition: gclib.cs:465
Provides a class that binds to gclib's unmanaged dll. Wraps each call and provides a more user-friend...
Definition: gclib.cs:68
GCLIB_DLL_EXPORTED GReturn GCALL GCommand(GCon g, GCStringIn command, GBufOut buffer, GSize buffer_len, GSize *bytes_returned)
Performs a command-and-response transaction on the connection.
GCLIB_DLL_EXPORTED GReturn GCALL GMessage(GCon g, GCStringOut buffer, GSize buffer_len)
Provides access to unsolicited messages from the controller.
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownload(GCon g, GCStringIn program, GCStringIn preprocessor)
Downloads a program to the controller's program buffer.
GReturn message(GCon g)
Demonstrates how to receive messages from the controller and detect differences in Trace and crashed ...
Definition: message.cpp:14
partial Module Examples
Definition: Commands.vb:4