How do I manipulate screen components with a script?


Recommended Posts

I would like to do the following using a script

Check if a LED component changes state.

if state >0 then get the entered value from a variable value text box

assign value from text box to Dac0

if state =0 then assign a value of 0 to dac0

Only do the state>0 routine once to allow for manual adjustment

I have no idea how to write this sequence and would really appreciate the help and advice.

Link to comment
Share on other sites

What's driving the LED? A channel? If so, use a Channel Event to look for when the state changes and perform the appropriate action. The text box (don't use an edit box, see the blog), should change a global variable that you access from the event.

Link to comment
Share on other sites

I am using a toggle switch to change the state of the LED component, and based on that, I want to retrieve a variable value from an edit box and assign it to a channel.

The only time I want to assign the value is when the state changes from 0 to 1. If the state remains with a value of 1 I do not want to continually assign a value. If the state remains 0 then the assigned value should always be 0.

Link to comment
Share on other sites

I currently have the two components tied together.

Component.FanPowerIndicator.strExpression

FanPowerIndictor is the LED

I am prepared to change whatever is necessary in order to get this to work.

I have no ego so if there is a better way feel free to tell me.

Link to comment
Share on other sites

You can do it that way, but somewhere you are doing something like:

Component.FanPowerIndicator.strExpression = "1" to turn the LED on. Well, in the line after that, do your logic for the output.

That said, I personally would do the reverse and use a Test channel to hold the state of the LED. Make it device type Test, I/O type Dig Out. Then set the expression of the LED to that channel (mychannel[0]). You can then change the state by doing MyChannel = 1 or MyChannel = 0. Then you can take advantage of the Event of the channel. The event is script that executes whenever a new value comes to a channel. So you can put your logic for the control right there and as long as you use the MyChannel = to change its value, the logic will always apply.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.