Hello Guest it is March 28, 2024, 02:54:49 PM

Author Topic: Writing to machine.ini  (Read 3662 times)

0 Members and 1 Guest are viewing this topic.

Writing to machine.ini
« 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))

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Writing to machine.ini
« Reply #1 on: May 27, 2016, 03:13:01 AM »
have you tried tostring(val)

Im away from a computer so cant check myself.

DazTheGas
New For 2022 - Instagram: dazthegas

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Writing to machine.ini
« Reply #2 on: May 27, 2016, 05:05:49 AM »
4.4 in the scripting manual
Re: Writing to machine.ini
« Reply #3 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?

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Writing to machine.ini
« Reply #4 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
New For 2022 - Instagram: dazthegas
Re: Writing to machine.ini
« Reply #5 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.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Writing to machine.ini
« Reply #6 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
New For 2022 - Instagram: dazthegas

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Writing to machine.ini
« Reply #7 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.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Writing to machine.ini
« Reply #8 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?

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Writing to machine.ini
« Reply #9 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
New For 2022 - Instagram: dazthegas