Jump to content
OMRON Forums

OOP for Script ?


Recommended Posts

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?
 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted (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 by leandro.martins
Link to comment
Share on other sites

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.

 

 

 

 

 

Link to comment
Share on other sites

@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.


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...