CogCommCard DiscreteIOAccess Property Cognex VisionPro 9.8 SR1
Gets a discrete I/O access object.

Use the discrete I/O access object to access the discrete I/O and precision I/O features of the comm card.

This property returns null if the hardware does not support discrete I/O.

Namespace: Cognex.VisionPro.Comm
Assembly: Cognex.VisionPro.Comm (in Cognex.VisionPro.Comm.dll) Version: 75.0.0.0
Syntax

public CogDiscreteIOAccess DiscreteIOAccess { get; }

Property Value

Type: CogDiscreteIOAccess
Remarks

Precision I/O supports getting and setting the state of the Comm Card's Discrete I/O lines.

Precision I/O also supports configuration of an event system that runs on the Comm Card's real-time processor.

The precision I/O event system allows the Comm Card to receive inputs and automatically react to them without involving the host PC.

This enables accurate configuration and reporting of I/O events and avoids typical host PC latency issues.

Examples

// This code shows simple use of 
// Comm Card API. This sample: 
//  
// 1. Initializes comm card's i/o interface. 
// 2. Reads input line 0. 
// 3. Signs up for host notification when input line 0 toggles. 
// 4. Sets an output line 0 high.
[Test]
public void Example2()
{
CogCommCards commCardCollection = new CogCommCards();

Console.WriteLine("Found: {0} comm cards", commCardCollection.Count);

if (commCardCollection.Count == 0)
return;

CogCommCard card = commCardCollection[0];

Console.WriteLine("Name: {0}", card.Name);
Console.WriteLine("Serial: {0}", card.SerialNumber);

CogDiscreteIOAccess discreteIOAccess = card.DiscreteIOAccess;
if (discreteIOAccess == null)
throw new Exception("discrete IO is not supported.");

// Create the prio interface
CogPrio prio = discreteIOAccess.CreatePrecisionIO();

// Read input 0 
bool isInputLine0High = mPrio.ReadState()[CogPrioBankConstants.InputBank0, 0];
Console.WriteLine("Input line 0 is " + (isInputLine0High ? "high" : "low"));

// Create an event that occurs when Input 0 changes
prio.Events.Add(
new CogPrioEvent() {
Name = "InputChanged_0",
CausesLine = new CogPrioEventCauseLineCollection() {
new CogPrioEventCauseLine() {
LineBank = CogPrioBankConstants.InputBank0,
LineNumber = 0,
LineTransition = CogPrioLineTransitionConstants.Any }}});

// Sign up for host notification when on the event
prio.Events["InputChanged_0"].HostNotification +=
new CogPrioEventHandler(InputChanged_0_HostNotification);

// Always ensure the events collection is valid. 
if(!prio.Valid)
{ 
  Console.WrtieLine(prio.ValidationErrorMsg[0]);
}

// Set output 0 high
prio.SetOutput(CogPrioBankConstants.OutputBank0,         // i/o bank 
0,                                        // line number
CogPrioOutputLineValueConstants.SetHigh); // line value to set
}

void InputChanged_0_HostNotification(object sender, CogPrioEventArgs e)
{
Console.WriteLine("rcvd host notification for InputChanged_0 event");
}
See Also