VisionBox .NET Library
Multi_Example.vb

Visual Basic example using the Strobe, Multiplexer, DigitalInput and CameraTrigger devices

1 
2 
3 'A small example demonstrate the use of the strobe unit in combination with
4 'the multiplexer/digital inputs and the camera trigger.
5 'this code works for the VisionBox AGE-X Type 8, 9, 10 and 12
6 '
7 'The strobe unit is triggered with the digital input 4,
8 'and copies the input and the resulting strobe pulse to the camera trigger outputs.
9 '
10 'DigIn4 > Mux0 > Strobe0 > Mux1 > CamTrig1
11 ' Mux0 > > CamTrig0
12 
13 
14 Public Class Multi_Example
15 
16  Public Shared Sub Multiplexer()
17  Console.Clear()
18  'acquire a new factory
19  Dim pVIBSystem As VIB_NET.VIBSystem = New VIB_NET.VIBSystem()
20 
21  If pVIBSystem IsNot Nothing Then
22  Try
23  ' open devices (trigger generator, multiplexer, digital output, 2x camera trigger and strobe
24  Dim pTriggerGenerator As VIB_NET.TriggerGenerator = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.TRIGGER_GENERATOR, 0), VIB_NET.TriggerGenerator)
25  Dim pDigitalOutput As VIB_NET.DigitalOutput = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.DIGITAL_OUTPUT, 0), VIB_NET.DigitalOutput)
26  Dim pCameraTrigger As VIB_NET.CameraTrigger = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.CAMERA_TRIGGER, 0), VIB_NET.CameraTrigger)
27  Dim pStrobe As VIB_NET.Strobe = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.STROBE, 0), VIB_NET.Strobe)
28  Dim pMultiplexer As VIB_NET.Multiplexer = Nothing
29  Dim pService As VIB_NET.Service = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.SERVICE, 0), VIB_NET.Service)
30  Try
31  If ((pTriggerGenerator IsNot Nothing) And (pDigitalOutput IsNot Nothing) And (pCameraTrigger IsNot Nothing) And (pStrobe IsNot Nothing) And (pService IsNot Nothing)) Then
32 
33 
34 
35 
36  'strobe (hardware trigger by edge, puls time 1ms with 1A)
37  Dim minOffTime_us As Int32
38  Dim res As VIB_NET.Strobe.eSTROBE_MODE
39  pStrobe.Init(True)
40  minOffTime_us = pStrobe.SetLimits(0, 24, 0, 1 * 1000, 0, 1000)
41  pStrobe.OnTime = 1 * 1000
42  pStrobe.Validate = False
43  pStrobe.Current = 1000
44 
45  ' you have to set the TriggerMode to hardware before you can configure the TriggerSource and TriggerSourceInvert
46  pStrobe.TriggerMode = VIB_NET.Strobe.eSTROBE_MODE.HARDWARE_EDGE
47  res = pStrobe.TriggerMode
48  pStrobe.TriggerSourceInvert = False
49 
50  ' Decide if it is a AGEX Type 7 - 12
51  If (pService.SerialNumber.Substring(8, 1) = "1") Then ' for AGE-X Type 7-12
52  '>configure
53  'multiplexer
54  pMultiplexer = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.MULTIPLEXER, 0), VIB_NET.Multiplexer)
55  ' Get number of outputs of the multiplexer
56  Console.WriteLine(vbNewLine + "Number Of Multiplexer Outputs: " + pMultiplexer.NumberOfOutputs.ToString())
57  pMultiplexer.ConnectOutput(0, VIB_NET.Multiplexer.eMUX_SOURCE.DIG_IN4) ' DigIn4 > Line0
58  pMultiplexer.ConnectOutput(1, VIB_NET.Multiplexer.eMUX_SOURCE.STROBE_0) ' StrobeOut0 > Line1 Test STROBE_0
59 
60  'camera trigger as push/pull
61  pCameraTrigger.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.MUX_OUT0, False, True, True, False) ' Line0 > CamTrig
62 
63  Dim pCameraTrigger1 As VIB_NET.CameraTrigger = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.CAMERA_TRIGGER, 1), VIB_NET.CameraTrigger)
64  pCameraTrigger1.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.MUX_OUT1, False, True, True, False) ' Line1 > CamTrig1
65 
66  pStrobe.TriggerSource = VIB_NET.Strobe.eSTROBE_SOURCE.MUX_OUT0 ' Line0 > Strobe
67 
68  ' DigIn4 > Line0 > CamTrig
69  ' > Strobe
70  ' StrobeOut0 > Line1 > CamTrig1
71 
72  If (pCameraTrigger1 IsNot Nothing) Then
73  pVIBSystem.CloseDevice(pCameraTrigger1)
74  pCameraTrigger1 = Nothing
75  End If
76  If (pMultiplexer IsNot Nothing) Then
77  pVIBSystem.CloseDevice(pMultiplexer)
78  pMultiplexer = Nothing
79  End If
80  Else ' for AGEX Type 1-6
81  '>configure
82  'TriggerGenerator StrobeOut0 is connected to TrigIn6
83  pTriggerGenerator.ConfigureSet("TrigOut0_Mux=TrigIn6") ' StrobeOut0 > TrigOut0
84 
85  'camera trigger as push/pull
86  pCameraTrigger.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.DIG_IN4, False, True, True, False) ' DigIn4 > CamTrig
87  pCameraTrigger.Set(1, VIB_NET.CameraTrigger.eTRG_SOURCE.TRIGGEN_OUT0, False, True, True, False) ' TrigOut0 > CamTrig1
88 
89  pStrobe.TriggerSource = VIB_NET.Strobe.eSTROBE_SOURCE.DIG_IN0 + 4 ' DigIn4 > Strobe
90 
91  ' DigIn4 > CamTrig
92  ' > Strobe
93  ' StrobeOut0 > TrigOut0 > CamTrig1
94  End If
95 
96 
97  pDigitalOutput.Output = 16
98  System.Threading.Thread.Sleep(1000)
99  Console.WriteLine(vbNewLine + "Press enter to proceed...")
100  System.Console.ReadLine()
101  pDigitalOutput.Output = 0
102 
103 
104  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''/
105  '/ Using the trigger generator to control the camera trigger with the digital input 2
106  '/ you need to connect digital output 2 with digital input 2
107  '/DigIn0 > Mux3 > CounterA CounterA > TrigIntern0 > TrigOut0_Mux > Mux1 > pCameraTrigger channel 0
108  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''/
109 
110  ' Reset Digital Output
111  pDigitalOutput.SetBit(0, False)
112  pDigitalOutput.SetBit(1, False)
113 
114  ' Read trigger generator version
115  Console.WriteLine(vbNewLine + "Trigger Generator Version: " + pTriggerGenerator.ConfigureGet("Version").ToString())
116 
117  ' Configure trigger generator A to count on both edges of the input signal(TrigIn3 and TrigIn4) up to 10
118  pTriggerGenerator.ConfigureSet("CounterA=10,TrigIn3_Both CounterA_OFF=0 CounterA_ON=3 CounterA_Reset=Auto") 'TrigIn3(Mux3) > CounterA
119  pTriggerGenerator.ConfigureSet("CounterA_Start=On")
120 
121  ' Connect trigger generator
122  ' Gen A
123  pTriggerGenerator.ConfigureSet("TrigOut0_Mux=TrigIntern0 MuxIntern0=CounterA") ' CounterA > TrigIntern0 > TrigOut0_Mux
124 
125  ' Decide if it is a AGEX Type 1-6 or 7 - 12
126  If (pService.SerialNumber.Substring(8, 1) = "1") Then ' for AGE-X Type 7-12
127  pMultiplexer = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.MULTIPLEXER, 0), VIB_NET.Multiplexer)
128  ' Connect multiplexer output 3 with digital input 0
129  pMultiplexer.ConnectOutput(3, VIB_NET.Multiplexer.eMUX_SOURCE.DIG_IN0) ' DigIn0 > Mux3
130  ' Connect trigger generator output 0 to multiplexer output 1
131  pMultiplexer.ConnectOutput(1, VIB_NET.Multiplexer.eMUX_SOURCE.TRIGGEN_OUT0) ' TrigOut0_Mux > Mux1
132  'Connect camera 0 channel 0 to multiplexer output 1
133  pCameraTrigger.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.MUX_OUT1, False, True, False, False) ' Mux1 > pCameraTrigger channel 0
134  If (pMultiplexer IsNot Nothing) Then
135  pVIBSystem.CloseDevice(pMultiplexer)
136  pMultiplexer = Nothing
137  End If
138  Else ' for AGEX Type 1-6
139  'Connect camera channel 0 to trigger generator output 0
140  pCameraTrigger.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.TRIGGEN_OUT0, False, True, False, False) ' TrigOut0_Mux > pCameraTrigger channel 0
141  End If
142 
143  ' Reset CounterA
144  pTriggerGenerator.ConfigureGet("CounterA,Reset")
145 
146  Console.WriteLine(vbNewLine + vbNewLine + "Trigger Generator:" + vbNewLine + "" + vbNewLine + "0." + vbNewLine + "Input State: " + pTriggerGenerator.ConfigureGet("TrigIn").ToString()) ' 0
147  Console.WriteLine(vbNewLine + "Counter A State: " + pTriggerGenerator.ConfigureGet("CounterA").ToString()) ' 0
148  pDigitalOutput.SetBit(0, True)
149  System.Threading.Thread.Sleep(100)
150  ' Read trigger generator states
151  Console.WriteLine(vbNewLine + vbNewLine + "1." + vbNewLine + "Input State: " + pTriggerGenerator.ConfigureGet("TrigIn").ToString()) ' 8(Mux3 active)
152  Console.WriteLine(vbNewLine + "Counter A State: " + pTriggerGenerator.ConfigureGet("CounterA").ToString()) ' 1
153  pDigitalOutput.SetBit(0, False)
154  System.Threading.Thread.Sleep(100)
155  Console.WriteLine(vbNewLine + vbNewLine + "2." + vbNewLine + "Input State: " + pTriggerGenerator.ConfigureGet("TrigIn").ToString()) ' 0
156  Console.WriteLine(vbNewLine + "Counter A State: " + pTriggerGenerator.ConfigureGet("CounterA").ToString()) ' 2
157  pDigitalOutput.SetBit(0, True)
158  System.Threading.Thread.Sleep(100)
159  ' Read trigger generator states
160  Console.WriteLine(vbNewLine + vbNewLine + "3." + vbNewLine + "Input State: " + pTriggerGenerator.ConfigureGet("TrigIn").ToString()) ' 10(Mux1 und Mux3 active)
161  Console.WriteLine(vbNewLine + "Counter A State: " + pTriggerGenerator.ConfigureGet("CounterA").ToString()) ' 3
162  pDigitalOutput.SetBit(0, False)
163  System.Threading.Thread.Sleep(100)
164  Console.WriteLine(vbNewLine + vbNewLine + "4." + vbNewLine + "Input State: " + pTriggerGenerator.ConfigureGet("TrigIn").ToString()) ' 2(Mux1 active)
165  Console.WriteLine(vbNewLine + "Counter A State: " + pTriggerGenerator.ConfigureGet("CounterA").ToString()) ' 4
166  End If
167 
168 
169  ' Decide if it is a AGEX Type 1-6 or 7 - 12
170  If (pService.SerialNumber.Substring(8, 1) = "1") Then
171  ' Switch off the multiplexer outputs 0...3
172  pMultiplexer = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.MULTIPLEXER, 0), VIB_NET.Multiplexer)
173  pMultiplexer.ConnectOutput(0, VIB_NET.Multiplexer.eMUX_SOURCE.OFF)
174  pMultiplexer.ConnectOutput(1, VIB_NET.Multiplexer.eMUX_SOURCE.OFF)
175  pMultiplexer.ConnectOutput(2, VIB_NET.Multiplexer.eMUX_SOURCE.OFF)
176  pMultiplexer.ConnectOutput(3, VIB_NET.Multiplexer.eMUX_SOURCE.OFF)
177  pMultiplexer.ConnectOutput(4, VIB_NET.Multiplexer.eMUX_SOURCE.OFF)
178 
179  ' Turn off camera triggger 0 and 1
180  pCameraTrigger.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.OFF, False, True, False, False)
181 
182  Dim pCameraTrigger1 As VIB_NET.CameraTrigger = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.CAMERA_TRIGGER, 1), VIB_NET.CameraTrigger)
183  pCameraTrigger1.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.OFF, False, True, False, False)
184 
185  If (pCameraTrigger1 IsNot Nothing) Then
186  pVIBSystem.CloseDevice(pCameraTrigger1)
187  pCameraTrigger1 = Nothing
188  End If
189  If (pMultiplexer IsNot Nothing) Then
190  pVIBSystem.CloseDevice(pMultiplexer)
191  pMultiplexer = Nothing
192  End If
193  Else
194  ' Turn off camera triggger 0 and 1
195  pCameraTrigger.Set(0, VIB_NET.CameraTrigger.eTRG_SOURCE.OFF, False, True, False, False)
196  pCameraTrigger.Set(1, VIB_NET.CameraTrigger.eTRG_SOURCE.OFF, False, True, False, False)
197  End If
198 
199  ' Turn Counter off
200  pTriggerGenerator.ConfigureSet("CounterA_Start=Off")
201 
202  ' Reset digital outputs
203  pDigitalOutput.Output = 0
204 
205  Catch e As System.Exception
206  Console.WriteLine(e.Message)
207  Finally
208  ' Close the devices
209  If (pStrobe IsNot Nothing) Then
210  pVIBSystem.CloseDevice(pService)
211  pService = Nothing
212  End If
213  If (pStrobe IsNot Nothing) Then
214  pVIBSystem.CloseDevice(pStrobe)
215  pStrobe = Nothing
216  End If
217  If (pCameraTrigger IsNot Nothing) Then
218  pVIBSystem.CloseDevice(pCameraTrigger)
219  pCameraTrigger = Nothing
220  End If
221  If (pDigitalOutput IsNot Nothing) Then
222  pVIBSystem.CloseDevice(pDigitalOutput)
223  pDigitalOutput = Nothing
224  End If
225  If (pTriggerGenerator IsNot Nothing) Then
226  pVIBSystem.CloseDevice(pTriggerGenerator)
227  pTriggerGenerator = Nothing
228  End If
229  End Try
230 
231  Catch e As System.Exception
232  Console.WriteLine(e.Message)
233  Finally
234  'release factory
235  If (pVIBSystem IsNot Nothing) Then
236  pVIBSystem = Nothing
237  End If
238  End Try
239  End If
240  Console.WriteLine(vbNewLine + "Press enter to proceed...")
241  System.Console.ReadLine()
242  End Sub
243 End Class