07-21-2015 01:28 PM
I'm trying to use an NI USB-6002 device as a shutter controller. It should receive a trigger signal input and in response send one or more pulses along its digital output lines. Based on the example in this link, I wrote up this code in C++:
char startTrigPort[256] = "/Dev1/port2/line0"; // source trigger port char taskName[256] = "Trigger test task"; int numSamples = 1000; int samplesPerSec = 100; TaskHandle handle; error = DAQmxCreateTask(taskName, &handle); if (error) { return logError(error, "CreateTask"); } char outChan[256] = "Dev1/port0/line0"; error = DAQmxCreateDOChan(handle, outChan, "", DAQmx_Val_ChanForAllLines); if (error) { return logError(error, "CreateDOChan"); } error = DAQmxCfgSampClkTiming(handle, "OnboardClock", samplesPerSec, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numSamples); if (error) { return logError(error, "CfgSampClkTiming"); } error = DAQmxCfgDigEdgeStartTrig(handle, startTrigPort, DAQmx_Val_Rising); if (error) { return logError(error, "CfgDigEdgeStartTrig"); } // 10000 matches number in CfgSampClkTiming // Wait 10s for writing to complete (maybe should vary based on length of // data being written?) uInt32 *sequence = new uInt32[numSamples]; for (int i = 0; i < numSamples; ++i) { sequence[i] = (i / 50) % 2; } int32 numWritten = 0; error = DAQmxWriteDigitalU32(handle, numSamples, false, 10, DAQmx_Val_GroupByScanNumber, sequence, &numWritten, NULL); if (error) { return logError(error, "WriteDigitalU32"); } if (numWritten != numSamples) { LogMessage(("Didn't write all of sequence; wrote only " + boost::lexical_cast<string>(numWritten)).c_str()); return 1; }
(the logError function just calls DAQmxGetErrorString, logs the result, and then returns the original error code)
As suggested in the title, I'm getting an error -200077 when I call DAQmxCfgSampClkTiming, with the error message being "Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property."
I don't know what's going wrong here. According to the documentation, the parameters to that function seem correct, and our device really ought to be capable of 100 samples per second for 10 seconds, so I doubt the sample rate or number of samples is an issue. Any advice?
07-21-2015 03:24 PM
07-21-2015 03:24 PM - edited 07-21-2015 03:25 PM
Okay, so it turns out the USB-6002 doesn't have an onboard clock. Fortunately conceptually I shouldn't need it; advance trigger mode should be fine. Assuming I understand it correctly: when an external trigger comes in, the card should move to the next set of outputs in the sequence I've pre-loaded onto it.
Unfortunately, I still get the same -200077 error when I try to use "Dev1/PFI0" as the clock terminal instead of "OnboardClock". Dev1/PFI0 is listed as a valid terminal by DAQmxGetDevTerminals, so I would expect it to be a valid clock for DAQmxCfgDigEdgeStartTrig. Any ideas what's going wrong?
EDIT: heh, simultaneous with the response from Dennis_Knutson.
07-21-2015 04:47 PM - edited 07-21-2015 04:47 PM
Further digging turned up the WriteDigChan_ExtClk example program, which also doesn't work, with the same error, but lead me to the DAQmxGetExtendedErrorInfo() method, which has this to say:
DAQmx Error: Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.
Property: DAQmx_SampTimingType
Requested Value: DAQmx_Val_SampClk
Possible Values: DAQmx_Val_OnDemand
Attempting to use DAQmxSetSampTimingType() with a value of DAQmx_Val_SampClk throws the same error. Does this mean that using the DAQmxCfgSampClkTiming method is completely impossible for this device? If so, how do I go about accomplishing my task? Which, again, is to load a sequence of outputs onto the card, and have it advance to the next set of outputs each time it receives an input trigger. E.g. on the first trigger it should set Dev1/port0/line0 to 1, on the second trigger it should set that line to 0 and set line 1 to 1 instead, etc.
07-21-2015 04:57 PM
07-21-2015 05:03 PM
At that point you're not doing external trigger; you're doing everything in software and thus subject to the horrendously slow and variable delays of the computer clock. Basically you're saying that the USB-6002 can't do even extremely basic external trigger tasks (input in -> generate specified output). I'm not saying you're wrong, but I'd like to know how I'd determine what its actual capabilities are, ideally through the API. Ultimately we're trying to write code that will run on many NI DAQs, and being able to programatically determine their capabilities would make our users' lives a lot simpler.
07-21-2015 06:33 PM
07-22-2015 11:23 AM
Hrm, that does appear to be the case. How vexing.
Well, thank you for your assistance! Guess we're going to have to switch in an old NI-6251 PCI card instead. Which of course I'm also having problems with, but they're different problems so perhaps I should make a new thread, with a less specific title. I hesistate to call this progress, but it is at least movement...
07-22-2015 01:27 PM
Hi there,
Unfortunally the USB-6002 does not have any clock onboard, it uses software time (on demand clock), this mean that it will use the computer software clock. for example, if you have a lot of programs running in your computer, the clock that your application will have is going to be a slow clock.
so for your application you do not need to set any clock settings in your program. you have to delete that part of the code.
Regards