Hello Guest it is January 28, 2020, 07:34:37 AM

Author Topic: Retrieve Scripts from Corrupted Mach 4 Profile  (Read 276 times)

0 Members and 1 Guest are viewing this topic.

Retrieve Scripts from Corrupted Mach 4 Profile
« on: November 16, 2019, 01:26:14 PM »
So I have managed to crash Mach 4 to the point where I cannot even load my profile or restore the backups from the loader screen. I have an offline backup that I will be able to restore, however I do not have the changes to the Screen Load script, PLC script, or any other button scripts saved since this last backup.

Is there a way to access the Screen Script master file from the C:/Mach4Hobby directory so I can attempt to recover some of these changes?

I looked but could only find the modules I created.

Thanks :(
Re: Retrieve Scripts from Corrupted Mach 4 Profile
« Reply #1 on: November 16, 2019, 06:28:49 PM »
Hi,
there may be a way but I haven't found it either. The teawks you have made to Mach4 in the screen load script, PLC etc are
stored in the screen set. If you have an individualized screen set, ie a copy of wx4.set, say, but with a distinct name then
when you update Mach4 to the latest build the incoming 'fresh' copy of wx4.set (which overwrites the existing copy)
will not overwrite your distinctly named copy.

Its for this reason that its ALWAYS recommended to have an individualized screen set.

My understanding is that the screen set (file with the .set extension) is in fact a database. If you know the correct means
you can access, edit, copy etc the individual components of the set. I don't know how and those who do sound as if such a thing
is so prosaic that embarrassment (read mis-placed pride) prevents me from asking.

Craig
My wife left with my best friend...
     and I miss him!
Re: Retrieve Scripts from Corrupted Mach 4 Profile
« Reply #2 on: November 16, 2019, 10:46:51 PM »
Well that sucks... Thanks for getting back with me.

I do have an individualized screenset for that reason, however any time I try to load that screenset, Mach crashes.

Fortunately my last backup was only 2 weeks ago, but I have been doing a lot of coding since then. Might take a few days to recover what I lost.

I need to make more frequent backups I guess. I have no experience with databases, but would definitely be interested in hearing if anyone does know how to do this.
Re: Retrieve Scripts from Corrupted Mach 4 Profile
« Reply #3 on: November 17, 2019, 10:45:50 AM »
What errors are you getting when you try to load mach4? If it’s an error with the screen set you may be able to directly edit the xml to resolve it
Re: Retrieve Scripts from Corrupted Mach 4 Profile
« Reply #4 on: November 18, 2019, 10:38:55 AM »
Have you tried opening the profile in the edit mode?  C:\Mach4Hobby\Mach4GUI.exe /pMyProfileName /e

HTH

RT
Re: Retrieve Scripts from Corrupted Mach 4 Profile
« Reply #5 on: November 18, 2019, 02:49:17 PM »
When I open the profile, it starts to load the screenset (green loading bar) and at some point goes to a blank grey screen and brings up the Mach 4 dialog box which asks if you want to save the crash report. If you click OK, the entire program closes.

I do not know what I would need to edit in the XML to fix it. I also did not know you could open directly in edit mode. Neat trick!

I think I have redone all my work at this point, however it might be worth my time to go back and make sure I got all my changes. If I can...
Re: Retrieve Scripts from Corrupted Mach 4 Profile
« Reply #6 on: December 13, 2019, 05:09:16 PM »
Hello,

I ran into a similar problem where the customers would just turn off the main power to the machine instead of properly shutting down Mach4. The fix I came up with is create an auto-save feature every 5 minutes paired with a Windows batch script to launch the Mach4 profile and overwrite Machine.ini and Screen.xml on start. The below example is only for Machine.ini but Screen.xml can be similarly saved.

Create a folder in the Mach4 installation directory...in this example the folder is called Source

Screen Load Script:

Code: [Select]
inst = mc.mcGetInstance()

-- import os
os = require "os"

saveStartTime = os.clock() -- start the time somewhere

PLC Script:

Code: [Select]
function autosave()
    -- every 5 minutes since os.clock() default counts in seconds
    if (os.clock() - saveStartTime) > 300 then
        saveStartTime = os.clock()

        -- might want to check here the Mach state and decide to save or not,
        -- might only want to save if machine is not running, for example
        mc.mcCntlSetLastError(inst, "Backing up Machine.ini")

        local profile = mc.mcProfileGetName(inst)
        local path = mc.mcCntlGetMachDir(inst)
    local mINIFilePath = path .. "\\Profiles\\" .. profile .. "\\Machine.ini"
    local backupfile = io.open(path .. "\\Source\\Machine.ini", "w+")

    for line in io.lines(mINIFilePath) do
            backupfile:write(line, "\n")
end
    end
end

autosave()

Create .bat file and either create a shortcut with icon or just save it to desktop your profileName and machDir will probably be different. This .bat file will be your Mach4 launcher:

Code: [Select]
set profileName=Mill
set machDir=C:\Mach4Industrial
set workingDir=%machDir%\Source

@echo F|xcopy /y "%workingDir%\Machine.ini" "%machDir%\Profiles\%profileName%\Machine.ini" 
start %machDir%\Mach4GUI.exe /p %profileName%
« Last Edit: December 13, 2019, 05:14:56 PM by compewter_numerical »
Re: Retrieve Scripts from Corrupted Mach 4 Profile
« Reply #7 on: December 13, 2019, 07:24:55 PM »
That's an awesome idea! I'll have to try that out when I get some time.

I'm diligent about shutting down the computer before powering off, however sometimes the computer never really shuts down, even after hours of waiting and this is when things get messed up.