06-13-2022 07:43 AM
Hey everyone,
I have created a VI with which I want to control a signal generator. Unfortunately, my VI can only be executed once (run). As soon as I start a test run, the data is transferred to the signal generator. As soon as I change something in my VI, such as the frequency, the change is not transmitted to the signal generator. If I stop the run and want to start again, no data is transferred to the signal generator. Can anyone help me to find the cause of this problem?
My VI is attached
Thanks in advance
06-13-2022 08:15 AM
This VI just does the setting up of the instrument and then ends. There is no repeating of this unless you are using the Run Continuously (which you should not be doing).
1. Your FOR loop is pointless. I will just use 100% of a CPU core and do nothing but read the controls the number of times you specified.
2. It seems like what you want to do is use a While loop. Use the Initialize VI before the loop and the Close VI after the loop. Inside of the loop, I would probably use an Event Structure to set the items when a control's value is changed.
06-15-2022 01:41 AM
Thank you.
So I should use something like a state machine. Normally a state machine consists of a while loop and a case structure located within the loop. But is it possible to create it with an event structure? If I use the event structure I have to do an event for every Instrument control, right?
06-15-2022 06:47 AM
It is not a State Machine. So let's stop that talk.
With the Event Structure, you make a different event case for each thing you want to react to, a control's value changing being the most common event type.
06-27-2022 11:23 AM
Hi crossrulz,
Thank you.
Now I have changed the code a little bit because I will use predefined sequences which I which I can select via the "sequence selection" in the front panel. I hope it makes sense with the case structure.
I have another question about how to implement the "Run" button. So if I now select the instrument and the sequence, the "Run" button should execute the specific sequence. How can this be implemented in my VI?
06-27-2022 12:44 PM
@Leamri wrote:
I have another question about how to implement the "Run" button. So if I now select the instrument and the sequence, the "Run" button should execute the specific sequence. How can this be implemented in my VI?
Put the sequence into an Event Structure. Have an event case for the Run button Value Change event. The case structure and the enum should be inside of that event case. You should also have another event for stopping the VI. I cleaned up one of the cases, I will leave the rest for you.
06-30-2022 03:32 AM
Thank you very much for your help!
If I want to start another sequence on the Channel 2 right after the first sequence. Is it a good way to make a new case for it and choosing Channel 2?
06-30-2022 07:02 AM
Or just create a control to select which channel is used. I try to avoid duplication of code whenever possible.
06-30-2022 07:17 AM
What do you mean by the control?
I already have a control in each case that selects the channel, but the other settings like frequency, amplitude etc. for the sequences are different. But I want two sequences to be executed per case, one per channel. If I now select "channel 1" in my first case and the corresponding settings for the sequence, I cannot select other settings for "channel 2" in the same case.