LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from Digital Line giving incorrect reading first time through loop

I am using two Read from Digital Line.vi functions inside a while loop to record when one of two switches is pressed (value of the digital channel changes from 'false' to 'true' when the corresponding switch is pressed). This is inside of another for loop that executes multiple times. During the first iteration of the for loop, the second Read from Digital Line function immediately returns a value of 'true' even though the corresponding switch has not been pressed. During subsequent iterations of the for loop this does not happen - both channels return 'false' until the switch is pressed.

Also, when the MAX test panel window for the second digital channel is open during execution of the progra
m, the problem does not appear. Any explanations?
0 Kudos
Message 1 of 12
(3,494 Views)
Have you wired the iteration node?
See:
http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/6cf86049ee91768a86256d530078abde?OpenDocument
It's true for reads, too.


2006 Ultimate LabVIEW G-eek.

Message 2 of 12
(3,494 Views)
Yes, I tried wiring the iteration node and this does not fix the problem.
0 Kudos
Message 3 of 12
(3,494 Views)
Could you upload the vi in question?


2006 Ultimate LabVIEW G-eek.

0 Kudos
Message 4 of 12
(3,494 Views)
Here's the vi - not sure if this will help or not. The second digital channel (for the middle finger button) returns a value of true on the first iteration of the for loop. It doesn't matter which digital channel I use for the middle finger switch, this one is always the problem. With execution highlighting on, I can see that this is the channel that reads first (maybe that is significant).

We are using the switches in an MRI scanner and this problem only appears when the switches are run through the RF filter panel (not if I hook the switches up directly to the NI connector box outside of the magnet). I'm not sure why this makes a difference - and it only happens the first time through the loop so I don't think it's a cable problem
.
0 Kudos
Message 5 of 12
(3,494 Views)
Something you can try, because I still think this is an initialization issue (i've seen this before when one portion of the program has a Write to DIO and one has a Read DIO w/o initializing)

In the frame sequence on the far left where you're writing to a digital line, write zero to the iteration node of the Write vi on frame zero. Wire a non-zero value to the vi on frame one. Add an additional frame with your Middle/Index Read vis and wire zero to the iteration nodes. In the main program True Case wire non-zeros to the Read Midlle/Index vi's. Perhaps this will initialize everything.


2006 Ultimate LabVIEW G-eek.

0 Kudos
Message 6 of 12
(3,494 Views)
When I initialize everything as you suggested, I get error -10008 at DIO Port Read "Group is invalid" inside the main program case (but it appears to work apart from this error - not sure how to fix this error).

I also tried initializing just the Write DIO in the left sequence (0 in the 1st frame, non-zero in the 2nd) and then wired the while loop iteration terminal to the Read DIO's in the main program. This resulted in one switch not working at all (both channels always False) and the other switch when pressed caused both channels to read True.
0 Kudos
Message 7 of 12
(3,494 Views)
This should be a simple thing to fix, and I don't know why it's doing all this craziness. Without wiring any of the iteration nodes and REMOVING the Write DIO vi's, does it work normally? If it doesn't then the issue is somewhere else, either in the configuration via MAX or in the physical way it's wired. You've checked to make sure that a true 5V signal is getting to the DAQ card even when the program is reading false?


2006 Ultimate LabVIEW G-eek.

0 Kudos
Message 8 of 12
(3,494 Views)
The program works normally with the Write DIO's removed and without wiring the iteration terminal to the Read DIO's. If I wire the iteration terminal to the Read vi's then I get the problem where one switch doesn't work and the other switch controls both channels. I haven't checked the actual voltage signal yet but I'll do that when I get a chance.
0 Kudos
Message 9 of 12
(3,494 Views)
3 other things that may work:
Put a delay between when the Write to DIOs go and the main program (just add an additional frame, move the True Constant there adn put a Wait function in Frame 1).

Sometimes the single DIO R/W vi works better in these kinda situations. You could replace the write DIO vis with it pretty easily, an example of which is attached.

Instead of configuring individual lines, configure the DIOs as Ports, with the first 4 as writes and the last 4 as reads.


2006 Ultimate LabVIEW G-eek.

0 Kudos
Message 10 of 12
(3,494 Views)