06-20-2024 10:47 AM
I am a beginner to LabView and am trying edit two global variables based on collected digital inputs. However when I run the program the values from the previous execution are what is output. I've tried inserting a flat sequence structure and writing a constant to the variables first, but it doesn't seem to execute. Thanks for any help you can give.
Solved! Go to Solution.
06-20-2024 11:42 AM
Hi edawgie,
You are not using global variables, you are using Network Published Shared Variables.
Those variables are shared over the network through the NI Shared Variable Engine. A consequence compared to plain global variables is that the value you obtain from the Shared Variable Node may take a little time to reflect the last value written to it, typically causing race conditions like you have in your code.
A solution would be to only write to the Shared Variable (not read), and have a local copy of the value in a Shift Register:
Regards,
Raphaël.
06-20-2024 11:48 AM
I hate Network Published Shared Variables. They are slow (requires a timeout, writing to a database, and then waiting for the update) and insecure (anybody on the network can write to them). There are so many things that can go wrong and you have little to no readability into anything if there is an issue. NPSVs are actually evil (this coming from the guy who gave an entire presentation on why Global Variables are not evil).
When communicating with cRIOs, I just use raw TCP. I know many like Network Streams. Both of these options are a lot better than NPSVs. Write a main application for the cRIO that can run your two subroutines when desired and have it stream the data back to the PC. You PC application can then read the data, parse it, and do whatever else is required from there.
06-20-2024 11:53 AM
@edawgie wrote:
I am a beginner to LabView
Are you writing this yourself, or is this something you've inherited?
For a beginner, my advice would be to avoid global variables altogether. They break data flow and can easily read to race conditions. There are almost always better ways.
On top of that, do you need to publish all of these values to the network? If not, you should not be using Shared Variables. That's not the same thing as a global variable.
06-20-2024 11:56 AM
Thank you! I did not know the difference between such variables. I will do a deeper dive into those to learn more.
Everett