Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

how can I read the DIO status when I set it as output port?

In traditional Measurement studio, we can read the port status even it is output port.
But in Measurement stuido V8.0, I don't know how the get the value I just set.
This is useful in Mask function.
For example:
m_taskWrite = std::auto_ptr<CNiDAQmxTask>(new CNiDAQmxTask(_T((LPCTSTR) tempString)));
m_taskWrite->DOChannels.CreateChannel("Dev1\Port0","", DAQmxOneChannelForAllLines);     
m_writer = std::auto_ptr<CNiDAQmxDigitalSingleChannelWriter>(new CNiDAQmxDigitalSingleChannelWriter(m_taskWrite->Stream));
m_writer->WriteSingleSamplePort(true,value /*12*/);
--> here how can I read the value back?
if I use
m_taskRead = std::auto_ptr<CNiDAQmxTask>(new CNiDAQmxTask(_T((LPCTSTR) m_DeviceUniqueString)));      
m_taskRead->DIChannels.CreateChannel("Dev1\Port0","", DAQmxOneChannelForAllLines);      
m_reader = std::auto_ptr<CNiDAQmxDigitalSingleChannelReader>(new CNiDAQmxDigitalSingleChannelReader(m_taskRead->Stream));             
m_reader->ReadSingleSampleMultiLine(readData);
All the lines in Port0 will become high.
So if any function call in 'CNiDAQmxDigitalSingleChannelWriter' can let me get the DO status?
0 Kudos
Message 1 of 5
(4,196 Views)

Bird,

There should be no need to create a new task, as it looks like that is what you are doing to just do the digital read after a write. In the same task as your digital write, right after you write your value, put a DAQmx Digital Read command and that should do it for you. Let us know how that goes.

-GDE

0 Kudos
Message 2 of 5
(4,185 Views)

Hi GDE,

I really don't understand how you implement a digital read when you create the DOChannels (Writer).

If I need to create DIChannels after write as the following, it would have the following exception:

m_taskWrite = std::auto_ptr<CNiDAQmxTask>(new CNiDAQmxTask(_T((LPCTSTR) tempString)));
m_taskWrite->DOChannels.CreateChannel("Dev1\Port0","", DAQmxOneChannelForAllLines);     
m_writer = std::auto_ptr<CNiDAQmxDigitalSingleChannelWriter>(new CNiDAQmxDigitalSingleChannelWriter(m_taskWrite->Stream));
m_writer->WriteSingleSamplePort(true,value /*12*/);
m_taskWrite ->DIChannels.CreateChannel("Dev1\Port0","", DAQmxOneChannelForAllLines);      ---> exception error here
//m_reader = std::auto_ptr<CNiDAQmxDigitalSingleChannelReader>(new CNiDAQmxDigitalSingleChannelReader(m_taskWrite ->Stream));             
//m_reader->ReadSingleSampleMultiLine(readData);
The exception code-->
The task cannot contain a channel with the specified channel type (DIChannel), because the task already contains channel with a different channel type (DOChannel).
 
Can you give me more clear command in VC .net?
0 Kudos
Message 3 of 5
(4,171 Views)

Bird,


You don’t need to run the DIChannels.CreateChannel… This is what is causing the error. You already have the resources reserved for your output task, so now trying to reallocate them is throwing this error. All you should need to do is run your next two lines, that were commented out:

 



m_reader = std::auto_ptr<CNiDAQmxDigitalSingleChannelReader>(new CNiDAQmxDigitalSingleChannelReader(m_taskWrite ->Stream));            

m_reader->ReadSingleSampleMultiLine(readData);

The idea is, you don’t need to create any new tasks, or reallocate any resources, the digital write tasks, have the ability to read their same channels as well. So the strategy is to just do all of your writes as usual, and if you need to read the same lines to ensure things worked you can just do so without reconfiguring anything.


I hope that clears up the confusion.

-GDE

0 Kudos
Message 4 of 5
(4,153 Views)

Hi GDE,

Thank you. It works now.

Bird

0 Kudos
Message 5 of 5
(4,129 Views)