Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way to find the index of the PLC a subroutine is being called from?
I ask because we've been using Sys.CdTimer as recommended in the manual and we realized that there could be race conditions if a subroutine using a given timer is being called from multiple PLCs. So ideally we would use a different timer based on which PLC we are being called from.
Here's a sample subroutine that worked for me. It should show you the concept at least.

open subprog SetTimer(TimerStart)
local idx;
idx = 0;
while (idx < 32)
if (Plc[idx].Active == 1)
Sys.CdTimer[idx] = TimerStart;
idx = 32;
else idx++;
This gives me the index of the first active PLC, not necessarily the one the code is being called from. I thought maybe Plc[i].Running would work, but for some reason it refuses to let me evaluate this. It says "Error : ( error #31) invalid parameter number in conditional : if (Plc[L0]. 4 == 1)" on build and download, or ILLEGAL CMD: Plc[6].4 on the command line. This seems like a bug.

What works for me is testing Plc[idx].Ldata.Address == Ldata.Address with the rest of the code the same.
Does your project have a Macro substitution like:

#define Running 4

I don't think it matters, as it would probably have the same issue as the Active element.
Ah, yes, the default NC UI machine state Running #define. When I get rid of that, yes, Running has the same issue. What I would need is a property that says the Plc is currently in a scan. But the Ldata.Address approach seems to work.

Forum Jump:

Users browsing this thread: 1 Guest(s)