Machsupport Forum
Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: awander on August 09, 2015, 03:24:22 PM
-
I added a DRO to the standard screenset that lets me select the Spindle Range, but when I close Mach4 and re-open it, the range goes back to zero.
How can i have Mach4 remember this setting?
-
have a look at using script to save the value of the dro to your profile, and then load it on startup.
DazTheGas
-
write to .ini its in the scripting manual in the manual section of mach web site
-
Correct, thats what writing to the profile does ;-) by doing it that way it auto writes in the ini and auto loads it on startup.
DazTheGas
-
have a look at using script to save the value of the dro to your profile, and then load it on startup.
DazTheGas
I looked thru the .ini file and I don;t see a setting that is in there for the selected spindle range.
How do I know the format that this entry should have?
-
You can add any settings to the .ini file that you want, and use any format you want.
-
OK, what is the format to write this stuff to the ini? Is this documented somewhere?
And this means there is no "standard" .ini setting for spindle range, right? So I will have to use a script to take care of saving and restoring.
-
give me a little more explanation on the dro.
what sets its value or what value it sets etc and i will write one for you as an example to you on track.
DazTheGas
-
The DRO is set to DRO Code "Spindle Range"
thanks,
-
have a look at this
-
I figured it out. I am saving my Spindle rannge and alsso teh commandded speed on screen unload, and restoring them on screen load.
I put this in my unload script:
local inst = mc.mcGetInstance()
local cRange = mc.mcSpindleGetCurrentRange(inst)
--What Pulley range is currently active 0-19
cRange = tostring(cRange)
mc.mcProfileWriteString(inst, "SpindleStuff", "CurrentRange", cRange)
local inst = mc.mcGetInstance()
local cSpeed = mc.mcSpindleGetCommandRPM(inst)
--What Spindle Speed is currently commanded
cSpeed = tostring(cSpeed)
mc.mcProfileWriteString(inst, "SpindleStuff", "CurrentSpeed", cSpeed)
and I put this in my Load script:
local inst = mc.mcGetInstance()
local cRange = mc.mcProfileGetString(inst, "SpindleStuff", "CurrentRange", "0")
--Get saved Range Value from Profile (0-19)
cRange = (tonumber(cRange))
mc.mcSpindleSetRange(inst, cRange)
--Set Current Range to saved value
local inst = mc.mcGetInstance()
local cSpeed = mc.mcProfileGetString(inst, "SpindleStuff", "CurrentSpeed", "0")
--Get saved Speed Value from Profile
cSpeed = (tonumber(cSpeed))
mc.mcSpindleSetCommandRPM(inst, cSpeed)
--Set Current Range to saved value
and it works!
Not sure if this is the best way to do it, but...it works!
-
This should get you on the right track, DO NOT edit the ini file, using the profile will automatically create what it needs.
--Screen Load Script
local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)
--Screen Unload Script
local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)
All working on my machine.
-
your getting good at lua daz inst, val is the key
-
This should get you on the right track, DO NOT edit the ini file, using the profile will automatically create what it needs.
--Screen Load Script
local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)
--Screen Unload Script
local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)
All working on my machine.
Hi, thanks, but I don't understand how this would work.
It appears that the unload script and the load script are doing the same thing, which is getting the value from the ini file and writing it to MAch4.. One of them(the unload script) needs to do the opposite, that is, take the value from Mach4 and store it in the ini file.
No?
-
OOps didnt spot that. posted the screen load twice
Screen Unload script should be
--local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcSpindleGetCurrentRange(inst)
mc.mcProfileWriteInt(inst, 'SpindleDefaultRange','Range',val)
DazTheGas
-
Hello, this code not working in my machine. What can be a problem ?
--Screen Load Script
local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)
--Screen Unload Script
local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcSpindleGetCurrentRange(inst)
mc.mcProfileWriteInt(inst, 'SpindleDefaultRange','Range',val)