Impact Acquire SDK .NET
DigitalIOs.cs

The DigitalIOs program shows the digital I/O information of the used Balluff device. The user can also interactively change the state of the digital output line and some other properties during the sample execution.

Purpose of the program
The DigitalIOs program shows the digital I/O information of the used Balluff device.
Program location
The source file DigitalIOs.cs can be found under:
%INSTALLDIR%\apps\CSharp\DigitalIOs\
Note
If you have installed the package without example applications, this file will not be available. On Windows® the sample application can be installed or removed from the target system at any time by simply restarting the installation package.
DigitalIOs example:
  1. Opens a Balluff device.
  2. You can change the state of the digital I/O's.
Console Output
[0]: BF000306 (mvBlueFOX-202C, Family: mvBlueFOX, interface layout: DeviceSpecific)

Please enter the number in front of the listed device followed by [ENTER] to open it: 0
Using device number 0.
This device has
  2 digital input(s)
   [0]: DigitialInput0(current state: 0)
   [1]: DigitialInput1(current state: 0)

All input registers can be queried with a single function call: Calling 'readInputRegister' returned 0x0
From the LSB to the MSB a '1' in this result indicates, that this input is currently connected to a signal
that is interpreted as a logical '1'. E.g. 0x13 indicates that inputs 0, 1 and 4 are currently in 'high' state.
  4 digital output(s)
   [0]: DigitalOutput0(current state: 0, manually switchable)
   [1]: DigitalOutput1(current state: 0, manually switchable)
   [2]: DigitalOutput2(current state: 0, manually switchable)
   [3]: DigitalOutput3(current state: 0, manually switchable)

Enter the number of a digital output followed by [ENTER] to modify its state or 'c' followed by [ENTER] to continue.

>>> 0
Please enter the number in front of the function that shall be called followed by [ENTER]:
  [0]: set
  [1]: reset
  [2]: flip

>>> 0
   [0]: DigitalOutput0(current state: 1, manually switchable)
   [1]: DigitalOutput1(current state: 0, manually switchable)
   [2]: DigitalOutput2(current state: 0, manually switchable)
   [3]: DigitalOutput3(current state: 0, manually switchable)

Enter the number of a digital output followed by [ENTER] to modify its state or 'c' followed by [ENTER] to continue.

>>>
How it works
In the main, a functions is called, where the user can select the device (getDeviceFromUserInput()). Afterwards the sample opens the device (pDev->open()) and will check, if the device is a member of the mvBlueFOX family, a member of the mvBlueCOGUAR family or a frame grabber.

According to the device, the digital I/O information will be displayed. In detail this will be:

Apart from this output of the current state and description of the different input and output signal lines and related properties the user can also interactively change the state of the digital output line and some other properties during the sample execution. How this can be achieved can be seen in the source code of the sample.

Source code
using mv.impact.acquire.examples.helper;
using System;
using System.Collections.ObjectModel;
namespace mv.impact.acquire.examples
{
class DigitalIOs
{
static void modifySyncOutput(SyncOutput p)
{
FeatureAccess.displayPropertyData(p.frequency_Hz);
FeatureAccess.modifyPropertyValue(p.frequency_Hz, "", "");
FeatureAccess.displayPropertyData(p.lowPart_pc);
FeatureAccess.modifyPropertyValue(p.lowPart_pc, "", "");
}
static void displayCommonIOFeatures(IOSubSystem ioss)
{
// display available features
Console.WriteLine("This device has");
int inputCount = ioss.inputCount;
Console.WriteLine(" {0} digital input(s)", inputCount);
// display the state and name of each individual digital input
for (int i = 0; i < inputCount; i++)
{
Console.WriteLine(" [{0}]: {1} (current state: {2})", i, ioss.input(i).description, ioss.input(i).get());
}
Console.WriteLine();
if (inputCount > 0)
{
// read the state of all digital inputs in a single function call
Console.WriteLine("All input registers can be queried with a single function call: Calling 'readInputRegister' returned ");
Console.WriteLine("{0:X}", ioss.readInputRegister());
Console.WriteLine();
Console.WriteLine("From the LSB to the MSB a '1' in this result indicates, that this input is currently connected to a signal");
Console.WriteLine("that is interpreted as a logical '1'. E.g. 0x13 indicates that inputs 0, 1 and 4 are currently in 'high' state.");
}
int outputCount = ioss.outputCount;
Console.WriteLine(" {0} digital input(s)", outputCount);
if (outputCount > 0)
{
int readOnlyAccessMask = 0;
bool boRun = true;
while (boRun)
{
// display the state and name of each individual digital output
for (int j = 0; j < outputCount; j++)
{
DigitalOutput pOutput = ioss.output(j);
Console.WriteLine(" [{0}]: {1}(current state: {2}, {3}manually switchable)", j, pOutput.description, pOutput.get(), (pOutput.isWriteable ? "" : "NOT "));
if (!pOutput.isWriteable)
{
readOnlyAccessMask |= 1 << j;
}
}
Console.WriteLine();
Console.WriteLine("Enter the number of a digital output followed by [ENTER] to modify its state or 'c' followed by [ENTER] to continue.");
string cmd = Console.ReadLine();
if (cmd == "c")
{
boRun = false;
continue;
}
int index = 0;
try
{
index = Convert.ToInt32(cmd);
}
catch
{
Console.WriteLine("Invalid input:");
continue;
}
if (index >= outputCount)
{
Console.WriteLine("Invalid selection");
continue;
}
DigitalOutput Output = ioss.output(index);
if (!Output.isWriteable)
{
Console.WriteLine("{0} is not manually switchable.", Output.description);
continue;
}
Console.WriteLine("Please enter the number in front of the function that shall be called followed by [ENTER]:");
Console.WriteLine(" [0]: set");
Console.WriteLine(" [1]: reset");
Console.WriteLine(" [2]: flip");
int newMode = Convert.ToInt32(Console.ReadLine());
switch (newMode)
{
case 0:
Output.set();
break;
case 1:
Output.reset();
break;
case 2:
Output.flip();
break;
default:
Console.WriteLine("Invalid selection.");
break;
}
}
// read the state of all digital outputs in a single function call
Console.WriteLine("All output registers can be queried with a single function call.");
Console.WriteLine("From the LSB to the MSB a '1' in this result indicates, that this output is currently switched to 'high' or 'active' state");
Console.WriteLine("E.g. 0x22 indicates that outputs 1 and 5 (zero-based) are currently in 'high' state.");
uint fullOutputMask = 0;
if (outputCount > 0)
{
fullOutputMask = (uint)Math.Pow(2, outputCount) - 1;
}
boRun = true;
while (boRun)
{
Console.WriteLine("Calling 'readOutputRegister' returned ");
Console.WriteLine("0x{0}", ioss.readOutputRegister().ToString("X2"));
Console.WriteLine();
Console.WriteLine("Please enter 'y' followed by [ENTER] to modify all digital outputs with a single function");
Console.WriteLine("call or anything else followed by [ENTER] to continue.");
if (Console.ReadLine() != "y")
{
boRun = false;
continue;
}
Console.WriteLine("Please enter the bitmask in hex that contains the new values for the digital outputs followed by [ENTER]: ");
uint value = UInt32.Parse(Console.ReadLine(), System.Globalization.NumberStyles.HexNumber);
if ((value & ~fullOutputMask) != 0)
{
value &= fullOutputMask;
Console.WriteLine("WARNING: More bits than outputs specified. Bitmask truncated to ");
Console.WriteLine("0x{0}", value.ToString("X4"));
Console.WriteLine();
}
Console.WriteLine("Please enter the bitmask in hex that contains '1's for outputs that shall be affected by this operation followed by [ENTER]: ");
uint mask = UInt32.Parse(Console.ReadLine(), System.Globalization.NumberStyles.HexNumber);
if ((readOnlyAccessMask & mask) != 0)
{
Console.WriteLine("WARNING: At least one selected output is not manually switchable: Mask: ");
Console.WriteLine("0x{0}", mask.ToString("X4"));
Console.WriteLine(", read-only access mask: ");
Console.WriteLine("0x{0}", readOnlyAccessMask.ToString("X4"));
Console.WriteLine();
Console.WriteLine("No digital outputs have been modified.");
continue;
}
ioss.writeOutputRegister(value, mask);
}
}
Console.WriteLine("This device also has");
Console.WriteLine(" {0} hardware real-time controller(s).", ioss.RTCtrProgramCount);
if (ioss.RTCtrProgramCount > 0)
{
Console.WriteLine("How to program the HRTC (Hardware RealTime Controller) is not part of this sample, but the manual will contain a separate chapter on this topic.");
}
Console.WriteLine(" {0} pulse start configuration(s).", ioss.pulseStartConfigurationCount);
}
static void mvGenICamIOAccess(Device pDev)
{
try
{
//Count the number of Digital IOs
int IOCount = dioc.lineSelector.dictSize;
bool boRun = true;
while (boRun)
{
Console.WriteLine();
Console.WriteLine(" This device has {0} DigitalIOs", IOCount);
Console.WriteLine(" ------------------------------------------");
// display information about each individual DigitalIO
ReadOnlyCollection<long> validLineSelectorValues = dioc.lineSelector.listOfValidValues;
foreach (long value in validLineSelectorValues)
{
dioc.lineSelector.write(value);
Console.WriteLine(" IO {0}: \t Type: {1} \t Current state: {2}", value, dioc.lineMode.readS(), Convert.ToBoolean(dioc.lineStatus.read()) ? "ON" : "OFF");
}
Console.WriteLine(" ------------------------------------------");
Console.WriteLine();
Console.WriteLine("Please enter a valid line number:");
Console.WriteLine("- if it is an output its value will be inverted");
Console.WriteLine("- if it is an input its value will be polled continuously for 10 seconds");
Console.Write("- or press 'c' to continue:");
ConsoleKeyInfo userInput = Console.ReadKey();
Console.WriteLine();
// get user input
if (userInput.Key == ConsoleKey.C)
{
boRun = false;
continue;
}
//check if key is a digit
else if (Char.IsDigit(userInput.KeyChar))
{
int userInputDigit = Convert.ToInt32((userInput.KeyChar.ToString()));
// check if selected digit is a valid IO number
if (userInputDigit < IOCount)
{
//Define the IO we are interested in
dioc.lineSelector.write(userInputDigit);
//check whether selected IO is an Output or an Input
if (dioc.lineMode.readS() == "Output")
{
if (Convert.ToBoolean(dioc.lineInverter.read()))
{
dioc.lineInverter.write(TBoolean.bFalse);
}
else
{
}
}
else if (dioc.lineMode.readS() == "Input")
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(" ------------------------------------------");
Console.WriteLine(" Polling Input '{0}'", dioc.lineSelector.readS());
Console.WriteLine(" ------------------------------------------");
Console.WriteLine();
for (int i = 0; i < 100; i++)
{
Console.Write("\r Value:{0} \t Remaining Time:{1:F1}", Convert.ToBoolean(dioc.lineStatus.read()) ? "ON" : "OFF", 10.0 - ((float)i / 10));
System.Threading.Thread.Sleep(100);
}
Console.WriteLine();
Console.WriteLine();
}
else
{
Console.WriteLine("IO {0} is a '{1}'!", userInputDigit, dioc.lineMode.readS());
}
}
else
{
Console.WriteLine();
Console.WriteLine(" Invalid IO Number! ");
Console.WriteLine();
}
}
else
{
Console.WriteLine();
Console.WriteLine(" Invalid Keyboard Input! ");
Console.WriteLine();
}
}
}
{
Console.WriteLine();
Console.WriteLine("An error occurred while playing around with the digital I/Os of device " + pDev.serial +
"(error code: " + e.Message + ").");
Console.WriteLine();
}
}
static void mvBlueFOXIOAccess(Device pDev)
{
displayCommonIOFeatures(ioss);
if (ioss.digitalInputThreshold.isValid)
{
Console.WriteLine("This device also supports the '{0}' property.", ioss.digitalInputThreshold.name);
FeatureAccess.displayPropertyData(ioss.digitalInputThreshold);
}
Console.WriteLine("To use a digital output in 'expose active' mode, the property '{0}' can be used.", cs.flashMode.name);
Console.WriteLine("If a delay between switching the output and starting the frame exposure is needed, this can be achieved by ");
Console.WriteLine("writing to the property '{0}'.", cs.flashToExposeDelay_us.name);
}
static void Main(string[] args)
{
mv.impact.acquire.LibraryPath.init(); // this will add the folders containing unmanaged libraries to the PATH variable.
Device pDev = DeviceAccess.getDeviceFromUserInput();
if (pDev == null)
{
Console.WriteLine("Unable to continue! Press any key to end the program.");
Console.Read();
Environment.Exit(1);
}
if (pDev.interfaceLayout.isValid && pDev.interfaceLayout.read() == TDeviceInterfaceLayout.dilGenICam)
{
mvGenICamIOAccess(pDev);
}
else if (pDev.family.readS() == "mvBlueFOX")
{
mvBlueFOXIOAccess(pDev);
}
else
{
Console.WriteLine("Device {0} ({1}) is not supported by this sample", pDev.serial, pDev.product);
Console.WriteLine("Press [ENTER] to end the application");
Console.Read();
Environment.Exit(1);
}
Console.WriteLine();
Console.WriteLine("Press [ENTER] to end the application");
Console.Read();
}
}
}
mvBlueFOX related camera settings (Device specific interface layout only).
Definition CameraSettingsBlueFOX.cs:15
readonly EnumPropertyI< TCameraFlashMode > flashMode
An enumerated integer property defining the behaviour of the flash output of the camera (if available...
Definition CameraSettingsBlueFOX.cs:174
readonly PropertyI flashToExposeDelay_us
An integer property defining the delay in us between the start of the flash signal output and the beg...
Definition CameraSettingsBlueFOX.cs:160
This class and its functions represent an actual device detected by this interface in the current sys...
Definition Device.cs:91
readonly EnumPropertyI< TDeviceInterfaceLayout > interfaceLayout
An enumerated integer property which can be used to define which interface layout shall be used when ...
Definition Device.cs:603
readonly PropertyS product
A string property (read-only) containing the product name of this device.
Definition Device.cs:501
readonly PropertyS family
A string property (read-only) containing the family name of this device.
Definition Device.cs:490
readonly PropertyS serial
A string property (read-only) containing the serial number of this device.
Definition Device.cs:515
String description
Returns a description for this digital output.
Definition DigitalIO.cs:74
override bool get()
Returns the current state of this input pin.
Definition DigitalIO.cs:192
A class to represent a digital output pin(Device specific interface layout only).
Definition DigitalIO.cs:91
override bool get()
Returns the current state of this output pin.
Definition DigitalIO.cs:120
bool isWriteable
Checks if the caller has write/modify access to this digital output.
Definition DigitalIO.cs:144
void set()
Sets the output pin to 'logic 1'.
Definition DigitalIO.cs:122
void reset()
Sets the output pin to 'logic 0'.
Definition DigitalIO.cs:124
bool flip()
Inverts the current state of the digital output and returns the previous state.
Definition DigitalIO.cs:107
ReadOnlyCollection< T > listOfValidValues
Returns a list of valid values for this property.
Definition EnumPropertyI64.cs:602
EnumPropertyI64< T > write(T value)
Writes one value to the property.
Definition EnumPropertyI64.cs:432
EnumPropertyI< T > write(T value)
Writes one value to the property.
Definition EnumPropertyI.cs:449
T read()
Reads a value from a property.
Definition EnumPropertyI.cs:342
Category that contains the digital input and output control features.
Definition mvIMPACT_acquire_GenICam.autogen.cs:3628
readonly mv.impact.acquire.PropertyI64 lineMode
An enumerated integer property. Controls if the physical Line is used to Input or Output a signal.
Definition mvIMPACT_acquire_GenICam.autogen.cs:3730
readonly mv.impact.acquire.PropertyI64 lineSelector
An enumerated integer property. Selects the physical line (or pin) of the external device connector o...
Definition mvIMPACT_acquire_GenICam.autogen.cs:3718
readonly mv.impact.acquire.PropertyIBoolean lineInverter
A boolean property. Controls the inversion of the signal of the selected input or output Line.
Definition mvIMPACT_acquire_GenICam.autogen.cs:3735
readonly mv.impact.acquire.PropertyIBoolean lineStatus
A boolean property. Returns the current status of the selected input or output Line.
Definition mvIMPACT_acquire_GenICam.autogen.cs:3740
A class to handle the digital inputs and outputs for mvBlueFOX USB cameras (Device specific interface...
Definition IOSubSystemBlueFOX.cs:51
readonly EnumPropertyI< TBlueFOXDigitalInputThreshold > digitalInputThreshold
An enumerated integer property defining the threshold for the digital inputs in Volt.
Definition IOSubSystemBlueFOX.cs:211
A base class to handle digital inputs and outputs (Device specific interface layout only).
Definition IOSubSystem.cs:19
DigitalInput input(int nr)
Returns a const pointer to a mv.impact.acquire.DigitalInput object.
Definition IOSubSystem.cs:131
void writeOutputRegister(uint value, uint mask)
Alters the state of the digital output register.
uint readOutputRegister()
Returns the current state of the digital output register.
DigitalOutput output(int nr)
Returns a pointer to a mv.impact.acquire.DigitalOutput object.
Definition IOSubSystem.cs:144
uint readInputRegister()
Returns the current state of the digital input register.
int inputCount
Returns the number of mv.impact.acquire.DigitalInput s available for the mv.impact....
Definition IOSubSystem.cs:233
int outputCount
Returns the number of digital outputs available for the mv.impact.acquire.Device associated with this...
Definition IOSubSystem.cs:235
int pulseStartConfigurationCount
Returns the number of mv.impact.acquire.PulseStartConfiguration objects available for the mv....
Definition IOSubSystem.cs:239
int RTCtrProgramCount
Returns the number of mv.impact.acquire.RTCtrProgram s available for the mv.impact....
Definition IOSubSystem.cs:237
An base class for exceptions generated by Impact Acquire.
Definition Exceptions.cs:9
A small helper class to administer various library search path related variables and paths.
Definition LibraryPath.cs:14
static void init()
Calling this method will add the folders containing unmanaged libraries to the systems library search...
Definition LibraryPath.cs:251
String readS()
Reads data from this property as a string.
Definition Property.cs:303
A class to represent a sync. output pin(Device specific interface layout only).
Definition SyncOutput.cs:18
readonly PropertyF lowPart_pc
A float property defining the width in percent the sync. signal stays low during one period....
Definition SyncOutput.cs:54
readonly PropertyF frequency_Hz
A float property defining the frequency(in Hertz) for the sync. signal generated by this pin.
Definition SyncOutput.cs:52
TBoolean
Defines a Boolean value type.
Definition mvDriverBaseEnums.cs:481
TDeviceInterfaceLayout
Defines valid interface layouts for the device.
Definition mvDriverBaseEnums.cs:1921
This namespace contains classes and functions belonging to the GenICam specific part of the image acq...
Definition GenTLDriverConfigurator.cs:6
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition Enumerations.cs:2
Definition Enumerations.cs:2
Definition Enumerations.cs:2