Hello Guest it is March 28, 2024, 04:14:02 PM

Author Topic: What does .PlcCycle() Do?  (Read 740 times)

0 Members and 1 Guest are viewing this topic.

What does .PlcCycle() Do?
« on: February 20, 2021, 07:44:02 PM »
I have some code for controlling a vfd. I am wondering what .PlcCycle() does at the end of the primary function. This is the first row of the function:

function VFD_Spindle_Controller.PlcCycle()

The code is to be placed in the PMC folder. Does the .PlcCycle() added to the end cause the function to be called on each cycle of the PLC using the specified PLC Interval.
Re: What does .PlcCycle() Do?
« Reply #1 on: February 23, 2021, 07:15:59 PM »
Are you looking at some code that came from the PMC? If so I suspect that is the function that is called to update the PLC scan for that pmc.
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: What does .PlcCycle() Do?
« Reply #2 on: February 23, 2021, 08:01:10 PM »
Yes, I am using code that stared with the PMC. This is a function in the code that I assume is related, but not named PlcCyle.

function VFD_Spindle_Controller.GetCycleInterval()
    return 10
end

Not sure what that function does. I don't see it called anywhere in the code.

When I enable this code as a PMC object for the screen, there is a refresh interval that can be specified. So I ma trying to figure out what controls the PLC cycle. The field in the PMC object screen, the .GetCycleInterval appended to the function above or the .PlcCycle() at the end of the main function I wrote/modified.

The good news is that I have been successful with controlling my spindle via ModBus. However, I want to fully understand what the code does.

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: What does .PlcCycle() Do?
« Reply #3 on: March 10, 2021, 10:31:00 PM »
The LUA code that the PMC generates is not meant to be used outside of the context of the PMC functionality.  It has special hooks that the Mach4GUI uses and nothing else will ever call them.  Taking a PMC generated LUA file and trying to modify it is guaranteed to end in failure. 

It is much better to start with the original .pmc file and work all of the logic in the PMC editor.  The PMC editor just takes the ladder logic and generates LUA code to to work with the screen set.  The .Plc_Cycle() is what the screen set calls to run the logic in that generated file.  In hindsight, I probably should have compiled the generated LUA code into bytecode.  But I left it as plain text LUA code because it was easier to debug. 

Steve
Re: What does .PlcCycle() Do?
« Reply #4 on: March 10, 2021, 11:32:55 PM »
Thank you for the response. I recently converted from Mach3 to Mach4. I needed to get my spindle up and running which I controlled via modBus. I found some very helpful code that a person had written using PMC along with some custom code. That was enough to get me started but I never like implementing something that has pieces I do not understand. I have since converted everything to be Lua in the ScreenLoad and PLC areas and stopped using the PMC code. I still have a lot to learn, but am making very good progress. Always thankful for everyone's help on the forum!