09-15-2009 04:36 PM
I'm working with a USB-2009 and want to write an array of bytes to the digital output using DigitalSingleChannelWriter.WriteMultiSamplePort. The C# code below illustrates what I am trying to do. An error occurs when 'task.Timing.ConfigureSampleClock' is excuted and the message listed below.
I have read the NI-DAQmx .NET documentation. It does not specify which classes and/or function should not be called on the USB-2009 so I am not certain whether or not the 'ConfigureSampleClock' can even be used in this situation.
Can anyone point me to or provide me with sample code that demonstrates how a byte array can be sent to the digital output on the USB-2009? If the USB-2009 is not designed to do this then this also would be very helpful to know. If your example is only for analog output then I believe this would be just as good. I am able to successfully output a single byte, one at a time, on the digital output line ... but not an array of bytes.
Thanks,
Ian
===============================
Sample code
// note the following object instances:
// 'simulator' simulates a square wave with an amplitude of 255
// 'deviceID' manages the string ID of the USB-2009
int x = -1;
Byte[] waveData = new Byte[simulator.Count];
foreach( Double sample in simulator ) {
waveData[++x] = Convert.ToByte( sample );
}
using( Task task = new Task( "myTask" ) ) {
task.DOChannels.CreateChannel(
deviceID + "/port0",
"myPort",
ChannelLineGrouping.OneChannelForAllLines
);
task.Timing.SampleTimingType = SampleTimingType.OnDemand;
task.Timing.ConfigureSampleClock(
String.Empty,
samplingRate,
SampleClockActiveEdge.Rising,
SampleQuantityMode.FiniteSamples,
simulator.Count
);
task.Control( TaskAction.Verify );
DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter( task.Stream );
writer.WriteMultiSamplePort( true, waveData );
} // using( Task task = new Task() ) {
===============================
Error message generated by executing the line 'task.Timing.ConfigureSampleClock':
NationalInstruments.DAQmx.DaqException: Requested value is not a supported value for this property.
Property: NationalInstruments.DAQmx.Timing.SampleTimingType
You Have Requested: NationalInstruments.DAQmx.SampleTimingType.SampleClock
You Can Select: NationalInstruments.DAQmx.SampleTimingType.OnDemand
Task Name: myTask
Status Code: -200077
at nNIMSSAIL100.StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >.CheckWithName(StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >* , tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* pName)
at NationalInstruments.DAQmx.Timing.set_SampleTimingType(SampleTimingType value)
at NationalInstruments.DAQmx.Timing.ConfigureSampleClock(String signalSource, Double rate, SampleClockActiveEdge activeEdge, SampleQuantityMode sampleMode, Int32 samplesPerChannel)
at Test.MainForm.testNINetLibrary_Click(Object sender, EventArgs e) in C:\Users\XXXXXl\Documents\Visual Studio\Projects\Digital IO - test\MainForm.cs:line 197
Solved! Go to Solution.
09-15-2009 08:15 PM
09-16-2009 05:42 PM
Hello Ian,
The error you are seeing is because you are trying to cinfigure a sample clock that is not actually present. The USB-6009 is completely software timed (meaning that the values are updated based on your loop rate and how quickly your computer can change them). It seems like you're calling the right property, so the error message seems a little misleading. We can look into that to see if it's something that needs to be corrected. Normally, SW timed applications just don't configure a sample clock. Here's some code to output just once, so feel free to just repeat it to update as you need.
int main(void)
{
int error=0;
TaskHandle taskHandle=0;
uInt32 data=0xffffffff;
char errBuff[2048]={'\0'};
int32 written;
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"Dev1/port0","",DAQmx_Val_ChanForAllLines));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
/*********************************************/
// DAQmx Write Code
/*********************************************/
DAQmxErrChk (DAQmxWriteDigitalU32(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&data,&written,NULL));
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}