Perspective Button to Toggle OPC tag value

Nope, it'll just lock up a thread on the gateway; Perspective can have multiple worker threads, and the more you lock up with sleeps, the more that need to be spawned, the more resources wasted and the less scaleable your solution will be.

Sleeps lock up a Vision client because all scripts run in the same event dispatch thread which handles every event that occurs on the client. So if you have a sleep running, you're no longer able to push buttons or get tag updates, as the edt is busy sleeping

2 Likes

Good afternoon Team,

I have tried this process with an OPC tag and I cannot get it to work.

Here is my script and some screen shots.

Anyone can help?

	self.custom.chute_status = not self.custom.chute_status

Just trying to get the obvious stuff out of the way:

The "onActionPerformed" script is correctly defined on the same component as the one where you created your custom property, right ?

Basically, is the "onActionPerformed" event defined on "Checkbox_28" ?

EDIT: Also, if you're running this in the designer, make sure you turned on read/write mode

image

Hi Samuel,

I removed the custom prop and will use the self.props.selected. I do not think I need the custom prop.

I have bound that prop to the tag and made it bi-directional.

def runAction(self, event):
	self.props.selected = not self.props.selected

What's the outcome then?

Be careful though, this will have an unexpected behaviour.

You're binding this on the selected props AND you're also triggering the script.

When you click on your checkbox, a write will first occur through the binding.
THEN another write may happen because you've also configured a write on your "onClick" event.

So potentially if both writes go through, there may be a race condition where the value doesn't change at all because you write to it twice, and one write is a negation.

If you're planning on doing this, you're better off doing this on a regular button rather than a checkbox.

If you're binding a prop, remove the onClick or actionPerformed event. The original solution was for a Button which does not have a boolean prop to begin with.

1 Like

I have removed the script but it does not change the OPC tag when I check it.

The Tag path in your binding dialog doesn't match the Tag displayed in the Tag Browser panel. CHUTE21 vs CHUTE26W.

Sorry, I had the wrong one open.

Here is the correct pic.

Are you sure nothing else is writing to that tag? Can you toggle it from your tag browser?

Good morning Michael,

I am sure. I even dragged the tag to the view and recreated the checkbox.

When I toggle from the actual tag, it did popup and asked if I wanted to write once or enable read and write.

I enabled read and write and it now works.

Where, when settting this up, would I change this to read or write?

Thanks Andrew

Read up on comm mode.