01-30-2024 05:10 PM
I have a VI that uses cases in a loop to do a visa query with a *IDN? for all of my instruments. When all of the instrument are working, the VI works perfectly. When one of the instruments is off line, I would expect to have an error on the visa read as well as an empty string returned. What I get instead is a stale string from the previous instrument's *IDN?, but only when I wire the string out of the for loop. I am attaching a pared down case from an off-line computer to illustrate what I am seeing. I can not get the info of the actual test stand with the real instruments. In this example, when the instruments are both working, I get the id strings correctly from both. When instrument 2 goes off line, the visa read in case 1 returns the exact same string that instrument 1 just returned in case 0. In the same situation, if I delete the wire branch that takes the read string out of the loop, I get the empty string that I would expect from case 1. Is this a bug with LabVIEW, or is there some reason that adding a seemingly unrelated string wire changes the behavior of how the visa read works? I know I can query for an error after the visa open and just not do the *IDN?, but I would like to understand the behavior I am seeing here. The LabVIEW version is 2016. Thanks for any insight.
01-30-2024 05:51 PM
I have no idea what's causing the problem;
but writing code like that is worse than using a stacked sequence.
Instead, do something like this:
01-31-2024 07:57 AM
Hi Paul, Thanks for taking the time to reply. I agree that the code I posted is not the most efficient way to do things, but it is actually pared down from a much larger VI that does more instrument specific actions within each case. This is the result of chopping out everything not related to the issue. Also, in the actual code, it it is not the loop index that chooses the cases. This too was done to create a vi with the minimum content but still show the problem. Interestingly, when structured as you suggest, the duplication of the previous instrument's response does not happen and I get an empty string from the second visa read as expected. It appears that the presence of string wire coming out of the case and exiting the loop affects what is returned by the visa read and that is blowing my mind.
01-31-2024 08:15 AM
There have been a lot of fixes to the LabVIEW compiler due to it being too anxious to reuse data space (ie avoid copying) in the last 7+ years. Try adding an Always Copy (Application Control->Memory Control palette) after your VISA Read or elsewhere on the path and see if that fixes it.
01-31-2024 10:33 AM
Placing Always Copy in every case just before the string wire goes out fixes the problem. The string variable in each case, which is wired to the visa read directly and before the Always Copy, now gets the expected result. This too is odd since the Always Copy is not in between the visa read and the variable. Placing a single Always Copy outside the case but inside the loop has no effect.