Addressing I/O Points in a loop / Naming conventions


#1

Hello - I am trying to find a way to address many digital I/O points without writing Optoscript for each point. As an example, I have 40 digital output ports: Output_0 thru Output_39 (as named in PAC Control). Is there a way I can use a For Loop to address all of them? (instead of writing 40 separate lines of code)

This would probably involve changing the way I name these outputs…

Perhaps there is a way to use a loop to write to a table then transfer the table to the outputs?


#2

use pointer table


#3

Hi Maddosc,

As leeveney succinctly said (perhaps a little too succinctly?) pointer tables are the way to go.
For an example, check out the PAC Control Users Guide (From within PAC Control, click on Help -> Manuals -> Users Guide).
Its Doc #1700.
Page’s 86 to 89 almost exactly describe what you mention.
There is even some Opto Script example code there to get you started…
If you are looking for more examples, check out the Code Samples and Tips section of the forum. Some of the summer of code contest entries used pointer tables.

If you have any questions, Opto_Mary will be delighted to help you out (or Nick, or a bunch of other forum lurkers)… Im not much of a pointer guy myself, but they are powerful…

Cheers,

Ben.


#4

I’m by no means an expert at it, but I’ve been considering a similar need and have been playing with using the[B] SetIoUnitFromMomo[/B] command. If all of your digital output points are on the same rack, and are in standard 4 channel modules (not high density), the command should usable.

The command uses a “must-on mask” and a “must-off mask”.

For 40 points, you would use an i64 for your masks. For those of you who, like me, don’t naturally think in binary or hex, I’ve attached a simple spreadsheet to figure out what the masks should be to achieve the desired behavior on each point.


#5

Wow, nice, thanks for the spreadsheet, sensij!

To answer the specific original question, there’s this MOMO command sensij mentioned, and also under the “I/O Unit Commands,” we have: [I]Move Numeric Table to I/O Unit[/I].

Both of these commands assume all the points are on the same I/O unit.

I would agree w/the Pointer Table solution, as Ben figured I would. The Pointer Table method does NOT assume all the points are on the same I/O Unit, nor does it get messed up if you were to move points around (to a different spot on the rack, or do a different rack completely). Maddosc also mentioned changing the point names, which is a good idea since they could be much more descriptive/helpful than Output_0 etc.

I’d also like to second the plug for the user manual section Ben mentioned which breaks the Pointer Table technique nicely:

[B]BEFORE:[/B]


[B]AFTER in Action/Condition Blocks:[/B]


[B]AFTER in OptoScript:[/B]


Good question & suggestions, keep 'em coming!

-OptoMary


#6

FYI - here’s a kinda related discussion about referencing I/O Points [click here].

One technique which is mentioned in that discussion which would work if you’re going to:

  1. Keep your "standard" naming convention (Output_0, Output_1 etc.)
  2. Never, ever change those names

It uses the command [I]GetPointerFromName [/I](vs. setting up a Pointer Table), so you could loop through building your point name…

sPointName = "Output" + sStringPointNumber;
GetPointerFromName(sPointName, pMotor);

Not something I’d recommend for this case since I don’t think you want to be stuck with the limitations I mentioned above, but sometimes it’s a handy trick, especially if you’re not a Pointer Table guy. :wink:

-OptoMary


#7

as i got to the 3rd post, i was thinking exactly what mary just posted above. i use this in a complex alarms chart and it works great. however as mentioned, never ever change the names. it will break the whole process.