Sign in to follow this  
Antony

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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Yes, but how are you tying the two together? Is the switch directly changing the LED state, or are you using a global variable or channel as an intermediary?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this