SystemLink Forum

annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

Using python scripts

Risolto!
Vai alla soluzione

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
Messaggio 1 di 7
5.380Visualizzazioni

Hello, what are you trying to do ?

Why did you not use LabVIEW?

0 Kudos
Messaggio 2 di 7
5.349Visualizzazioni
Soluzione
Accettato da autore argomento 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)
Messaggio 3 di 7
5.342Visualizzazioni

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
Messaggio 4 di 7
5.329Visualizzazioni

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
Messaggio 5 di 7
5.319Visualizzazioni

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
Messaggio 6 di 7
5.283Visualizzazioni

Hi,

 

Did you find a solution for this problem?

0 Kudos
Messaggio 7 di 7
4.919Visualizzazioni