Jump to content
OMRON Forums

Is there a way to find the index of the PLC a subroutine is being called from?


Recommended Posts

Posted
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.
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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)

{

Ldata.GoBack=32;

if (Plc[idx].Active == 1)

{

Sys.CdTimer[idx] = TimerStart;

idx = 32;

}

else idx++;

}

close

Posted

This gives me the index of the first active PLC, not necessarily the one the code is being called from. I thought maybe Plc.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.

Posted

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.

Posted
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.
Guest
This topic is now closed to further replies.

×
×
  • Create New...