10-18-2017 02:45 PM
Hello everyone,
I am using NI usb-6003 and C# programming. I need to activate two digital line (p0/line0 and P0/line1) synchronously, and remain active 500 microsecond for the first one and 12 second for the other one. I couldn't do that with software because of the accuracy. I was wondering if anyone know how I can do it with the hardware using C#.
10-19-2017 01:32 PM
Hi,
I want to make sure we're on the same page. If you're using LabVIEW ("software"), you are still able to enforce hardware timing, where the timing is enforced on the USB 6003 instead of on the software.
There isn't any reason that text-based should run faster. It might seem like because LabVIEW is a graphical programming language, and C# is text-based, that text-based would be faster, but that is not the case.
If you are running into limitations with the USB 6003 with LabVIEW, the same limitations will exist in LabWindows CVI. But we can make sure you're using the hardware as optimally as possible, by exploring your code.
Are you using a LabVIEW example? You can get to the example finder from within LabVIEW by going to Help -> Find Examples, and I would look in the Hardware Input and Output folder on the Browse tab.
Hope this helps! Keep us posted!
10-19-2017 02:51 PM
Dear Timothy D.,
Thank you for the response.
I don`t use LabVIEW software. I am developing a software using C# programming. In this case, I compared the windows form application timer with the hardware one. The windows timer is not able to do a task in microsecond. The only thing I need is to design a button on a form. When the button is pressed each time, I need to write true on p0/line0 for 500 microsecond duration and on p0/line1 for 2 second duration. I do not know how I can use the internal timer to do this. I would appreciate your help.
Best,
E.
10-20-2017 01:02 PM
E,
If you look at Text Based NI-DAQmx Data Acquisition Examples, you can see what examples we have provided by our DAQmx drivers.
You would need the DAQmx drivers, the newest of which are here. Make sure you do a custom installation so you can choose to include the DotNET options which are not included by default.
I hope this helps! But, let me know!
Thanks,
10-20-2017 02:55 PM - edited 10-20-2017 03:16 PM
Thanks for the answer,
@TimothyDug wrote:
E,
If you look at Text Based NI-DAQmx Data Acquisition Examples, you can see what examples we have provided by our DAQmx drivers.
You would need the DAQmx drivers, the newest of which are here. Make sure you do a custom installation so you can choose to include the DotNET options which are not included by default.
I hope this helps! But, let me know!
Thanks,
@TimothyDug wrote:
E,
If you look at Text Based NI-DAQmx Data Acquisition Examples, you can see what examples we have provided by our DAQmx drivers.
You would need the DAQmx drivers, the newest of which are here. Make sure you do a custom installation so you can choose to include the DotNET options which are not included by default.
I hope this helps! But, let me know!
Thanks,
10-20-2017 03:15 PM - edited 10-20-2017 03:21 PM
Thank you for the answer,
I already installed the driver. I looked at the examples but I couldn't find the right answer.
I have written this code to use stopwatch timer of windows but it doesn't work properly in 500 microsecond.
DigitalSingleChannelWriter write0 = new DigitalSingleChannelWriter(task0.Stream);
DO0 = task0.DOChannels.CreateChannel("Dev1/port0/line0", "", ChannelLineGrouping.OneChannelForEachLine);
sw.Start();
task0.Strat();
write0.WriteSingleSampleSingleLine(true, true);
while ((sw.ElapsedTicks *1000000/Stopwatch.Frequency ) <=500)
{
continue;
}
write0.WriteSingleSampleSingleLine(true, false);
task0.Dispose();
I want to write "true" on line0 only for 500 microsecond duration and then return to "false".
10-23-2017 02:48 PM
Hey, so the way you have it is, as you suspect, software-timed. Instead of a single sample write and a software while loop delay, you are going to want to write a waveform, and enforce the 500 microsecond delay by enforcing the corresponding frequency, 2kHz. Then just configure the waveform to write, a 1 and then a 0, at that frequency. That should be the behavior you are looking for.
http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/55df5f1f/
Alternatively, if you'd like to create something continuous, a pulse train, this would use a counter task (as opposed to a digital task), and the following link should help you set that up.
http://www.ni.com/example/30745/en/
Keep in touch with us, and let me know how it is going for you, and of course if you have anymore questions, or if anything is unclear.
Thanks,
10-24-2017 05:05 PM
Hi, I tried for the timing and write the waveform. I couldn't do that. Is it possible to give me a brief example of this. I couldn't find any example in NI DAQmx folder for writing the waveform and changing frequency.
Thanks,
E.
10-25-2017 11:31 AM
I have written this code:
NationalInstruments.DAQmx.Task task0 = new NationalInstruments.DAQmx.Task();
DO0 = task0.DOChannels.CreateChannel("Dev1/port0/line0", "Port", ChannelLineGrouping.OneChannelForEachLine);
task0.Timing.SampleTimingType = NationalInstruments.DAQmx.SampleTimingType.OnDemand;
task0.Timing.ConfigureSampleClock("", 2000 , SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);
.
.
.
But it has an error:
Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.
Property: NationalInstruments.DAQmx.Timing.SampleTimingType
Requested Value: NationalInstruments.DAQmx.SampleTimingType.SampleClock
Possible Values: NationalInstruments.DAQmx.SampleTimingType.OnDemand
Task Name: _unnamedTask<0>
Status Code: -200077
Does it mean that usb-6003 is not able for changing clock frequency?
Also, I was wondering if you could give me a sample code that how I can write a waveform exactly a 1 and a 0.
Thanks,
E.
10-25-2017 02:55 PM
Hey, thanks for the replies!
I did some research, and found that the USB 6003 cannot do a hardware-timed digital out task. You cannot use hardware timing with the digital out task for the USB 6003.
I want to understand what you want to do as we probably offer a device better suited to your needs. Do you simply want two pulse trains running at 2 kHz and 0.5 Hz (500 us delay, and 2s delay)? Or, do you just want a signal that arbitrarily goes high for 500 us and then low indefinitely, and the same situation for 2s on a different signal?
If all you want is a pulse train, then we have an example that would do that, which I attached. Although, you only have access to one counter with the USB 6003, so you cannot do two continuous tasks simultaneously at different frequencies.
You can however do an analog square wave task at a 2 kHz frequency. However, your USB 6003 only has 1 counter on it, so you could not do 2 simultaneous tasks at different rates. Check out the spec sheet here:
http://www.ni.com/pdf/manuals/374372a.pdf
For writing the 1 and 0 to a digital waveform, if you configure the task as a square wave, or a pulse train, you would not need to explicitly write a 1 and a 0 periodically. It would automatically happen.
However, to explicitly write a line high, there is a lot that goes into that. I have a code snippet from the ContWriteDigChan_PipeSampClk from our examples below:
myTask.Stream.WriteRegenerationMode = WriteRegenerationMode.DoNotAllowRegeneration; int states = (int)samplesPerBufferNumericUpDown.Value; int signals = myTask.DOChannels.Count; // Loop through every sample waveform = new DigitalWaveform[signals]; Random r = new Random(); for (int i = 0; i < signals; i++) { waveform[i] = new DigitalWaveform(Convert.ToInt32(samplesPerBufferNumericUpDown.Value), 1); // Generate a random set of boolean values for (int j = 0; j < states; j++) { if (r.Next() % 2 == 0) waveform[i].Signals[0].States[j] = DigitalState.ForceUp; else waveform[i].Signals[0].States[j] = DigitalState.ForceDown; } }
The bolded lines would be explicitly writing a line high or low, and you could adapt the code as neccessary for your application. However, like I said above, the USB 6003 is unable to do a hardware-timed digital task.
I hope this helps. Let us know how this works for you!