SystemLink Forum

cancel
Showing results for 
Search instead for 
Did you mean: 

Using python scripts

Solved!
Go to solution

I'm trying to do something very simple, I'd like to change the value of a LED in the Dashboard every ten seconds but I have no clue how to use the Python scripting event to do this. Could you help me please.

0 Kudos
Message 1 of 7
(3,794 Views)

Hello, what are you trying to do ?

Why did you not use LabVIEW?

0 Kudos
Message 2 of 7
(3,763 Views)
Solution
Accepted by topic author nandiouioui

Hi,

 

The attached dashboard features an LED that is triggered to change value every second using a timer event script.

 

The manual (https://www.ni.com/documentation/en/systemlink/latest/data/adding-event-scripts-to-widgets/) text falls a bit short.

The python code below is added to an led widget with label "led1". Every time the timer event trigger the function testLED is called with the widget name as argument. The biggest issue is that the LED property page shows the property name, which is spot on for "Off label" and "On label", but not for "value". This property name is all lower case, but it doesn't seem to be described anywhere. (accidentally stumbled on this while reviewing the raw content of the exported fp file).

 

def testLED(widget_name):
  currentValue = get_widget_prop(widget_name, 'value')
  newValue =  not currentValue
  set_widget_prop(widget_name, 'Off label', 'False')
  set_widget_prop(widget_name, 'On label', 'True')
  set_widget_prop(widget_name, 'value', newValue)

Unzip the file and import into SystmLink (V19.0) (@NI: Please add .fp to allowed file extensions) 

Regards,
André (CLA, CLED)
Message 3 of 7
(3,756 Views)

Thank you so much, do we have to use ' ' every time we want to change the value ?, also can we add conditions or loops? And what if we want tu update our value depending on some other widget? 

0 Kudos
Message 4 of 7
(3,743 Views)

You can do a lot as long as it's supported by Python within the scope of the defined function.

You can create variables that hold the constant values and use those, e.g.

Param = 'value'

This variable can then be used instead of the constant string. I only did it this way to clearly show which value is taken from which place. 

Regards,
André (CLA, CLED)
0 Kudos
Message 5 of 7
(3,733 Views)

I've been trying to use python scripts with 'Binding Updated' but it doesn't work. I don't know what I'm doing wrong

0 Kudos
Message 6 of 7
(3,697 Views)

Hi,

 

Did you find a solution for this problem?

0 Kudos
Message 7 of 7
(3,333 Views)