Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting nidaq in C to nidaqmx in C#

Hello,

I'm new at NiDaqmx and I've to convert NiDaq Code. I've read the documentation but I've not understand what mode I should use to do a buffered Period Measurement with a TimeBase of 20 Mhz. The hole Code that has to be converted is here:

 

GPCTR_Control(Pcicard.Address, ND_COUNTER_1, ND_RESET);
GPCTR_Control(Pcicard.Address, ND_COUNTER_3, ND_RESET);

 

GPCTR_Set_Application(Pcicard.Address,ND_COUNTER_1, ND_BUFFERED_PERIOD_MSR);
GPCTR_Set_Application(Pcicard.Address,ND_COUNTER_3, ND_BUFFERED_PERIOD_MSR);
                   
GPCTR_Change_Parameter (Pcicard.Address, ND_COUNTER_1,ND_BUFFER_MODE, ND_SINGLE);
GPCTR_Change_Parameter (Pcicard.Address, ND_COUNTER_3,ND_BUFFER_MODE, ND_SINGLE);
               
Set_DAQ_Device_Info (Pcicard.Address, ND_DATA_XFER_MODE_GPCTR1,ND_UP_TO_1_DMA_CHANNEL);
Set_DAQ_Device_Info (Pcicard.Address, ND_DATA_XFER_MODE_GPCTR3,ND_UP_TO_1_DMA_CHANNEL);
                   
GPCTR_Change_Parameter (Pcicard.Address,ND_COUNTER_1 , ND_SOURCE, ND_INTERNAL_20_MHZ);
GPCTR_Change_Parameter (Pcicard.Address,ND_COUNTER_3 , ND_SOURCE, ND_INTERNAL_20_MHZ);
                   
GPCTR_Change_Parameter(Pcicard.Address, ND_COUNTER_1, ND_INITIAL_COUNT, 0);

GPCTR_Change_Parameter(Pcicard.Address, ND_COUNTER_3, ND_INITIAL_COUNT, 0);
                   
Select_Signal(Pcicard.Address, ND_START_TRIGGER, ND_PFI_32,ND_LOW_TO_HIGH);
                   
GPCTR_Change_Parameter (Pcicard.Address,ND_COUNTER_1 , ND_GATE, ND_PFI_34);
GPCTR_Change_Parameter (Pcicard.Address,ND_COUNTER_3 , ND_GATE, ND_PFI_26);
                   
GPCTR_Change_Parameter (Pcicard.Address, ND_COUNTER_1,ND_START_TRIGGER, ND_ENABLED);
GPCTR_Change_Parameter (Pcicard.Address, ND_COUNTER_3,ND_START_TRIGGER, ND_ENABLED);

 

Thanks

André

Message Edited by koins on 03-05-2009 05:43 AM
0 Kudos
Message 1 of 4
(4,396 Views)

Hello André,

 

what kind of hardware are you using? Am I right, that you like to convert from NI-DAQ in C to NI-DAQmx in C#?

 

Best regards

Marian Vorderer
0 Kudos
Message 2 of 4
(4,358 Views)

Hello MarianMO,

I'm using a PCI6602. Yes you are right I like to convert from NI-DAQ in C to NI-DAQmx in C#.

I've tried in meantime to construct a asynchronous callback for both Counters but I always get a timeout for more than about 2000 samples for samples1 or samples2.

Here`s the code I wrote:

 

private static AsyncCallback asyncCBefwp;

public static long[] Tags1 = new long[samples1];

public static long[] Tags2 = new long[samples2];

public static Task myTask3 = new Task();

public static Task myTask4 = new Task();
public static CounterReader Counter3 = new CounterReader(myTask3.Stream);

public static CounterReader Counter4 = new CounterReader(myTask4.Stream);

public static AsyncCallback asyncCBefwp = new AsyncCallback(CounterEFWPCallback);


Counter3.SynchronizeCallbacks = true;
myTask3.CIChannels.CreatePeriodChannel("Dev1/ctr1", "", 0.000001, 0.1, CIPeriodStartingEdge.Rising, CIPeriodMeasurementMethod.LowFrequencyOneCounter, 1, 4, CIPeriodUnits.Ticks);

Counter3.BeginReadMultiSampleDouble(samples1, asyncCBefwp, myTask3);

myTask3.Triggers.ArmStartTrigger.ConfigureDigitalEdgeTrigger("PFI32", DigitalEdgeArmStartTriggerEdge.Rising);

 

Counter4.SynchronizeCallbacks = true;
myTask4.CIChannels.CreatePeriodChannel("Dev1/ctr3", "", 0.000001, 0.1, CIPeriodStartingEdge.Rising, CIPeriodMeasurementMethod.LowFrequencyOneCounter, 1, 4, CIPeriodUnits.Ticks);                    

 Counter4.BeginReadMultiSampleDouble(samples2, asyncCBefwp, myTask4);

myTask4.Triggers.ArmStartTrigger.ConfigureDigitalEdgeTrigger("PFI32", DigitalEdgeArmStartTriggerEdge.Rising);

 

private static void CounterEFWPCallback(IAsyncResult ar)
        {
           
            if (ar.AsyncState == myTask3)
            {
                int i = 0;
                foreach (double data in Counter3.EndReadMultiSampleDouble(ar)) //here ocurrence the timeout

                {
                    Tags1[i] = (long)data;
                    i++;
                }
                MessageBox.Show("Tags1 ready");
            }
            if (ar.AsyncState == myTask4)
            {
                int i = 0;
                foreach (double data in Counter4.EndReadMultiSampleDouble(ar)) //and here ocurrence the timeout
                {
                    Tags2[i] = (long)data;
                    i++;
                }
                MessageBox.Show("Tags2 ready");
            }

        }

 

Can you help me? I'm expecially interesteste about the Callback functions for multiple tasks. I've searched in your examples but the are no examples with more than one Counter.

Thanks

André

 

Message Edited by koins on 03-12-2009 03:50 AM
Message Edited by koins on 03-12-2009 03:51 AM
0 Kudos
Message 3 of 4
(4,346 Views)

Sorry for answering that late, but I was out of office. I just want to hear back to you: what is the actual status of your project? Where did you get the original C-Code?

 

Please can you describe in words, what you are planning to do?

 

Best regards

Marian Vorderer
0 Kudos
Message 4 of 4
(4,224 Views)