Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Upgrading from Legacy code to C# - need help configuring counter input and output channels

I am in the process of upgrading some legacy Visual C++ 6 code that was programmed against the NI PCI-6034e card.  The card that was identified by NI as an equivalent replacment is the NI PCIe-6321 card.  There is upstream hardware that is not being replaced or reconfigured, so this card was identified as providing the same functionality and I/O as the old NI card.

 

I am trying to figure out how to program the onboard counter input/output using the latest NIDAQ .NET 4.5 libraries (C#) to achieve the same functionality as the legacy code.

 

Here is the legacy code for the Counter 0 configuration:

 

// Reset the counter for programming.
GPCTR_Control(m_iDevice, ND_COUNTER_0, ND_RESET), "Reset GPCTR0" );
// Set General purpose counter #0 to use pulse-train count. GPCTR_Set_Application(m_iDevice, ND_COUNTER_0, ND_PULSE_TRAIN_GNR);
// Set General purpose counter #0 to count using the PFI6 pin. GPCTR_Change_Parameter(m_iDevice, ND_COUNTER_0, ND_SOURCE, ND_PFI_6);
// Make sure the counting is on low to high transitions of the PFI6 signal pin. GPCTR_Change_Parameter(m_iDevice, ND_COUNTER_0, ND_SOURCE_POLARITY, ND_LOW_TO_HIGH);
// Generate first pulse after m_GPCTR0_Value pulses. GPCTR_Change_Parameter(m_iDevice, ND_COUNTER_0, ND_COUNT_1, m_GPCTR0_Value);
// Generate second pulse after next m_GPCTR0_Value pulses. GPCTR_Change_Parameter(m_iDevice, ND_COUNTER_0, ND_COUNT_2, m_GPCTR0_Value);

// When count reaches zero, pulse the counter output signal pin. GPCTR_Change_Parameter(m_iDevice, ND_COUNTER_0, ND_OUTPUT_MODE, ND_TOGGLE);
// General purpose counter #0 will count down when DIO6 is low. GPCTR_Change_Parameter(m_iDevice, ND_COUNTER_0, ND_UP_DOWN, ND_HARDWARE);
// Load the settings into the counter and arm it. GPCTR_Control(m_iDevice, ND_COUNTER_0, ND_PROGRAM);  

 

My analysis of this code is that in current NIDAQmx programming, I have to create both a CIChannel task, and a COChannel task.

 

I have figured out that the CIChannel should be:

 - Count Edges Counter

 - CountEdgesTerminal = PFI6

 - CountEdgesActiveEdge = low to high

 

What I am struggling with is how to program the coordination between the CIChannel and the COChannel. From the documentation of the legacy NIDAQ library,  I think that the logic of the legacy code is that for every "m_GPCTR0_Value" pulses of the PFI6 signal being counted by the counter input, the counter output sends out either the high value or the low value of its output signal.  The CIChannel needs to count down from "m_GPCTR0_Value" to 0, then signal the COChannel to output the correct state, then start counting down again from "m_GPCTR0_Value" to 0. I believe this is a continuous operation that starts when the signal on Digital Input #6 goes "Low", and stops when it goes back "High".

 

 I have looked at most of the NIDAQmx C# samples, but have not seen anything that shows this level of complexity.  I have looked through the documentation, but it hasn't help me figure this out.

 

I would appreciate any help that can be offered. 

 

Thanks,

Elaine Visner

 

 

 

 

0 Kudos
Message 1 of 2
(4,668 Views)