LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local varible cannot write

Hi all,

 

I recently started to work with LabVIEW and am trying to control our Omicron LED. I found the LabVIEW program that the company developed. From the file, we can enter the LED power and percentage to control the light output. However, as I try to use the Local variable to enter the power and percentage through different controls, none of them work.

 

As shown in the screenshot, for percentage 3 and power 2, they have no response at all. For percentage 5 and power 4, when I changed their values, the data shown on the original percentage and power were updated, but the actual running data was not affected. I guess the problem is due to the race conditions? 

 

The ultimate goal of this project is to change the light power for each time interval, but right now I cannot control the input using local variables. Could someone help? Thanks in advance!

 

Best

 

 

block diagram.png

zxnb_0-1777898281412.png

 

0 Kudos
Message 1 of 10
(236 Views)

Hi zxnb,

 


@zxnb wrote:

I recently started to work with LabVIEW


We can see this from your overuse of local variables!

(You just created race conditions in your code!)

 

Suggestions:

  1. Note those learning resources offered at the top of the LabVIEW board!
  2. Use less local variables.
    Use more wires.
    Learn about shift registers.
    Learn to avoid race conditions.
  3. Obey the LabVIEW mantra "Think Dataflow!"…

After doing so: ask again with a cleaned-up VI!

 


@zxnb wrote:

For percentage 5 and power 4, when I changed their values, the data shown on the original percentage and power were updated, but the actual running data was not affected. I guess the problem is due to the race conditions?


Yes.

Why do you even wire them to local variables instead of using them directly in your event case?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(220 Views)

@zxnb wrote:

 

As shown in the screenshot, for percentage 3 and power 2, they have no response at all. For percentage 5 and power 4, when I changed their values, the data shown on the original percentage and power were updated, but the actual running data was not affected. I guess the problem is due to the race conditions? 


Yes, your code is just peppered with glaring "race conditions" and since you mention this term, why didn't you fix it already?

 

It is impossible to diagnose a truncated code picture, so please attach the actual VI. Your "power" control gets values from multiple places at once, and whatever writes last wins. Writing to a local of "power" will NOT fire a value change event. We cannot tell if you also have value change events for the other controls. As soon as your visible event fires, these controls get immediately overwritten at the start of the next iteration by the code outside the event structure, so what was the point of changing them for 100ms?

 

As already suggested, wire up all you controls and indicators are get rid all the local variables. Most are probably not needed.

 

Once you attach your VI (Make sure to use "save for previous, 2020 or below) we can give more specific advice. Make sure you explain what the code is supposed to do and the meaning of the various terminals. It will probably help to give them more intuitive names.

 

I was looking at your upper picture. How does the code in the lower picture fit into all this? You seem to e trapping your code inside inner loops for minutes. Not a good idea!

0 Kudos
Message 3 of 10
(169 Views)

I like love to be lexically nit-picky.

 


@GerdW wrote:
  1.  
  2. Use less local variables.

That should be "Use fewer local variables".

"Less" refers to things that cannot be enumerated (e.g. less water).

"Fewer refers to things that can be enumerated (e.g. fewer molecules of water).

Think of "less" as a singular form and "fewer" as a plural form.

I never get them mixed up; otherwise I might say things like: 'To lose weight, I should eat fewer food (then I would be fewer fat).'.

0 Kudos
Message 4 of 10
(128 Views)

Not everyone has English as first language here, and we definitely got the gist. 😄

 

I would suggest: "...  use fewer useless local variables... ".

Message 5 of 10
(122 Views)

Hi Paul,

 


@paul_a_cardinale wrote:

I like love to be lexically nit-picky.


I behave the same when it comes to German text… 🙂

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(105 Views)

Hi GerdW, 

 

Thanks for the reply. I am not sure if I understand "Use more wire" clearly. I duplicated the case and made it detect changes in the value of the second control. So it worked fine. I am trying to understand the dataflow right now.

zxnb_0-1777962826842.png

 

I learned LabVIEW using the VI files my graduate colleague created. We used LabVIEW to run continuous experiments with different stages of set temperatures and light powers, and each input was wired to a local variable. We have now switched to Omicron LED and have to rebuild the VI file. Therefore, I was thinking if using a local variable is more convenient than duplicating 20+ events.

zxnb_1-1777963497618.pngzxnb_2-1777963533622.png

 

Best Regards, 

zxnb

 

0 Kudos
Message 7 of 10
(72 Views)

Hi altenbach,

 

Thanks for the reply and explanation. In the upper screenshot, I removed the local variables and created a duplicate event for the second control, and it worked fine.

 

The lower screenshot is from another file, where I was trying to coordinate the light control system with our previous temperature control file. We used LabVIEW to continuously monitor experiments at different temperature setpoints and light powers. We hope that the code can run for several minutes and automatically jump to the next stage with the next set of values. Since we have 20+ stages, I was thinking if there is a better way than duplicating lots of events. 

 

Best,

zxnb

0 Kudos
Message 8 of 10
(64 Views)

Hi zxnb,

 


@zxnb wrote:

Since we have 20+ stages, I was thinking if there is a better way than duplicating lots of events. 


Have you ever heard of "state machines"?

It seems you didn't, otherwise you would NOT create a sequence of 21 frames with each frame holding the very same code fragment...

 

When you want to repeat the same code multiple times then you should use a loop!

When there is an array of input data to be processed one after the other: use an autoindexing FOR loop!

 


@zxnb wrote:

I removed the local variables


Why is there a "COM port" local variable? Why don't you use a shift register instead?

Why are there still lots of unused terminals in the block diagram? (Like "LED Power", "LED Percentage".)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(59 Views)

Value change doesn't trigger on Local variable changes.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 10
(38 Views)