maxvoxel8 Posted May 16, 2019 Posted May 16, 2019 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.
curtwilson Posted May 16, 2019 Posted May 16, 2019 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
maxvoxel8 Posted May 17, 2019 Author Posted May 17, 2019 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.
curtwilson Posted May 18, 2019 Posted May 18, 2019 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.
maxvoxel8 Posted May 20, 2019 Author Posted May 20, 2019 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.
Recommended Posts