Hello Guest it is May 31, 2026, 04:27:10 AM

Author Topic: PLC Scripts  (Read 2844 times)

0 Members and 1 Guest are viewing this topic.

PLC Scripts
« on: March 07, 2026, 04:45:09 PM »
I'm wanting to add a PLC script that calls a module for Mach status lighting. In Mach 4, that seemed pretty straight forward. I'm not a seasoned coder, so there is little that is intuitive about LUA coding for me.  In Mach Pro, the "new" PLC Script just has the following:


Code: [Select]
if m.CommonPLCScript ~= nil then
m.CommonPLCScript()
end

I want to insert this code into the PLC Script, so that it calls the towerscript.lua module.

Code: [Select]
if towerscript == nil then
towerscript = require "towerscript" -- Load's towerscript.lua from a path. probably C:\Mach4\Modules
end
towerscript.PLCScript()

I tried just pasting it at the end of the previous lines, but that did not seem to work. I've found little information in the documentation that would guide me in the right direction.


Re: PLC Scripts
« Reply #1 on: March 07, 2026, 05:02:03 PM »
Okay, might just be user error. I did not restart Mach Pro after updating the script. On restarting, it does seem to be working as expected.
Re: PLC Scripts
« Reply #2 on: March 09, 2026, 09:48:41 AM »
In MachPro there's actually already a built in method for handling Light Stacks inside of Configure → Control → Settings. Alternatively you can also handle it through the GMS plugin as well.
If you prefer the lua code route, under the Service → Maintenance tabs, we have a Compile Scripts button that should apply your custom programming and most changes, so you no longer have to power cycle Mach.

In an ideal sense, we prefer to not have custom programming on the newer software as it becomes a nightmare to support. We are working on documentation on how to handle all these things.
Thanks,

Paul
Re: PLC Scripts
« Reply #3 on: March 09, 2026, 09:56:11 AM »
Thanks Paul - looking forward to the documentation. As I'm not a coder, but can figure out mostly how to add custom stuff that others have built and get it to work. Since Mach Pro has changed so much, its a challenge sometimes to figure out where to get things done.  While exploring further, I did note the Compile Scripts button on the Service tab. I think it is mostly getting used to the changes and knowing how things are done in Pro.

I think some clear examples of what might be considered typical of what someone might want to do would be helpful. In other words, beginning to end.

BTW, I am on the Beta, so happy to review the doc in progress.
Re: PLC Scripts
« Reply #4 on: March 09, 2026, 01:24:08 PM »
Edit Screen -> PLC script edit.
Add that snippet to the PLC script. Exit editor and then exit from Edit screen. It will ask if you want to save.
Say yes and your done. there should not be any reason to restart Mach at that point.

As for the config->control->settings light stack, it is NOT similar to what you are putting in place. It is meant for a tower Light that has 3 positions. And you have no control really on those.
the PLC.Towerscript() has alot more to say about machine status and is programmable to change what you'd like to see. I'm the one who wrote the towerscript and looked at various methods to implement
what I wanted, which did include the settings light stack.

Colten
Re: PLC Scripts
« Reply #5 on: March 09, 2026, 01:36:13 PM »
In an ideal sense, we prefer to not have custom programming on the newer software as it becomes a nightmare to support. We are working on documentation on how to handle all these things.


thank you for verifying what I'm suspected from the start of the beta program. Mach it seems is locking down features from consumer use. When Mach removes the Edit->screen function, I'll be saying goodbye and thanks for all the fish. I understand the support view point. but locking it down so the consumer ie me and many others is rather short sighted. Fixing bugs in the program that have been IN mach for years now would definitely be worthwhile. But then I'll assume it will never be backported to Mach4. That sucks. We all paid good money for a program which was supposed to be and usually is a massive upgrade from Mach3.
Re: PLC Scripts
« Reply #6 on: March 09, 2026, 10:07:54 PM »
I recognized who you were  :)  - I was able to add it and get it working fine in Mach Pro. But it would be helpful to understand how stuff like this will be possible in the future without the same level of access that was available in Mach 4, despite it's shortcomings.
Re: PLC Scripts
« Reply #7 on: March 10, 2026, 09:50:25 AM »
Hi,

The planned programming method for MachPro is going to be vastly different from what you have experienced on Mach4. We are continuously working on documentation for both the operator side and the programming side as there are hundreds of more API calls that can be made now.
Thanks,

Paul
Re: PLC Scripts
« Reply #8 on: March 10, 2026, 12:10:31 PM »
I do have to admit, that simple things like adding a button that toggles an output is far easier than having to write a script. Not being a coder, I'm able to get these simple things done far easier than before.

Using User Commands under the Screen Configuration option on the Service tab has been so far very easy to use. Once I've set up the output, then it is pretty straight forward to add a new command, select the command and the options, and it is done. No script.

However, for things like the script in this post, it would not have been possible with my skills to accomplish.
Re: PLC Scripts
« Reply #9 on: March 10, 2026, 02:44:12 PM »
Yeah, Ideally we are trying to remove some of this logic from the screens themselves. The GMS is amatively a little clucky - We are looking to improve it - but can be a powerful tool that could replace a lot of PMC and PLC logic that users have built into the GUI. Is it all powerful? no. Will it get most tasks done well or well enough? yes. When it comes to custom programming, we have a user GUI module and a user M code module for all custom logic or code. This is for modifying existing features or adding new features to our screens. We will have proper documentation on this in the -hopefully- near future.
Thanks,

Paul