| gclib 528 Communications API for Galil controllers and PLCs |

Motion_Complete.vb
1 Partial Public Module Examples
2 Public Function Motion_Complete(gclib As Gclib)
3 Console.WriteLine("*************************************************************")
4 Console.WriteLine("Example GInterrupt() usage")
5 Console.WriteLine("*************************************************************")
6
7 'Simple check for appropriate communication bus
8 'EI will fail below if interrupts are Not supported at all
9 Dim ei_support = False
10
11 If gclib.GCommand("WH").Contains("IH") Then
12 ei_support = True
13 End If
14
15 If Not ei_support Then
16 Console.WriteLine("No support on this bus")
17 Return GALIL_EXAMPLE_ERROR
18 End If
19
20 'Flush interrupts
21 gclib.GCommand("EI0,0") 'Turn off interrupts
22 gclib.GTimeout(0) 'Zero timeout
23
24 'Flush interrupts, status will be zero when queue Is empty
25 While (gclib.GInterrupt() > 0)
26 End While
27
28 gclib.GTimeout(-1) 'Restore timeout
29
30 'Independent Motion
31 gclib.GCommand("DP 0,0") 'define position zero On A And B
32 Console.WriteLine("Position: " + gclib.GCommand("RP")) 'Print reference position
33
34 gclib.GCommand("SP 4000,4000") 'Set up speed
35 gclib.GCommand("AC 1280000, 1280000") 'acceleration
36 gclib.GCommand("DC 1280000, 1280000") 'deceleration
37 gclib.GCommand("PR 8000, 10000") 'Position Relative. B will take longer To make its move.
38 gclib.GCommand("SH AB") 'Servo Here
39
40 Console.WriteLine("Beginning independent motion...")
41 gclib.GCommand("BG AB") 'Begin motion
42 Check_Interrupts(gclib, "AB") 'Block until motion Is complete On axes A And B
43 Console.WriteLine("Motion Complete on A and B")
44 Console.WriteLine("Position: " + gclib.GCommand("RP")) 'Print reference position
45
46 Return GALIL_EXAMPLE_OK
47 End Function
48
49 Private Sub Check_Interrupts(gclib As Gclib, axes As String)
50 'bit mask of running axes, axes arg Is trusted to provide running axes.
51 'Low bit indicates running.
52 Dim axis_mask As Byte = &HFF
53
54 'iterate through all chars in axes to make the axis mask
55 For i = 0 To axes.Length - 1
56
57 'support just A-H
58 Select Case (axes(i))
59 Case "A"
60 axis_mask = axis_mask And &HFE
61 Exit Select
62 Case "B"
63 axis_mask = axis_mask And &HFD
64 Exit Select
65 Case "C"
66 axis_mask = axis_mask And &HFB
67 Exit Select
68 Case "D"
69 axis_mask = axis_mask And &HF7
70 Exit Select
71 Case "E"
72 axis_mask = axis_mask And &HEF
73 Exit Select
74 Case "F"
75 axis_mask = axis_mask And &HDF
76 Exit Select
77 Case "G"
78 axis_mask = axis_mask And &HBF
79 Exit Select
80 Case "H"
81 axis_mask = axis_mask And &H7F
82 Exit Select
83 End Select
84 Next
85
86 'send EI axis mask to set up interrupt events.
87 gclib.GCommand("EI " + (Not axis_mask).ToString())
88
89 Dim status As Byte
90
91 While (axis_mask <> &HFF) 'wait for all interrupts to come in
92 status = gclib.GInterrupt()
93 Select Case (status)
94 Case &HD0 'Axis A complete
95 axis_mask = axis_mask Or &H1
96 Exit Select
97 Case &HD1 'Axis B complete
98 axis_mask = axis_mask Or &H2
99 Exit Select
100 Case &HD2 'Axis C complete
101 axis_mask = axis_mask Or &H4
102 Exit Select
103 Case &HD3 'Axis D complete
104 axis_mask = axis_mask Or &H8
105 Exit Select
106 Case &HD4 'Axis E complete
107 axis_mask = axis_mask Or &H10
108 Exit Select
109 Case &HD5 'Axis F complete
110 axis_mask = axis_mask Or &H20
111 Exit Select
112 Case &HD6 'Axis G complete
113 axis_mask = axis_mask Or &H40
114 Exit Select
115 Case &HD7 'Axis H complete
116 axis_mask = axis_mask Or &H80
117 Exit Select
118 End Select
119 End While
120 End Sub
121 End Module