05-05-2008 10:49 AM
I'd
like to do some fast digital writes to my DAQmx device's individual lines. By
fast, I mean sub-millisecond timing per write.
Using NI's examples, it appears I have to do four things to write to a digital
line:
1. Create a new "Task".
2. Create a digital output channel for that task.
3. Create a new "DigitalSingleChannelWriter" from the task's
"Stream".
4. Call the "WriteSingleSampleSingleLine" method of that
"DigitalSingleChannelWriter".
It takes 15 - 30 milliseconds to do all four of those, per digital write.
So I tried doing the first three when my C# form loads, then only calling the
fourth one when I want the speedy digital write. I get the following error
message when I try that:
An unhandled exception of type 'NationalInstruments.DAQmx.DaqException'
occurred in NationalInstruments.DAQmx.dll
Additional information: Measurements: Task specified is invalid or does not
exist.
Status Code: -200088
Attached is my entire project in a .zip file. Also, here is my source code
which demonstrates the aforementioned error when checkBox1_CheckedChanged() is called:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NationalInstruments.DAQmx;
namespace DigitalLineWriter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Task digitalWriteTask;
private DigitalSingleChannelWriter
digitalWriter;
private void Form1_Load(object
sender, EventArgs e)
{
using (digitalWriteTask
= new Task())
{
digitalWriteTask.DOChannels.CreateChannel("dev3/port0/line23",
"",
ChannelLineGrouping.OneChannelForEachLine);
digitalWriter
= new DigitalSingleChannelWriter(digitalWriteTask.Stream);
digitalWriter.WriteSingleSampleSingleLine(true, true);
}
}
private void
checkBox1_CheckedChanged(object sender, EventArgs e)
{
digitalWriter.WriteSingleSampleSingleLine(true, checkBox1.Checked);
}
}
}
05-05-2008 01:56 PM
05-22-2008 02:32 PM