Importing Charts

Is it possible to import a chart into a strategy using a wildcard to change (and create) variable names as the chart is imported?

I have a chart that can’t be run as a subroutine (includes subroutines, PID’s, fairly large) and I need to duplicate as many as 20 times. I have written the chart excluding any I/O points. All variables unique to this chart have a common part of the name.

All of my projects have this type of setup, so using a wildcard during import or something of that sort would save me a lot of time.

Hi dgerdts,

Welcome to the forums! A few thoughts come to mind on this one.

But first I’d like to take a step back and ask about that “duplicate as many as 20 times” comment.

This raises a red flag for me because of the “don’t copy & paste” concept we cover in the second half of this video about building maintainable code:


(The concepts in this video apply even if you don’t have any OptoScript.)

Consider this: suppose you build these 20 nearly identical charts, then down the road you find a bug or want to make a small change.
You’d have to do it 20 times.

Also, perhaps today you’re doing it 20 times but in the future you want to expand to 40 or 100! You could hit the limit of how many simultaneous charts you can have running on the particular PAC you’re using.

Do all these need to run at once? Or can you loop through each one in turn? How many variables are unique to each “chart” currently? What types of variables are they? (Ints, floats, float tables?)

Here’s an example of what I’m getting at. Say now you have:

Chart 1 calls a subroutine with Variable1
Chart 2 calls the same sub with Variable2
Chart 3 calls the same sub with Variable3

Instead just have:

Table of Variables loaded w/the values in Variable1, Variable2, & Variable3

ChartA loops and calls the sub passing: table element 0, table element 1, table element 2 in turn.

Does that make sense? Most likely you’d need several tables (one for each of the variables you currently re-name in each chart). You might even need a pointer table. But ultimately, the little extra setup could save you a lot of effort down the road.

Also, by decreasing the number of charts you’re running at once, you could improve your overall system performance/throughput, as we discuss in this form 1776.

Hope that helps.

Thanks, OptoMary,

Ultimately I know what you say is true, but from here it looks like a daunting task. I currently have 40 (will probably get to 60 by the time I’m finished) variables of various types and will need to use pointers for my I/O (something I haven’t used for 15 years since class). I have 3 PID’s per chart, all using Host connections. I am manipulating the PID’s depending on conditions in the chart and cascading two of them for best control. I will have to handle these outside of the subroutine, correct?

The strategy starts out with 20 nearly identical charts (and 10 of another and 5 of another) but when I get to the job-site, I inevitably have to change a few of those to something not identical. So with the subroutines, it helps in debugging but makes it more difficult to “customize” individual zones.

Timing isn’t really an issue. I’m dealing mostly with refrigeration zones that don’t react quickly. One second “scan rates” would be adequate for all of my logic. Sequencing the subroutines would not be a problem for that reason.

The basic issue here is me trying to take 15 years of PLC and Paragon logic and apply it in OPTO style.

Thanks again, dgerdts

Not so daunting! Yes, PID stuff would have to be outside the sub, but sounds like you have the right idea of putting as much stuff in the sub as possible. If you’d like to send me your strategy or a couple of charts I could take a quick peek and perhaps take a piece of it and share what a before/after might look like?