Replicating a deprecated feature - Geting Serial Address of I/O Unit

Hello all,

I’m in the midst of upgrading an old Factory Floor 4.1 strategy to PAC Control Pro 9.6. I’m moving everything over from SNAP-BRS brains and a SNAP-LCSX-PLUS controller to newer SNAP-PAC-SB2 brains and a SNAP-PAC-S2 controller.

The old strategy relies very heavily on handling I/O units by their Serial Addresses (i.e., ‘Get address of I/O unit causing error’, etc.) and it looks like many of the newer commands in 9.6 rely on the I/O unit’s individual names (e.g., ‘Control Box 1’). We’ve been treating I/O unit serial addresses as table indices for things like error flags and such…it’s much harder to do any useful table manipulations with string names.

Is there any way to get and work with an I/O unit’s serial address in PAC-Control 9.6?
Again, all of our brains are SNAP-PAC-SB2s, so the only Ethernet involved is at the Controller - everything else is RS-485.

You could continue to use the integer addresses in your strategy and then use a pointer table to “lookup” the IO Unit for those commands that need the IO Unit as a parameter.

Initialize a pointer table when your strategy starts:

ptIOUnits[0] = &Serial_0;
ptIOUnits[1] = &Serial_1;
//etc.

and when you have an serial index in your strategy and you need the IO unit you would lookup the IO unit from the pointer table:

//pSerial_IOUnit is a pointer to a SB2
pSerial_IOUnit = ptIOUnits[SerialAddress];
//Now we can call a command that requires an IO unit
if (IsIoUnitReady(*pSerialIOUnit)) then
  //Do Something
endif
1 Like

Thanks again Philip, I’ll give that a try!

Sorry for the trouble, but I’m getting an error in my if statement:

if (IsIoUnitReady(*pSerialIOUnit)) then ... is throwing me
Invalid type for argument #0, but I have a pointer variable set up by the name “pSerialIOUnit” - I’m not sure what the mismatch is.

I figured it out, I think! My pointer variable was set to and int32 variable when it should have been a “digital multifunction I/O unit

It should be set to SNAP-PAC-SB2, if that is what you are using.

Also, I was only using the IsIOUnitReady command as an example - it is not something mandatory to call.

Thank you for the heads-up. I’m afraid this is my first foray into OptoScript. And I’m just using the IsIoUnitReady as something to start off with until I get my bearings - no worries!