Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: rrc1962 on May 26, 2016, 11:48:00 PM

Title: Writing to machine.ini
Post by: rrc1962 on May 26, 2016, 11:48:00 PM
I'm writing to the ini file for saving persistent DRO's and it works great.  I'm setting up some check boxes using toggle buttons and images and I'm trying to save the state of the button to the ini file on screen unload.  It doesn't work.  It should be saving the button state in the Preferences section, but it's not.  I inserted a message box and it is capturing the button state, just not writing it to the ini.  Code is below.  What am I doing wrong?

inst = mc.mcGetInstance()
val = scr.GetProperty('togCheck1', 'Button State')
mc.mcProfileWriteString(inst, "Preferences", "togCheck1", string.format (val))
Title: Re: Writing to machine.ini
Post by: DazTheGas on May 27, 2016, 03:13:01 AM
have you tried tostring(val)

Im away from a computer so cant check myself.

DazTheGas
Title: Re: Writing to machine.ini
Post by: dude1 on May 27, 2016, 05:05:49 AM
4.4 in the scripting manual
Title: Re: Writing to machine.ini
Post by: rrc1962 on May 27, 2016, 09:19:25 AM
I'm pretty much doing exactly what's in the scripting manual, but I changed the code to match the manual exactly and still nothing.  Is it possible that mc.mcProfileWriteString in the unload script is trying to write to the ini file while another process is writing to it?  Or will one wait fro the other to finish?
Title: Re: Writing to machine.ini
Post by: DazTheGas on May 27, 2016, 09:45:19 AM
You are not actually writing to the file, you are writing to internal registers, the last thing mach does before closing is to write these registers to the machine.ini

DazTheGas
Title: Re: Writing to machine.ini
Post by: rrc1962 on May 27, 2016, 09:50:38 AM
So what I did is I put this code in the button Down Script...

inst = mc.mcGetInstance()
mc.mcProfileWriteString(inst, "Registers", "togCheck1", "1")

And this code in the Button Up script....

inst = mc.mcGetInstance()
mc.mcProfileWriteString(inst, "Registers", "togCheck1", "0")

And this works.  Must some sort of conflict with doing this in the unload script.  Maybe Mach is writing the ini file before the unload script runs.

Title: Re: Writing to machine.ini
Post by: DazTheGas on May 27, 2016, 09:57:36 AM
Beet me to it but this works too.

Code: [Select]
local inst = mc.mcGetInstance()
val = scr.GetProperty('togCheck1', 'Button State')
mc.mcProfileWriteString(inst, "Preferences", "togCheck1", tostring(val))


DazTheGas
Title: Re: Writing to machine.ini
Post by: Chaoticone on May 27, 2016, 10:34:23 AM
Quote
Must some sort of conflict with doing this in the unload script.  Maybe Mach is writing the ini file before the unload script runs.

The button has been destroyed by the time the unload script runs so it is out of scope. You can't get the state if it isn't there. That is why I populate persistants in the first run of PLC script.
Title: Re: Writing to machine.ini
Post by: rrc1962 on May 27, 2016, 12:42:25 PM
So saving the state of a button can only be done in one of the buttons event scripts, correct?  There are plenty of outputs that will never be used.  I suppose I could tie the button to an output and get the state of the output on unload.  Are the outputs readable in an unload script?
Title: Re: Writing to machine.ini
Post by: DazTheGas on May 27, 2016, 01:34:15 PM
The state of your button is getting written to the machine.ini on clicking it with the code you had earlier, thats all you need.

DazTheGas
Title: Re: Writing to machine.ini
Post by: rrc1962 on May 27, 2016, 02:47:33 PM
I was thinking more along the lines of a way to do it all in the unload script.
Title: Re: Writing to machine.ini
Post by: DazTheGas on May 27, 2016, 03:17:04 PM
I really cant see the point when it can be done as you go with the button? but anyway you could use the registry plugin and save the states to registry values.

DazTheGas