Hello Guest it is April 19, 2024, 02:29:31 PM

Author Topic: Changing the state of a toggle switch at startup.  (Read 798 times)

0 Members and 1 Guest are viewing this topic.

Offline AXYZ_WI

*
  •  4 4
  • TLAR
    • View Profile
Changing the state of a toggle switch at startup.
« on: June 29, 2020, 11:35:24 PM »
I have a toggle switch set up to to change the value of a register when the switch is up its a 1 and when the switch is down its a 0, that value is written to the profile ini.
Heres the button code, down sets it to 0 and up, a 1.

Code: [Select]
local inst = mc.mcGetInstance() -- Get the instance of Mach4
local setter = 0
mc.mcProfileWriteString(inst, "Tool Setter", "Probe", string.format (setter))

The register value is used in my M6 to either use the tool setter or a movable touch plate.
 
What I would like to do is to read that register value and change the state of the toggle switch based on that value during Mach4 startup, if its a 1 the switch state is up and visa versa.

I tried putting the following code in the screen load script

Code: [Select]
local setter = mc.mcProfileGetString(inst, "Tool Setter", "Probe", "setter")
setter = tonumber(setter)
if setter == 1 then
scr.SetProperty('tog_setter','Botton State', 'Up')
else
scr.SetProperty('tog_setter','Botton State', 'Down')
end

But that failed to change the state of the button. As it stands there is a possibility that the feedback from the toggle switch and the actual value of the register are not the same and the machine can act differently then what the operator expects. Any insight would be appreciated.

Thanks
Josh
Re: Changing the state of a toggle switch at startup.
« Reply #1 on: July 01, 2020, 04:53:24 AM »
Hi, there are a couple of errors: Button is spelled wrong and '0' and '1' should be used rather than 'Up' and 'Down'

Try this

Code: [Select]
local setter = mc.mcProfileGetString(inst, "Tool Setter", "Probe", "setter")
setter = tonumber(setter)
if setter == 1 then
scr.SetProperty('tog_setter','Button State', '0') --up
else
scr.SetProperty('tog_setter','Button State', '1') --down
end

Offline AXYZ_WI

*
  •  4 4
  • TLAR
    • View Profile
Re: Changing the state of a toggle switch at startup.
« Reply #2 on: July 01, 2020, 07:47:31 AM »
Thank you So much!

I figured out the up down 0 1 thing after reading through the lua for dummies document I found on the forum but still no luck.

My button spelling error was the issue. Thanks for your help. I've spent hours trying to figure this out. I'm sure I'll never misspell button again in my life!

Josh
Re: Changing the state of a toggle switch at startup.
« Reply #3 on: July 01, 2020, 08:02:07 AM »
You can always check the return values when you are having problems, in this case it would have been -3 which is 'SERROR_PROPERTY_NOT_FOUND' which gives a clue as to what is wrong