VisionBox .NET Library
DigInOut_Example.cs

C# example for using the DigitalInput and DigitalOutput device

1 
2 // Connect each physical output signal OUT[0...7] with the corresponding input signal IN[0...7] on the VisionBox
3 using System;
4 using VIB_NET;
5 
6 namespace CSharp
7 {
8  class DigInOut_Example
9  {
10  public static void DigitalInputOutput()
11  {
12  Console.Clear();
13 
14  try
15  {
16  // Create device objects with the 'using' statement so they get closed automatically:
17  using (VIB_NET.DigitalInput digitalInput = new VIB_NET.DigitalInput())
18  using (VIB_NET.DigitalOutput digitalOutput = new VIB_NET.DigitalOutput())
19  {
20  // Open DigitalInput device 0
21  digitalInput.Open(0);
22 
23  // Open DigitalOutput device 0
24  digitalOutput.Open(0);
25 
26  // Set the debounce time: edge high to low = 200 ns and edge low to high = 200 ns
27  digitalInput.ConfigureDebounceTime(200, 200);
28  // Get the number of digital inputs and outputs
29  UInt32 NumberOfInputs = digitalInput.NumberOfInputs;
30  UInt32 NumberOfOutputs = digitalOutput.NumberOfOutputs;
31  Console.WriteLine( "\nNumber of digital outputs: " + NumberOfOutputs.ToString() +
32  "\nNumber of digital inputs: " + NumberOfInputs.ToString());
33 
34  // Set state of digital outputs syncroniously
35  digitalOutput.Output = 0xff;
36  System.Threading.Thread.Sleep(10);
37  // Get state of digital inputs syncroniously
38  Console.WriteLine("\nInput state: 0x" + digitalInput.Input.ToString("x"));
39  // Set state of one digital output
40  digitalOutput.SetBit(0, false);
41  System.Threading.Thread.Sleep(10);
42  Console.WriteLine("\nInput state Bit 0: " + (digitalInput.GetBit(0) ? "ON" : "OFF"));
43 
44  // Turn all digital outputs off
45  digitalOutput.Output = 0;
46  System.Threading.Thread.Sleep(10);
47 
48  // Configure event filter for input 0 and 1 (2^0 + 2^1 = 3)
49  digitalInput.SensitivityMask = 0x3;
50 
51  // Turn on output 0
52  digitalOutput.SetBit(0, true);
53 
54  try
55  {
56  // Start waiting for input event with a timeout of 1 s
57  UInt32 inputEvent = digitalInput.WaitForInputEvent(1000);
58  Console.WriteLine("Input Event, new Input State: 0x" + inputEvent.ToString("x"));
59  }
60  catch (System.Exception)
61  {
62  Console.WriteLine("WaitForInputEvent: TimeOut");
63  }
64 
65  // Abort waiting for input event
66  digitalInput.AbortWaitingForInputEvent();
67 
68  } // Close all devices
69  }
70  catch (System.Exception e)
71  {
72  Console.WriteLine(e.Message);
73  }
74 
75  Console.WriteLine("\nPress enter to proceed...");
76  System.Console.ReadLine();
77  }
78  }
79 }
VIB_NET::DigitalInput
This class represents a group of optically coupled input signals.
Definition: VIB_NET.h:1139
VIB_NET
All relevant classes and functions are residing in this namespace.
Definition: CameraLinkIn.cpp:6
VIB_NET::DigitalOutput
This class controls the optically isolated output signals.
Definition: VIB_NET.h:1074