Hello,
I am wondering how one is supposed to troubleshoot script code within the designer? I have run into a couple situations where code just doesn't execute and I cannot seem to find any way of easily troubleshooting what is going on. Is there no output or build window that gives some insight? Maybe a breakpoint I can insert to see if the pointer is even reaching that line of code? Or does one simply troubleshoot with outputting stuff to a debug window or text file?
For example, I wrote the following code in a script within a button click event and it would turn the tag on but not off. I forgot to import sleep function from time and it just seemed to stop executing at that function call. Once I imported the function it worked as intended, of course.
Cheers,
David
First... never use sleep.
Second, liberal use of system.util.getLogger to log data.
Thirdly, know your scope.
If Vision, then errors in the designer show up in the designer diagnostics, or client diagnostics, or the gateway logger.
If Perspective, then errors show up in the gateway logger.
Hey, thanks for the help...
Would you be able to share some insight as to why I shouldnt use the sleep function? I think you can see what I am trying to do. maybe you have a suggestion on how to properly acheive this? I essentially want to pulse the tag on when the button is pressed.
It is a designer project. I am able to find the issue in the logger file within the gateway as you mentioned. Thanks for showing me that!
In Vision, if you are ever using sleep in any sort of fashion, you are pausing a thread. If this is on the UI, then the ENTIRE UI is frozen until the sleep is over.
In Perspective, it is less of a problem but still the wrong way to accomplish something.
Ignition is highly event driven and tossing in random sleeps is how you create chaos in the backend. I can't speak to all the technical reason, there are guys here that can, but I do know that sleep can and will cause issues.
I assume that you are trying to emulate a one-shot button?
I had a funny feeling what I was doing was not correct / efficient. I am in very early development, and as I am sure you can tell, ignition is quite new to me. I appreciate you taking the time to help me!
I am indeed trying to emulate a one shot button.
This is perspective correct?
This: OPC "Start Button" in Perspective - #2 by pturmel would be what I would recommend. Set via OPC, not tag, and then once the PLC receives the command reset in the PLC.
right, and I would have already done that if I was communicating with a normal PLC... In this case it is going to an AMR robot and I don't really have access to be able to just write a 0 back to the tag... easily at least... is there another way you can suggest I take to achieve this? the sleep does work, but i understand your point, and would like to understand the correct way to handle this.
In this case, I would probably write both the value to the device, as well as a unique memory tag, or a custom property, that is x time into the future to represent when you want to reset the tag. Then, having a gateway timer script that is running, check through button values and any that are on, read the tag that represents when that button needs to get reset. If the current time is >= than the time to reset and the button tag is 1, then turn button tag off.
understood. It seems like quite the complex solution for something seemingly so simple. not saying you are wrong by ANY stretch, i just would have never thought this would be how to acheive this.
Better than sleep
but probably still frowned upon, I sometimes use a Timer
to achieve a delay:
from threading import Timer
def doLater(self):
self.doneLater = True
Timer(0.5, doLater, [self]).start()
Thanks, Ryan. I did see this as well when looking up solutions.