Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with CWDIO control programming -- Transient level change

I'm having a problem with using the CWDIO control in Measurement Studio / C++. What I am doing is using the DIO
port on a DAQPad to both monitor and control the state of an external device -- line 0 of Port 0 is used as an output bit for setting the state of the device, and line 1 is used as an input bit to monitor the state of the device.

See snippet below....

CCWDIO m_dio;
m_dio.SetErrorEventMask( -1 ) ;
m_dio.SetDevice( nID ) ;

CCWDIOPort port = m_dio.GetPorts().Item(CNiVariant(0)) ; // Port 0
port.SetAssignment( cwdioLineConfigured ) ;
port.SetLineDirection( 0x01 ) ; // output in first line only
CCWDIOLine pline = port.GetLines().Item(CNiVariant(0)) ;
pline.SingleWrite( CNiVariant( 1 ) ) ; // set output line high

The bit I'm using for output uses a pull-up resistor to keep in a high state when not in use.


The problem that I'm running into is that when the code above is executed it occasionally results in the line 0 being very briefly set low. Is there something I'm missing here? Are things being done in the right order? Could this be happening between the SetLineDirection() and SingleWrite() ?

Thanks for the help...

Mark Grehlinger
0 Kudos
Message 1 of 4
(2,967 Views)
Hi Mark,

The code you posted looks like it contains configuration, a read, a write. Is this your entire code or just a part of it? I would expect there to be some small glitch when you configure the lines (set direction). So you should probably see the glitch only once. Whenever you write to or read from the lines you should not be reconfiguring the directions. This would cause more glitching throughout the execution of your program. You should not see any glitches during the write operation (only when configuring the lines).

Hope this helps.

-Sal
Message 2 of 4
(2,956 Views)
Hi Sal:

Thanks for the reply. In answer to your questions, that is only a small section of the application code, and is only executed once when the application first starts -- the SingleWrite() following the SetLineDirection() was added to just insure that the port was in a known state. There are subsequent read/write operations on the port and they all work as expected.

I have also tried removing the SingleWrite() in this initialization block -- I still get the problem with the state of the line being occasionally set to 0 momentarily.

I gather from your reply that anytime the line direction is set on the port that there may be transient state changes. Is it possible to leave the DAQ HW configured in such a way that the ports are always set to the correct line direction? How persistent is this setting?

Thanks,

Mark
0 Kudos
Message 3 of 4
(2,952 Views)
Hi Mark,

Yes, you may experience transients when setting/resetting the line direction. When you set the line direction, it should stay set until the board is power-cycled, reset, or the line directions are reset. You should only need to set the directions once at the beginning of your code. It should not need periodic resetting unless the board itself is power cycled/reset.

Thanks,
Sal
0 Kudos
Message 4 of 4
(2,945 Views)