Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: awander on August 09, 2015, 03:24:22 PM

Title: Saving the selected spindle speed range
Post 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?
Title: Re: Saving the selected spindle speed range
Post by: DazTheGas on August 10, 2015, 06:24:34 PM
have a look at using script to save the value of the dro to your profile, and then load it on startup.

DazTheGas
Title: Re: Saving the selected spindle speed range
Post by: dude1 on August 10, 2015, 06:30:21 PM
write to .ini its in the scripting manual in the manual section of mach web site
Title: Re: Saving the selected spindle speed range
Post by: DazTheGas on August 10, 2015, 06:41:27 PM
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
Title: Re: Saving the selected spindle speed range
Post by: awander on August 13, 2015, 11:08:57 AM
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?
Title: Re: Saving the selected spindle speed range
Post by: ger21 on August 13, 2015, 11:37:32 AM
You can add any settings to the .ini file that you want, and use any format you want.
Title: Re: Saving the selected spindle speed range
Post by: awander on August 13, 2015, 11:55:30 AM
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.
Title: Re: Saving the selected spindle speed range
Post by: DazTheGas on August 13, 2015, 12:55:48 PM
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
Title: Re: Saving the selected spindle speed range
Post by: awander on August 13, 2015, 02:03:46 PM
The DRO is set to DRO Code "Spindle Range"

thanks,
Title: Re: Saving the selected spindle speed range
Post by: dude1 on August 13, 2015, 06:01:08 PM
have a look at this
Title: Re: Saving the selected spindle speed range
Post by: awander on August 13, 2015, 11:11:59 PM
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!
Title: Re: Saving the selected spindle speed range
Post by: DazTheGas on August 14, 2015, 06:42:39 AM
This should get you on the right track, DO NOT edit the ini file, using the profile will automatically create what it needs.

Code: [Select]
--Screen Load Script
local inst = mc.mcGetInstance()  -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)

Code: [Select]
--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.
Title: Re: Saving the selected spindle speed range
Post by: dude1 on August 14, 2015, 06:51:55 AM
your getting good at lua daz inst, val is the key
Title: Re: Saving the selected spindle speed range
Post by: awander on August 14, 2015, 04:08:25 PM
This should get you on the right track, DO NOT edit the ini file, using the profile will automatically create what it needs.

Code: [Select]
--Screen Load Script
local inst = mc.mcGetInstance()  -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)

Code: [Select]
--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?
Title: Re: Saving the selected spindle speed range
Post by: DazTheGas on August 14, 2015, 05:37:02 PM
OOps didnt spot that. posted the screen load twice

Screen Unload script should be

Code: [Select]
--local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcSpindleGetCurrentRange(inst)
mc.mcProfileWriteInt(inst, 'SpindleDefaultRange','Range',val)

DazTheGas
Title: Re: Saving the selected spindle speed range
Post by: gudre on March 24, 2016, 06:37:24 AM
Hello, this code not working in my machine. What can be a problem ?
Code: [Select]
--Screen Load Script
local inst = mc.mcGetInstance()  -- not needed if already declared
local val = mc.mcProfileGetInt(inst, 'SpindleDefaultRange','Range',0)
mc.mcSpindleSetRange(inst, val)
Code: [Select]
--Screen Unload Script
local inst = mc.mcGetInstance() -- not needed if already declared
local val = mc.mcSpindleGetCurrentRange(inst)
mc.mcProfileWriteInt(inst, 'SpindleDefaultRange','Range',val)