11-13-2013 10:06 AM
Hello,
Currently I have one C++ program reading AI signal from NI USB-6259 BNC and it works well. I have a different C++ program that also needs to read the same signal from the same DAQ board. I am wondering can I run these two programs simultaneouly since both need to access the same signal simultaneously? Would there be any conflict? Does anybody have similar experience? Otherwise I will just try. Thank you very much!
11-13-2013 10:24 AM
I'm not sure how helpful this will be, but it has been my experience that most NI hardware drivers only allow for one simultaneous session with a given instrument which is identified by a session id (ussually equivalent to an integer). If the API in question requires a ViSession variable or equivalent as an argument to most functions then you are probably in the same boat. What I have done to combat this, as I had a similar situation to yours, was to share the session variable between my separate processes allowing all processes to interact with the device.
That's just my .02, hope it helps.
11-13-2013 02:59 PM
Thanks a lot for replying! I tried with running both programs simultaneouly, only one project can access the data from the device. Can you specify more on how you shared the session variables between the two separate C++ projects? Seems like what you did can be a solution for mine.
11-13-2013 03:09 PM
Sure. As mentioned before, for the drivers I had the same problem with, each function that took a measurement / reading / did some configuration to a particular device requires a session identifier as a parameter. For example, the NI Frequency Generator that I was working with has a function for configuring a standard waveform, the C API call is:
ViStatus niFgen_ConfigureStandardWaveform (ViSession vi, ViConstString channelName, ViInt32 waveform, ViReal64 amplitude, ViReal64 dcOffset, ViReal64 frequency, ViReal64 startPhase);
Notice the first argument (vi). While the type is ViSession, it is easily cast to an integer and back. Thus to share operation of the device between two processes I placed the integer equivalent of vi in a memory space accessible to both processes (you can used shared memory or another memory sharing paradigm). Then when either process needs to access the device, it uses the value from shared memory as the argument vi. The ViSession variable sort of works like a file descriptor as far as the driver is concerned, thus as long as you use the same one for both processes the driver will not care which process is actually requesting the data. Be careful of data races using this method of sharing your device, though it should not be a problem as long as you are only reading values from the device.