Hello Guest it is May 15, 2021, 07:24:33 PM

Author Topic: Saving Mach 4 Register Values  (Read 249 times)

0 Members and 1 Guest are viewing this topic.

Saving Mach 4 Register Values
« on: December 19, 2020, 10:36:44 AM »
I've modified my Mach 4 lua scripts a bit and have managed to create a few ways to crash the program. This is no big thing, as I pretty much know what not to do to cause a crash. Anyway, through these unexpected shutdowns, I've discovered that the register values, tool height settings, and workspace coordinates, etc, are not saved except during an orderly shutdown. This means that if the Mach 4 crashes, all the changes I've made during that session are lost.

Is there a way to force the application to save all settings, registers, tool heights, etc? Something I could execute via a customized button?
Re: Saving Mach 4 Register Values
« Reply #1 on: December 19, 2020, 12:03:40 PM »
There is probably a better way but a button script:
Not sure if registers are in the profile but any other values you want saved and reread you could create a profile entry for each.

Re: Saving Mach 4 Register Values
« Reply #2 on: December 23, 2020, 02:05:14 AM »
You can extract the values from the pound variables and then do some lua coding to save/load work coordinates and tool heights. I don't know the tool height pound vars tho but the g54 is 5221-5226. G55 is 5241-5246 and through G59 follows that +20 #var increment (if that makes sense). Then you can save and load using a button and screen load function like this:

Code: [Select]
-- button script
function BackupG54()
    local backup_path = "C:\\Mach4Industrial\\backups\\work_coordinates.ini"
    local file = io.open(backup_path, "w")

    for i = 0, 6, 1 do
        file:write(tostring(mc.mcCntlGetPoundVar(inst, 5221 + i)), "\n")


-- screen load script
function lines_from(file)
    if not file_exists(file) then return {} end
    lines = {}
    for line in io.lines(file) do
        lines[#lines + 1] = line
    return lines

function LoadG54()
    local backup_path = "C:\\Mach4Industrial\\backups\\work_coordinates.ini"
    local file = io.open(backup_path, "rb")

    local lines = lines_from(file)

    for k,v in pairs(lines) do
        mc.mcCntlSetPoundVar(inst, 5220 + tonumber(k), tonumber(v))


for gRegs/iRegs, modbus...etc just copy current Machine.ini into another directory and overwrite it with a custom batch script launcher.

1. in button script copy current machine.ini into another directory.

Code: [Select]
-- button script
-- use popen in lua to copy the current machine.ini into another location:

local profile_name = "ProfileName"
local machine_ini_path = "C:\\Mach4Industrial\\Profiles\\" .. profile_name .. "\\Machine.ini"
local backup_path = "C:\\Mach4Industrial\\backups\\" 
io.popen('copy ' .. machine_ini_path .. ' ' .. backup_path)

2. create a batch script to launch Mach4 that moves the machine.ini you copied with the button script and overwrites the machine.ini in the profile directory before launching Mach4.
« Last Edit: December 23, 2020, 02:16:18 AM by compewter_numerical »