From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-06-2019 11:32 PM
Hi,
I am creating a program that will be able to control a power supply as well as continuously read the output current from the supply. I created my program such that I have a loop that will handle user events (i.e. user command turning on/off the power supply) and a loop that charts measurements to a live graph, one being the power supply output current.
How can I continuously monitor the power supply current while still being able to command it? What is the best method for doing this? Thanks,
Solved! Go to Solution.
01-06-2019 11:48 PM
Create a loop that continually writes the data requests to the port and receives the responses. For when you want to command it, use a case structure so that after getting the current data, it can write and/or read any commands you send to it.
01-07-2019 02:33 AM
There are lots of really interesting ways to approach this, but you are generally on the right track with parallel loops.
RavensFan is suggesting something like a state machine, which is either asking for current current, telling the power supply to do something or one and then the other. This design is pretty solid and is a good design to practice.
We could imagine further states like wait for connection or shutdown. The essential ingredients is a while loop with a case structure inside and an enum on a shift register. The enum controls which case of a case structure is executed on each iteration. The default state could be an event structure with a fast timeout asking if the user has sent a command, if command, then operate appropriate case in the next iteration using the enum, if timeout, then set the next state to ask the power supply what the current is. And so on. The use of the event structure gives you a lot of granularity in response to pressing different front panel buttons.
01-07-2019 09:26 AM - edited 01-07-2019 09:27 AM
An event driven state machine is the obvious architecture for this.
Basically you measure and display the current until a user event tells it to change or turn off/on the power.