Better Way to Stop My Charts?


#1

I am currently preferring OptoScript whenever possible as opposed to the GUI in PAC Control.

That said, is there a more elegant or fool-proof way to stop my charts during my initialization phase?

SetVariableFalse(bChartStatus);
repeat
StopChart(Test);
bChartStatus = not IsChartRunning(Test);
until (bChartStatus);

SetVariableFalse(bChartStatus);
repeat
StopChart(PID_Oil);
bChartStatus = not IsChartRunning(PID_Oil);
until (bChartStatus);

SetVariableFalse(bChartStatus);
repeat
StopChart(Bounds_Check);
bChartStatus = not IsChartRunning(Bounds_Check);
until (bChartStatus);

SetVariableFalse(bChartStatus);
repeat
StopChart(Data_Collection);
bChartStatus = not IsChartRunning(Data_Collection);
until (bChartStatus);

SetVariableFalse(bChartStatus);
repeat
StopChart(Safety);
bChartStatus = not IsChartRunning(Safety);
until (bChartStatus);


#2

You say initialization - if that means on powerup/restart - then none of the charts are running at startup, so this is unnecessary.

If you are trying to stop your charts to reset/restart your process, it may be better to have a variable with a stop request command for your charts so that your charts can check this and exit themselves. This way you can have your charts stop at a clean point and not midway through some task. If your charts have real long delays in them, this will probably not work well though.

You can also eliminate the bChartStatus variable:

while(IsChartRunning(Test))
  StopChart(Test);
  Delaymsec(50);
wend

If you want to keep going the way you are, I would command all the StopCharts first, then put in a delay of 100ms or so, and then check if they stopped, but efficiency is probably not that important in this code.

Also, be aware that if you are using locks (semaphores), that your code can end up deadlocked and never exit since charts will continue to run if a lock is set. If you don’t know what a lock is, then you are probably not using them.


#3

Thank you!

True on your first point, not necessary upon power-up / restart, but I am paving the way for (eventually) being able to jump back and re-init everything without power-up / restart taking place, sort of a re-init button in the GUI.

Good point on eliminating the status variable. I also realize I can do a similar thing below where I start them up.

Correct, I’m not using locks, but now I know they exist :slight_smile:


#4

Revisiting since I have a while before I can activate the machine that this chart belongs to:

for stopping I am now currently using:

while(IsChartRunning(Test))
StopChart(Test);
DelayMsec(50);
wend

And starting:

while(StartChart(Data_Collection))
wend

I have a ways to go as I slowly build in error checking and status of operations, so I know there’s plenty of improvements to be made. I’m anticipating one critique of the above is that the loops will run indefinitely if there’s an error or something’s jammed up, correct? If so, I’m currently okay with that until a better safeguard system is in place.

Continued critiques welcome!


#5

Is there a problem you are trying to solve where your charts don’t start? I’ve never had this happen - I just call

StartChart(Data_Collection);

and move on. My projects don’t have more charts than the controller can handle though, maybe yours does?

Anyways, I would throw a delay in the while loop if you need to keep it this way to improve performance on your other running charts. This one is wasting CPU time calling StartChart over and over.


#6

Thanks Philip, this is exactly why I’m digging into this stuff. I inherited a few designs that I am slowly working through while also nearing commission of my first machine w/ Opto code in it.

The time’s come for me to review what stuff I put into my new machine, that was based on the old ones, that might not be needed in a reasonable strategy.

I’m going to keep the StopChart stuff, but just switch to pure StartChart. The original example chart that someone provided to my co-worker to make our first few machines had all these checks to see if a chart was started. I forget if they were from Opto or not, and wasn’t around at the time.