DaveBarnett Posted May 13 Share Posted May 13 Dear Forum, I'd like to solve the following issue: I have a small state machine and sequence logic that I need to operate on a given machine axis. There are 5 identical axes on which I need the code to run. Currently, I have 5 separate script PLC's running the exact some logic, but with some different indices. Cutting & Pasting to create the 5 PLC's is awkward and error prone during code development. What I'd like, is to be able to instantiate each plc from a template, like is done with OOP programming with classes/objects. Then, it occurred to me that a motion program can be instantiated and run in any number of coordinate systems, each completely independent of the others. I tested it out, and used the LDATA.Coord construct inside the program to let each instance "know" where it's running and figure out indices based on that. The motion programs run no motion, just logic and I/O, but it seems to work fine. My question is, is this technique inadvisable for any reason? Or is there a better method? Quote Link to comment Share on other sites More sharing options...
leandro.martins Posted May 13 Share Posted May 13 (edited) You might be able to create a subprogram for that. Something like: OPEN SUBPROG IO_Logic(index1, index2) // Add Logic here ... CLOSE And call that from a single plc using CALL IO_Logic(0,1) CALL IO_Logic(2,3) However, I don't see any harm in using the motion program, but I could be wrong. Edited May 13 by leandro.martins Quote Link to comment Share on other sites More sharing options...
DaveBarnett Posted May 13 Author Share Posted May 13 @leandro.martins Thanks for the reply. But I don't think this will produce the desired result (two concurrent threads...) The first call to IO_Logic(0,1) will block until finished... THEN the plc calls IO_Logic(2,3) ... no ?? Quote Link to comment Share on other sites More sharing options...
MoMo Posted May 14 Share Posted May 14 Because the scripting language of PMAC is not an object-oriented language, it will be more difficult to program in an object-oriented way. Regarding blocking issues, Switch case can be used in scripting languages to replace the delay method of Call Timer, including using Sys.CdTimer[i]. Instantiation can only be implemented using base address + offset address addressing for the variables in it. Or you can consider using CPLC, there are many explanations and instructions on how to program C language in an object-oriented way. Even in a single thread, multi-threaded operations are implemented. All in all, other methods are more complex than using multiple PLCs. Of course, if you are very willing to pursue the elegance of programming, you can consider the above methods. Quote Link to comment Share on other sites More sharing options...
leandro.martins Posted May 14 Share Posted May 14 @DaveBarnett You're right, It wasn't clear to me that the PLCs have to be running in parallel. My suggestion was thinking in prevent the "cut and paste" process. The subprograms can be used for that, and in your case, could be used in multiple PLCs to run the same logic in parallel, having a single source of truth, which could be useful for maintaining the code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.