1 Public Class DigInOut_Example
2 ' Connect all outputs with the inputs Out 0 to In 0 and so on
3 Public Shared Sub DigitalInputOutput()
6 Dim pVIBSystem As VIB_NET.VIBSystem = New VIB_NET.VIBSystem()
8 If pVIBSystem IsNot Nothing Then
10 ' Open digital input device 0
11 Dim pDigitalInput As VIB_NET.DigitalInput = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.DIGITAL_INPUT, 0), VIB_NET.DigitalInput)
12 ' Open digital output device 0
13 Dim pDigitalOutput As VIB_NET.DigitalOutput = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.DIGITAL_OUTPUT, 0), VIB_NET.DigitalOutput)
15 If (pDigitalInput IsNot Nothing) And (pDigitalOutput IsNot Nothing) Then
17 ' Set the debounce time: edge high to low = 200 ns and edge low to high = 200 ns
18 pDigitalInput.ConfigureDebounceTime(200, 200)
19 ' Get the number of digital inputs and outputs
20 Dim NumberOfInputs As UInt32 = pDigitalInput.NumberOfInputs
21 Dim NumberOfOutputs As UInt32 = pDigitalOutput.NumberOfOutputs
22 Console.WriteLine(vbNewLine + "Number of digital outputs: " + NumberOfOutputs.ToString() + vbNewLine + "Number of digital inputs: " + NumberOfInputs.ToString())
24 ' Set state of digital outputs syncroniously
25 pDigitalOutput.Output = 255
26 ' Get state of digital inputs syncroniously
27 Console.WriteLine(vbNewLine + "Input state: " + pDigitalInput.Input.ToString())
28 System.Threading.Thread.Sleep(1000)
29 ' Get state of one digital input
30 Console.WriteLine(vbNewLine + "Input state Bit 0: " + pDigitalInput.GetBit(0).ToString())
31 ' Set state of one digital output
32 pDigitalOutput.SetBit(0, False)
33 Console.WriteLine(vbNewLine + "Input state Bit 0: " + pDigitalInput.GetBit(0).ToString())
35 ' Turn all digital outputs off
36 pDigitalOutput.Output = 0
38 ' Configure event filter to input 0 and 1 (2^0 + 2^1 = 3)
39 pDigitalInput.SensitivityMask = 3
41 ' Start waiting for input event with a timeout of 1 s
43 Dim bWaitForInputEvent As Boolean = False
44 If (bWaitForInputEvent) Then
45 Console.WriteLine("Input Event, new Input State: " + pDigitalInput.WaitForInputEvent(1000).ToString())
47 Catch e As System.Exception
48 Console.WriteLine("WaitForInputEvent: TimeOut")
51 ' Abort waiting for input event
52 pDigitalInput.AbortWaitingForInputEvent()
53 Catch e As System.Exception
54 Console.WriteLine(e.Message)
56 ' Close the digital output
57 If pDigitalOutput IsNot Nothing Then
58 pVIBSystem.CloseDevice(pDigitalOutput)
59 pDigitalOutput = Nothing
61 ' Close the digital input
62 If pDigitalInput IsNot Nothing Then
63 pVIBSystem.CloseDevice(pDigitalInput)
64 pDigitalInput = Nothing
68 Catch e As System.Exception
69 Console.WriteLine(e.Message)
75 Console.WriteLine(vbNewLine + "Press enter to proceed...")
76 System.Console.ReadLine()