Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI 5112 Simultaneous Sampling using C++

I am using the "gettingstarted" example for C++ 6.0 that came with the NI 5112 board to collect data for college project. We are trying to figure out few things.

1, How can we get data from both channels Simultaneously
using the C++ example? At present we are only able to get data from one channel at a time but we need to get data from both channels at the same time.



2, Once we get the data, how can we export it to other programs, such as MATLAB? We can see the measured data on the C++ example but there is no way to copy it.



3, How can we time stamp the incoming data? at this time, this is not that important but it may become.




Should we use a different C++ example? where can we get different examples?



Any help would really be very helpful and we will be very greatful. We spend so much time to get the PCB machine working and we don't have much time left now so please help.

Thanks
0 Kudos
Message 1 of 17
(5,135 Views)
Hi Finomad,

I personally like the Simulated Acquisition example to do what you want to do (C:\Program Files\IVI\Drivers\niScope\Examples\c\SimulatedAcquisition) -- the important thing is that you need to tell your device NOT to simulate by using the function
   handleErr (niScope_init (resourceName, NISCOPE_VAL_FALSE, NISCOPE_VAL_FALSE, &vi));

instead of    handleErr (niScope_InitWithOptions (resourceName, NISCOPE_VAL_FALSE, NISCOPE_VAL_FALSE,
                                       optionString, &vi));

(don't use InitWithOptions, get rid of that optionString).

This gives a more robust setup, and then as your channels, you can put in "0,1" as the channel string.

The good thing about this example is that it uses the niScope_ActualNumWfms function, which helps you delcare good waveforms and NI-SCOPE parses that channel list for you.


You will then need to output the data to arrays or text files on your own.  Make it easy for something like MATLAB to read.  Check out the PlotWfms function in this example -- you'll see some loops that will help you dig through the data and you can output them however you like.

The timestamps example in the c folder should help you with the timestamping.  wfminfo has all of the information you need.  You can also check out the NI-SCOPE help file and search for timestamps and see all of this information there if the code is confusing.  NI High-Speed Digitizers Help >> Fundamentals >> Time Stamping is a useful overview.

Modify the Simluated Acquisition to do what you need and I think you'll be on your way.

Thanks,
mike

 
0 Kudos
Message 2 of 17
(5,131 Views)
Thanks for the help Berto. But we don't have this "SimulatedAcquisition" example. Do you know where we can get it? Also is it fully customazible?

Do you know of any other examples that we can use to get data from both channels at the same time? Basically, we need an example that can start and stop getting the data from both channels at the same time.



Also, we need to output the data to a text file or some other document



Thanks

0 Kudos
Message 3 of 17
(5,113 Views)
Interesting.  Mine is at C:\Program Files\IVI\Drivers\niScope\Examples\c  (or can be found by going to Start >> Programs >> National Instruments >> NI-SCOPE >> Examples >> c)

If not, I would recommend getting the latest version from here

http://digital.ni.com/softlib.nsf/webcategories/85256410006C055586256BE600709528?opendocument&node=132060_US

When you install it, make sure you add the examples.  Otherwise I can zip it up and send it out to you.

Thanks!


0 Kudos
Message 4 of 17
(5,111 Views)

Hello Berto,

I think we have an older driver. It says "C:\VXIpnp\WinNT\NISCOPE\Examples\"  then it has some examples for msvc, visualbasic, VisualC.

We are on a school computer and we do not have the permission to install any drivers or programs (we tried to install). So can you please zip up the examples and send it to us?.  Can you also zip the header files that we will be needing because these header files are located at some other directory. This is the problem we have with every example we try because some of the header files are missing.

 

 Thanks

0 Kudos
Message 5 of 17
(5,100 Views)
Post Edited:  Hmm, my text got deleted when uploading.

I highly recommend you try to get IT to update you to the latest driver that works with your OS.  However, I've zipped up all of them for you.  The simulated example should at least show you the flow and how to use multiple channel datatypes -- but again, you'll need to change some of this code.

mike

Message Edited by Berto on 03-08-2006 03:07 PM

0 Kudos
Message 6 of 17
(5,090 Views)
Hello Berto,

We finally got the NI-scope driver upgraded to the new version. We are now able to run the "SimulatedAcquisition". However, we are having major problems with trying to get the output into a text file.

As you suggested, we tried to modify the PlotWfms function. We only had a basic course in C++ and it seems to be beyond our capabilities to modify the code. Do you have any suggestions as to how we should modify the code? How should we modify the loop so we can get a text output? Thanks for the help. We really appreciate it.

Thanks
0 Kudos
Message 7 of 17
(5,026 Views)
Hi finomad,

waveformPtr is the array of data that has the actual data in it.  asciiPlot is the function that is then called to look at the data.  You can see it if you look at asciiplot.c -- note that the first parameter, ViReal64 *waveform is the data that comes in.  So if you have a loop that goes from 0 to the total size of your waveform, you can look at each sample:

   min = max = waveform[0];
   for (i=1; i<size; i++)
   {
      if (waveform[i] > max) max = waveform[i];
      if (waveform[i] < min) min = waveform[i];
   }

So this bit of code looks at each point and then determines the min and max with that logic.

If you want to print out each point, possibly you can add more code:

   min = max = waveform[0];
       cout << "Datapoint 0 is " << waveform[0] << endl;
   for (i=1; i<size; i++)
   {
      if (waveform[i] > max) max = waveform[i];
      if (waveform[i] < min) min = waveform[i];
       cout << "Datapoint " << i << " is " << waveform[i] << endl;
   }

Or something to that extent...  You may need to #include iostream.h to use the cout function, I'm just adding that code off of the top of my head.

Either way, this is just one way to index through your array of data and output stuff, and can be done right after the fetch -- it doesn't have to be in this AsciiPlot function.

And of course, make sure you turn off Simulation like I said before, to make sure you're talking to your device.  Simulating is a fine way to test the code at first though.

If you'd like more work with arrays and strings and outputting, you may need to Google it, there's TONS of C++ references out there.

Thanks,
mike
0 Kudos
Message 8 of 17
(5,020 Views)

Berto,

We are trying to see if we can use the "save to file" example. This example gives a text file output, which is what we need. However, it only gets data from one channel at a time. But, we can modify the code so that it will get data from both channels simultaneously. There is not much help file on how we can modify the code. Have you had any experience with this particular example? If so, do you have any suggestions on how we can modify the code?

We are also working on Simulated Acquisition. We will see if we can get the data output to a text file or something.

 

Thanks

0 Kudos
Message 9 of 17
(5,006 Views)
Dear Berto,

You have been very helpful and please continue to help us with this. Our project is about analyzing the data and not about acquiring the data. However, we have to acquire the data before we can analyze. We have spent lot of time trying to acquire the data. We have spent two months trying to acquire the data and now we only have one month left to analyze, which is not going to be easy. So please help us little more. We really hope that we are not taking up too much off your time but we really need your help.


So if waveformPtr is the array of data with data in it, Can we not just use a printf function to print that out to a text file? If this is possible, how will the output for two channels look like? will be alternating data channel 0 and channel 1?

Quote
"So this bit of code looks at each point and then determines the min and max with that logic."

But why do we need to look at the min and the max? Each sample will have one data? so how will it have max and min?

Yes, we really really need to print out each point. So will that code you gave us for printing out the data work? If it does, how will the output look like for two channels? will it be two different columns? or will it be one Column with alternating data for the two channels?

The iostream.h is a standard header file, right? We can just get that from the C++ library?

Berto, if you can help us, we would be very grateful. If you would like to e-mail us, you can me us at fialexander@yahoo.com

I am going to do a lot of search to see how can i print out arrays. Hopefully, we will find what we are looking for.

Thanks
0 Kudos
Message 10 of 17
(4,999 Views)