03-05-2009 05:41 AM - edited 03-05-2009 05:43 AM
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é
03-10-2009 11:47 AM
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
03-12-2009 03:48 AM - edited 03-12-2009 03:51 AM
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é
03-30-2009 01:31 PM
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