PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

How Do I know if I am talking to PCI_MIO-16E-4 from C++ ?

1) I am migrating from traditional to Nidaqmx 8.5 using VC++ 2005. In traditional devices, I used to initialize it by loading up the nidaq32.dll and using its DLL functions (GetProcessAddress(NI_DB_CONFIG)..etc.. With NIDAQmx 8.5, Is there anythinge quivalent to that in order to get connected or initalized? 
 
2) Besides including Nidaqmx.h and nidaqmx.lib and loading up "nicaiu.dll", Is there anything else I need ?
0 Kudos
Message 1 of 38
(5,209 Views)
Hello NewBe,

The best answer to both of your questions would be to examine an example program which demonstrates an operation similar to your application. The directory that the Visual C++ examples are installed to depends on the version of the driver, the version of Visual Studio, the version of Measurement Studio, and the operating system that are installed.

The Visual C++ example directory locations on Windows XP/2000 are shown in the attached image "Windows XP_2000 C++ Example Locations.jpg." The image is taken from the Where To Find Examples topic in the NI Measurement Studio Help.



The Visual C++ example directory locations on Windows Vista are shown in the attached image "Windows Vista C++ Example Locations.jpg." The image is taken from the Where To Find Examples topic in the NI Measurement Studio Help.


Message Edited by Matt A on 08-02-2007 07:33 PM


Matt Anderson

Hardware Services Marketing Manager
National Instruments
Message 2 of 38
(5,174 Views)
Matt A.,
1) Thank you for the reply. I do have Vista ultimate, NIDAQmx 8.5, and Measurement Studio 4.2.1 (Relatively recent I believe), I looked under \users\public\...\DOT NET2\.., what I found was C# examples, not Visual C++. I did find C++ examples written for VC++ 6.0 under different path. Do yo think these examples are OK for my environment? Some of the examples seem to work alright. 
 
2) Using the C++ examples, I wasn't able to read any data for a" Measure Cont-voltage using External clock example". I feed the channel with voltage from a transdeucer source, It would spit out the number of samples its reading, but when I have it print out Data[i], seems to give me "0" for the answer. Do you have an idea why its not displaying zero for data array ?
 
Thanks
0 Kudos
Message 3 of 38
(5,165 Views)
Hello NewBe,

1. The VC++ 6.0 examples should work in your environment. However, if you do have any problems you could reference the ANSI C examples which are installed to the NI-DAQ\Examples\DAQmx ANSI C directory.

2. The example you listed would require an external clock source to acquire samples. It is important to be sure that you have configured the clock correctly in the software and that you have connected your clock source to the correct physical connection. What are you using for your external source?

Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 4 of 38
(5,144 Views)

Hello Matt A.,

Thanks again for the help.

With the same setup I have, which is using a Transdeucer voltage source as channel1, I can read voltage and test the counter using Edge triggered setup (PFI4 and PFI7) in Measurmeant and Automation tool. When I use the example of measuring voltage cont clk in C++, with the clock using PFI4 or PFI7 as I switched between both, the one difference I noticed is that with PFI7, I can read samples at higher speed. When I use a printf satament to read data array, it displays 0 for answers. I also played with sample rates, but it didn't seem to do anything.

Thanks

0 Kudos
Message 5 of 38
(5,142 Views)
Hello NewBe,

There are a couple things to note regarding this application. First, when using an external sample clock the actual rate of acquisition is determined by the clock. You specify a rate so that the driver can determine the dt parameter for the waveform, but it does not affect the rate of acquisition at all. For more details, you can see this KnowledgeBase.

Given this information, I wonder if you could clarify what you mean when you say that you are able to read samples at a higher speed when you use PFI7. I have attached an image from the E Series User Manual, which shows the connections for external timing sources on E Series devices, like the PCI-MIO-16E-4. The top, right section shows how any of the PFI lines 0-9 can be used as a source for the ai/SampleClock. Do you mean that you are able to specify a higher rate for the acquisition when you select PFI7 for the sample clock source? Are you actually generating a faster clock when you use PFI7? If your data appears as 0s, how are you able to determine that you are read at a faster rate?



Could you post the section of your code where you read the data from the device (probably using a DAQmx Read function) and where you use printf to display your data? This may help us determine why your display shows all 0s.

Message Edited by Matt A on 08-06-2007 04:15 PM


Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 6 of 38
(5,128 Views)
Hello Matt,
Thank you for the clarification as I am still reading up on NIDAQmx. The end goal for me is to be able to read data from within my application(VC++) for 8 channels from our hardware board using NIDAQmx. When I get to that point, I will give you a call as I am setting up a support plan with NI. The code was written with LEGACY, and it doesn't look to be too easy to move over to NIDAQmx. For the time being, I figured I'll start with a simple channel and read the data by using C++ examples that came with driver.  I used (Acq-Ext-clk) and VC_ContAcq_ExtClk_DigStart) examples, with in the read statment,

DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,-1,10.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL));

if( read>0 ) printf("Acquired %d samples\n",read);

for(int i=0;i<1000;i++) { printf(data[i]);

Yes, I do get higher rate of samples acquisition when I select PF7 as opposed to pf4 for clock source. 

Another question I have, to accomplish the above goal I mentioned of reading 8 channels, DO I have to create a task with 8 channels, or Could I do it without specifically creating a task?

Thanks

0 Kudos
Message 7 of 38
(5,124 Views)
Hello NewBe,

I believe the problem you are seeing is a result of the way you have implemented your printf() statement. If you notice, data[] is defined as an array of float64 in the example program. However, your call to printf() does not specify a data type. I am surprised your program even compiled, as printf() should take a const char* as the input parameter and not a float64[]. Try using the following syntax to display your values:

    if( read>0 )
        printf("Acquired %d samples\n",read);
   
    for(i=0;i<read;i++) {
        printf("%f \n",data[i]);
    }

Where i has been defined as an int earlier in the program. The %f in the printf() statement indicates that the value is a float. By adding that code, I was able to display the values I acquired in the command prompt. For more help with programming text based applications in NI-DAQmx, I would suggest you reference this tutorial.

In regards to your second question, you will have to add each additional channel that you want to monitor to your task. However, if the parameters are the same you do not have to make multiple calls to the DAQmxCreateAIVoltageChan(). You can simply use this syntax to add multiple channels to the task at the same time. So, for example, if you wanted to sample channels 0 through 7 at the same rate with the same range, you could simply modify the DAQmxCreateAIVoltageChan() function call as follows:

DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0:7","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));

If you make this change your data[] array will contain consecutive sets of points for each channel. That is, if you have configured DAQmxCfgSampClkTiming() to acquire 100 samples per channel, your data array will contain 100 samples for ai0, then 100 samples for ai1, then 100 samples for ai2 and so on. This is because the DAQmxReadAnalogF64() in the example is configured to use DAQmx_Val_GroupByChannel as the fillMode. If you change the fillMode parameter to DAQmx_Val_GroupByScanNumber the values will be interleaved in your data[] array. That is, the first sample for ai1 through ai7 will be the first 8 values, then the second sample for ai0 through ai7, then the third and so on. You will also need to adjust your printf() for loop accordingly, as my code is only set to display the first read samples where read is the number of samples acquired per channel.

Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 8 of 38
(5,106 Views)
Dear Matt,
 Indeed, it was as simple as changing %d to %f. Now, since I successfully tested couple of examples, I have a general idea on how Nidaqmx functions work. However, my question to you, and the part that I am still struggling to understand is, How do I assign my channel names within my application. In the example above, I created a voltage channel to read from the transducer, and assigned it to Dev0\ai1, but in my case, I want to read channels from our hardware like Pressure, RPM,HP, and others  which I have them in a channel array. I don't understand the concept of how to assign my channels to physical channels since I am not creating a voltage channel anymore? Which function can do that? Or, is there a way around specifying physical channels?
 
I can use CreateCICountEdgesChan(dev\cntr0....) function for counter channels,, but I am not sure how to create and assign channel names to my channels within the application?
 
I appreciate your help
 
 
0 Kudos
Message 9 of 38
(5,104 Views)
Hello NewBe,

The DAQmxCreateAIVoltageChan function is the function that is used to add and name channels in your task. As described in the "NI-DAQmx C Reference Help" (Start>>All Programs>>National Instruments>>NI-DAQ), the purpose of this function is:


"Purpose

Creates channel(s) to measure voltage and adds the channel(s) to the task you specify with taskHandle. If your measurement requires the use of internal excitation or you need the voltage to be scaled by excitation, call DAQmxCreateAIVoltageChanWithExcit."


The help file also provides the function definition as follows:


"int32 DAQmxCreateAIVoltageChan (TaskHandle taskHandle, const char physicalChannel[], const char nameToAssignToChannel[], int32 terminalConfig, float64 minVal, float64 maxVal, int32 units, const char customScaleName[]);"


The nameToAssignToChannel[] parameter is used to name the physical channels in the task and is described as follows:


"The name(s) to assign to the created virtual channel(s). If you do not specify a name, NI-DAQmx uses the physical channel name as the virtual channel name. If you specify your own names for nameToAssignToChannel, you must use the names when you refer to these channels in other NI-DAQmx functions."


If you want to assign a different name to each physical channel, you will have to use multiple calls to the DAQmxCreateAIVoltageChan() function and add a new physical channel with the new name to the same task.

You can add different types of channels to the same task, so long as they are all performing the same operation (analog input, analog output, digital input, digital output, counter input or counter output). There is a similar function to the DAQmxCreateAIVoltageChan() for the different types of functions you may want to add. There is a DAQmxCreateAIStrainGaugeChan() function for strain measurements, there is a DAQmxCreateAICurrentChan() function for current measurement; there is a DAQmxCreateAIRTDChan() function for RTD temperature measurements and so on. You can use these functions to add channels to the same AI task, however you will have to specify a physical channel for each function.

If you notice, the DAQmxCreateCICountEdgesChan() function also has a nameToAssignToChannel[] parameter that you can use to assign channel names to your counter task. For more details about channels and tasks, I would recommend that you review this KnowledgeBase. Again, I would also recommend that you examine the "NI-DAQmx C Reference Help" for more specifics; all these functions are described in detail in this help file.


Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 10 of 38
(5,093 Views)