Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Can create DAQmxCreateDIChan and DAQmxCreateDOChan in the same task.

Hi,

       Can we create DI and DO channel in the same task? Below is my coding but if used the same task it show error message.

 

         Error Msg  = 

Task cannot contain a channel with the specified channel type, because the task already contains channels with a different channel type.

Create one task for each channel type.

 

Code =

' Create the DAQmx task.
DAQmxErrChk DAQmxCreateTask("", vTaskHwnd)
' Add a digital input channel to the task.
DAQmxErrChk DAQmxCreateDIChan(vTaskHwnd, DIPortAddress, "", DAQmx_Val_ChanForAllLines)
DAQmxErrChk DAQmxCreateDOChan(vTaskHwnd, DOPortAddress, "", DAQmx_Val_ChanForAllLines)
'Start the task running, and read from the digital lines.
DAQmxErrChk DAQmxStartTask(vTaskHwnd)

vTaskIsRunning = True

 

Thank you very much.

 

0 Kudos
Message 1 of 6
(3,340 Views)

The error message already answered your question: no you can't have DI and DO channels in the same task.

 

Ben64

 

 

0 Kudos
Message 2 of 6
(3,308 Views)

Hi,

 

Just use the same task to write and read.

 

using (Task digitalWriteTask = new Task())
                {
                    //  Create an Digital Output channel and name it.
                    digitalWriteTask.DOChannels.CreateChannel("Dev1/po​rt0", "port0",
                        ChannelLineGrouping.OneChannelForAllLines);

                    //  Write digital port data. WriteDigitalSingChanSingSampPort writes a single sample
                    //  of digital data on demand, so no timeout is necessary.
                    DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream​);
                    writer.WriteSingleSamplePort(true, (UInt16)this.numericEdit1.Value  );

                    //  Create the reader
                    DigitalSingleChannelReader reader = new DigitalSingleChannelReader(digitalWriteTask.Stream​);
                    //   Read back the value
                    this.textBox1.Text =  reader.ReadSingleSamplePortByte().ToString();


                }

Curt

 

0 Kudos
Message 3 of 6
(3,224 Views)

No you can't.

0 Kudos
Message 4 of 6
(3,110 Views)

Yes you can. It works!

 

Curt

0 Kudos
Message 5 of 6
(3,106 Views)

@Curt_C wrote:

Yes you can. It works!

 

Curt


The answer is no you can't. Curt I agree that your code work but it is not the same thing. Your task only have DO channels that outputs data to a stream. Your reader is reading data from this stream so it is more like an echo mode, it is not reading input data from a physical channel.

 

Ben64

0 Kudos
Message 6 of 6
(3,101 Views)