11-23-2016 10:12 AM - edited 11-23-2016 10:13 AM
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.
11-26-2016 03:50 PM
12-27-2016 06:51 AM
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/port0", "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
02-01-2017 03:40 AM
No you can't.
02-01-2017 06:45 AM
Yes you can. It works!
Curt
02-01-2017 09:18 AM
@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