VisionBox .NET Library
IOScheduler_Example.vb

Visual Basic example for using the IOScheduler device

1 Public Class IOScheduler_Example
2  ' Connect all outputs with the inputs Out 0 to In 0 and so on
3  Public Shared Sub IOScheduler()
4  Console.Clear()
5  'acquire a new factory
6  Dim pVIBSystem As VIB_NET.VIBSystem = New VIB_NET.VIBSystem()
7 
8  If pVIBSystem IsNot Nothing Then
9  Try
10 
11  'The signal flow inside the FPGA
12  ' TrigGen0[0] > Mux0[0] > IOScheduler0[0] > Mux0[1] > DigOut0[1]
13  ' IOScheduler0[1] > Mux0[2] > DigOut0[2]
14  '
15  ' > IOScheduler1[0] > Mux0[3] > DigOut0[3]
16  '
17  ' > DigOut0[0]
18  '
19  ' Open digital input device 0
20  '>Open Units(Multiplexer, 2x IOScheduler, DigOut, TriggerGen)
21  'the multiplexer
22  Dim pMultiplexer As VIB_NET.Multiplexer = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.MULTIPLEXER, 0), VIB_NET.Multiplexer)
23  'first both IOScheduler
24  Dim pIOScheduler_0 As VIB_NET.IOScheduler = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.IOSCHEDULER, 0), VIB_NET.IOScheduler)
25  Dim pIOScheduler_1 As VIB_NET.IOScheduler = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.IOSCHEDULER, 1), VIB_NET.IOScheduler)
26  'DigitalOutput
27  Dim pDigitalOutput As VIB_NET.DigitalOutput = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.DIGITAL_OUTPUT, 0), VIB_NET.DigitalOutput)
28  'TriggerGenerator
29  Dim pTriggerGenerator As VIB_NET.TriggerGenerator = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.TRIGGER_GENERATOR, 0), VIB_NET.TriggerGenerator)
30 
31  If ((pTriggerGenerator IsNot Nothing) _
32  And (pDigitalOutput IsNot Nothing) _
33  And (pMultiplexer IsNot Nothing) _
34  And (pIOScheduler_0 IsNot Nothing) _
35  And (pIOScheduler_1 IsNot Nothing)) Then
36 
37  Try
38  '>Configure
39  'TriggerGenerator to 100Hz
40  pTriggerGenerator.ConfigureSet("GenA_tLow=5ms GenA_tHigh=5ms")
41  pTriggerGenerator.ConfigureSet("TrigOut0_Mux=GenA")
42 
43  'Multiplexer
44  pMultiplexer.ConnectOutput(0, VIB_NET.Multiplexer.eMUX_SOURCE.OFF) 'disconnect the 100Hz from the schedulers
45  pMultiplexer.ConnectOutput(1, VIB_NET.Multiplexer.eMUX_SOURCE.IOSCHEDULER_0_OUT0)
46  pMultiplexer.ConnectOutput(2, VIB_NET.Multiplexer.eMUX_SOURCE.IOSCHEDULER_0_OUT1)
47  pMultiplexer.ConnectOutput(3, VIB_NET.Multiplexer.eMUX_SOURCE.IOSCHEDULER_1_OUT0)
48 
49  'MuxOutpus as source for the DigOut
50  pDigitalOutput.SetSource(0, VIB_NET.DigitalOutput.eOUT_SOURCE.MUX_OUT0, False) 'noInvert
51  pDigitalOutput.SetSource(1, VIB_NET.DigitalOutput.eOUT_SOURCE.MUX_OUT1, False) 'noInvert
52  pDigitalOutput.SetSource(2, VIB_NET.DigitalOutput.eOUT_SOURCE.MUX_OUT2, False) 'noInvert
53  pDigitalOutput.SetSource(3, VIB_NET.DigitalOutput.eOUT_SOURCE.MUX_OUT3, False) 'noInvert
54 
55  'Prepare the IOScheduler
56  pIOScheduler_0.Reset() 'sets the default values
57  pIOScheduler_1.Reset()
58  pIOScheduler_1.SetOutputPulsTiming(8 * 1000, 2 * 1000) ' delay us, on us
59 
60  '> start the units
61  pIOScheduler_0.Start()
62  pIOScheduler_1.Start()
63 
64  'add some values
65  Dim StartDelay As UInteger = 4
66  Dim StepMul As UInteger = 2
67  For i As UInteger = 0 To 4 Step 1
68  'we want to toggle the output
69  If (1 = (i Mod 2)) Then
70  pIOScheduler_0.PushValue(StartDelay + StepMul * i, 2)
71  Else
72  pIOScheduler_0.PushValue(StartDelay + StepMul * i, 1)
73  End If
74  'we want only edges so we set always 1
75  pIOScheduler_1.PushValue(StartDelay + StepMul * i, 1)
76  Next
77  '> connect the 100Hz to the IOScheduler
78  pMultiplexer.ConnectOutput(0, VIB_NET.Multiplexer.eMUX_SOURCE.TRIGGEN_OUT0)
79 
80  '> wait until all elements are outputted
81  Dim iFillLevel As UInteger = 0
82  Do
83  iFillLevel = pIOScheduler_0.BufferFillLevel
84  Loop While iFillLevel > 0
85 
86  'disconnect the 100Hz from the schedulers
87  pMultiplexer.ConnectOutput(0, VIB_NET.Multiplexer.eMUX_SOURCE.OFF)
88 
89  Catch e As System.Exception
90  Console.WriteLine(e.Message)
91  Finally
92  ' Close the digital output
93  If (pDigitalOutput IsNot Nothing) Then
94  pVIBSystem.CloseDevice(pDigitalOutput)
95  pDigitalOutput = Nothing
96  End If
97  ' Close the multiplexer
98  If (pMultiplexer IsNot Nothing) Then
99  pVIBSystem.CloseDevice(pMultiplexer)
100  pMultiplexer = Nothing
101  End If
102  ' Close the IOScheduler_0
103  If (pIOScheduler_0 IsNot Nothing) Then
104  pVIBSystem.CloseDevice(pIOScheduler_0)
105  pIOScheduler_0 = Nothing
106  End If
107  ' Close the IOScheduler_1
108  If (pIOScheduler_1 IsNot Nothing) Then
109  pVIBSystem.CloseDevice(pIOScheduler_1)
110  pIOScheduler_1 = Nothing
111  End If
112  ' Close the trigger generator
113  If (pTriggerGenerator IsNot Nothing) Then
114  pVIBSystem.CloseDevice(pTriggerGenerator)
115  pTriggerGenerator = Nothing
116  End If
117  End Try
118  End If
119  Catch e As System.Exception
120  Console.WriteLine(e.Message)
121  Finally
122  'release factory
123  pVIBSystem = Nothing
124  End Try
125  End If
126  Console.WriteLine(vbNewLine + "Press enter to proceed...")
127  System.Console.ReadLine()
128  End Sub
129 End Class