Hello Guest it is March 28, 2024, 04:48:11 AM

Author Topic: Saving the selected spindle speed range  (Read 9475 times)

0 Members and 1 Guest are viewing this topic.

Re: Saving the selected spindle speed range
« Reply #10 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!

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Saving the selected spindle speed range
« Reply #11 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.
New For 2022 - Instagram: dazthegas

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Saving the selected spindle speed range
« Reply #12 on: August 14, 2015, 06:51:55 AM »
your getting good at lua daz inst, val is the key
Re: Saving the selected spindle speed range
« Reply #13 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?

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Saving the selected spindle speed range
« Reply #14 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
New For 2022 - Instagram: dazthegas
Re: Saving the selected spindle speed range
« Reply #15 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)