Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone verify this 1AI/2DI Program??

Hi,
I am modifying the 'ContAcqVoltageSamples_IntClk_ToFile' to acquire 1AI/2DI at the same time. But I am not sure what more modifications are needed in the startButton_Click function and also in AnalogInCallback function (how I can save all AI and DI data in the same data variable 'data') so that I can start and record AI and DI data at the same time. I am attaching the modified code. Hope someone will help me out correcting the program. Sorry I am not having measurement studio documentation, I have written added commands using Goto Definition option while coding Smiley Indifferent.
thanks,
-Pavan
0 Kudos
Message 1 of 11
(5,223 Views)
I would like to use 'ReadMultiSamplePortByte' for digital line, but the program gives error like 'Cannot implicitly convert type 'byte[*,*]' to 'double[*,*]'' at Line851 in the above attached program. I think because the AI channel acquires double data. How can I get around this Smiley Sad

thanks,
-Pavan
0 Kudos
Message 2 of 11
(5,223 Views)
Hi,
I have updated the program, now it is executing without any error, but its not doing anything when I hit start (i.e. it is not acquiring data), maybe I am missing something for starting the acquisition. It would be great if someone can look at my code, I am attaching the whole project so that you can run it easily.

thanks,
-pavan
0 Kudos
Message 3 of 11
(5,219 Views)
Hello Pavan,

There's quite a bit going on in your program!  Are you certain that it's related to the DAQ tasks?  You might be better off making sure that the DAQ portion works before you throw in the file I/O.  A great reference for synchronizing Analog Input and Digital Input is the shipping example ContAI-Read Dig Chan.  This shipping example is installed to the ~\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Synchronization\Multi-Function directory.  Compare the ContAI-Read Dig Chan and your own code to ensure that the flow is correct.  Try to get just the DAQ portion of you code working before integrating the file I/O.

If you just can't seem to find the problem, post again and we'll be happy to help you out further.

Regards,
Micaela N
National Instruments
0 Kudos
Message 4 of 11
(5,203 Views)
Hi Micaela,
Yep, that exactly what I am doing now, using the AnsiC example.
With C example I can run the program at 10MHz and data samples/channel at 10kS/s and not more than that (as the program crashes if I go above 10kS/s). I want make sure that if I am acquiring data at 10MHz and gettin 10kS, does that mean that I am loosing reamining data ( i.e10MS - 10kS) or will it be queued in the buffer so that it will read in next iteration?? Herewith I am attaching the modified C program, can you please verify it, if you dont mind Smiley Happy?? Actually I would like to acquire data at 10MHz.

Also I would like to know the Digital input connections on BNC-2110, if I want to acquire digital input from 2 lines then all I have to do is to connect one input to PO.0 and another one to PO.1 and both of their grounds to D GND (on BNC-2110) and use Dev2/port0/line0:1in the program, is this correct?

Coming to C# program, the program is same as the example program 'ContAcqVoltageSamples_IntClk_ToFile' but I am not sure if I coded it correctly while adding digital part and if I am starting it in the right way. The functions that I am not sure and those that I modified are 'startButton_Click' and 'AnalogInCallback' only and also I am not sure if I am doing the acquisition in the right way. I am attaching c#.NET project too with what I have done till now. It would be great if you can verify and guide me in the right direction.

My system is having dual processor and 2GB of ram, so I can store all the acquired data on ram temporarily and then write it to file at the end, for now we are planning to store 10sec of data (hmm this comes after a long time after I get the acquisition right Smiley Happy).

thanks,
-Pavan
Download All
0 Kudos
Message 5 of 11
(5,203 Views)
Hi Pavan,

Let's just concentrate on getting your DAQ working and then I think you will be able to integrate it into your other program as long as nothing is wrong with the file I/O.

First, what DAQ board are you using for this program?  It sounds like you are getting confused with some of the NI-DAQmx sampling terminology, this KnowledgeBase explains the terminology for the NI-DAQmx driver.  When you are doing continuous sampling, the driver allocates a buffer - this KnowlegeBase describes how the buffer is allocated.  When samples are obtained they are place in the buffer and then when a DAQmxRead call is executed the buffer returns the number of samples specified.  Even when the samples are being returned, the DAQ card is acquiring samples.  You have to be careful to sample fast enough and retrieve enough samples for the buffer not to fill up because then samples will be overwritten and you will get an overwrite error.  To avoid buffer overwrite errors, experiment with different values for scan rate, buffer size and number of scans to read at a time. The best combination will result in little or no scan backlog. A good rule of thumb to start with is: make your buffer size 2 - 4 times as large as the number of scans to read.  You can check the backlog of your buffer using the DAQmxGetReadAvailSampPerChan property.  You mentioned you are getting an error when you try to return samples faster than 10k/channel, what is that error?

Second, you asked about the connections on the BNC-2110, yes, you only need to connect to P0.0 and P0.1 for your digital signals.  Keep in mind that both of your digital signals need to have the same ground because the digital ground is shared.  You would then read from DevX/port0/line0:1 when X is the device number found in Measurement and Automation Explorer.  

Let me know if you have further questions,
Micaela N
National Instruments
0 Kudos
Message 6 of 11
(5,185 Views)
Hi Micaela,
I managed to run the program for 1AI/2DI successfully at 10MHz and 10kS/s. BTW I am using PCI-6115 along with BNC-2110. Now I am working on 1AO/2DO to generate output of the data recorded above but at 4MHz(the max rate on PCI-6115 for AO using single analog channel). I am using the example program for analog out ' ContGen-IntClk', but what all I need to do now is, to integrate digital generation into this program. Here is the code for 1AI/2DI at 10MHz and 10kS/s and also the program for continuous 1AO with the data that is recorded earlier in 1AI/2DI configuration. It would be great if you can help me out in integrating digital output with analog output. Meanwhile I will keep working on incorporating DO into AO program.
Thanks for your reply.
-Pavan

Download All
0 Kudos
Message 7 of 11
(5,180 Views)
Hi Micaela,

I got both the programs working now. I am recording at 10MHz and outputting at 4MHz. But I have a quick question for you, using PCI-6115, is it possible to acheive an output signal frequency of 4MHz?? See here are our observations, we used a sine wave of 2 different frequencies one is at 500kHz and the other at 1MHz and read them in at 4MHz and while outputting the same data at 4MHz the first one is having 200kHz and the second one having 400kHz (which is right around 40% of the input signal). So, how can I record a signal at some rate and playback (output) at the same rate?? Is it possible on this board or anyother boards you provide??

BTW here are my final programs running at 4MHz for testing purposes.

thanks,
-Pavan
Download All
0 Kudos
Message 8 of 11
(5,163 Views)
Pavan,

I don't really understand what you are asking.  Are you using two channels for each of your sine waves or are you testing two separate sine waves?  Are you saying that if you read the 500kHz sine wave in at 4MHz and generate it at 4MHz (using only one AI and one AO channel) you recover a signal at 200kHz?  Could you clarify your question and your data a little more?

Thank you,
Micaela N
National Instruments
0 Kudos
Message 9 of 11
(5,143 Views)
Hi Micaela,
I am using 1AI channel and recording a sine wave and then later I am using 1AO for generating the recorded sine wave. For testing, I have used 4MHz for both recording and generating the sine wave. I have tested with 500kHz, 1MHz, 2MHz input signal and recorded at 4MHz and used that data to generate signal at 4MHz, but the ouput signal is having 40% of frequency compared to its original frequencies. As per your understanding this is correct - "Are you saying that if you read the 500kHz sine wave in at 4MHz and generate it at 4MHz (using only one AI and one AO channel) you recover a signal at 200kHz?"
Hope I am clear now Smiley Happy.
Thanks,
-Pavan
0 Kudos
Message 10 of 11
(5,140 Views)