ibisjoe Posted November 17, 2011 Share Posted November 17, 2011 are there variables available to tell me WHICH CPLC or Script PLC I am when I am executing? I see everyone just using constants but it would seem that the system KNOWS which CPLC or Script PLC is executing so can I just obtain that information (I have axis CPLCs coded in a subroutine and to check the 'bgcplc[n]' flags you need to have that information). - Joe Link to comment Share on other sites More sharing options...
Omron Forums Support Posted November 17, 2011 Share Posted November 17, 2011 The easiest way (as far as I know) is to just put a global flag inside your CPLC to go high when the CPLC is running. I.e. you can define a global in your "global definitions.pmh" file as, for example: global CPLC1_Running, CPLC2_Running; and then in your CPLC you can just set pshm->P[CPLC1_Running]=1; when the CPLC starts, and set it to zero right before the CPLC ends, and so on. Link to comment Share on other sites More sharing options...
ibisjoe Posted November 17, 2011 Author Share Posted November 17, 2011 no...I want to know the INDEX to use for manipulating the 'pshm->UserAlgo.BgCplc[iNDEX]' variables, etc. and similar for the Script PLCs. - Joe The easiest way (as far as I know) is to just put a global flag inside your CPLC to go high when the CPLC is running. I.e. you can define a global in your "global definitions.pmh" file as, for example: global CPLC1_Running, CPLC2_Running; and then in your CPLC you can just set pshm->P[CPLC1_Running]=1; when the CPLC starts, and set it to zero right before the CPLC ends, and so on. Link to comment Share on other sites More sharing options...
daves Posted November 18, 2011 Share Posted November 18, 2011 I would be interested to know if there is a simple system variable for this too. Currently I use the following define at the top of the file which isn't too bad #define THIS_PLCC 3 and then use SetPmacVar((char *)"UserAlgo.BgCplc[THIS_PLCC]", 0); to self-disable. Also I think you should know I had various crashes after manipulating pshm->UserAlgo.BgCplc[iNDEX] in C code (reading is OK) and was told to use the above syntax (see post http://forums.deltatau.com/showthread.php?tid=604&pid=2128&mode=threaded for a good discussion on this and other CPLC flow control issues. If you really need a generic method, a messy option for CPLCs (I guess not PLCs) may be to parse the __FILE__ macro which gives "bdccplc03.c" etc on my system, assuming you haven't renamed the file...? Dave Link to comment Share on other sites More sharing options...
Omron Forums Support Posted November 18, 2011 Share Posted November 18, 2011 The index is just the PLC or CPLC number. e.g. bgcplc01 in your IDE's Solution Manager corresponds to pshm->UserAlgo.BgCplc[1] So, you could just put at the top of your bgcplc01.c (for example) file: #define THIS_CPLC 1 as the previous poster suggested. Then, to deactivate your CPLC, in your code below, you could do something like this: char buffer[64]=""; sprintf(buffer,"UserAlgo.BgCplc[%d]",THIS_CPLC); SetPmacVar(buffer,0); Link to comment Share on other sites More sharing options...
daves Posted November 21, 2011 Share Posted November 21, 2011 Oops, my Friday brain wrote that second line of code which doesn't actually do anything. In reality I have a global utilities h file with amongst other things void DoPLCC(int PLCC, int Value) { char buffer[25]; sprintf(buffer, "UserAlgo.BgCplc[%d]", PLCC); SetPmacVar(buffer, Value); } void DisablePLCC(int PLCC) {DoPLCC(PLCC, 0);} void EnablePLCC(int PLCC) {DoPLCC(PLCC, 1);} So I can just call DisablePLCC(THISPLCC); Link to comment Share on other sites More sharing options...
Recommended Posts