Hello Guest it is March 29, 2024, 04:24:54 AM

Author Topic: Set propperties from button within a function  (Read 1549 times)

0 Members and 1 Guest are viewing this topic.

Offline DAAD

*
  •  103 103
    • View Profile
Set propperties from button within a function
« on: April 13, 2020, 10:54:33 AM »
When running my dual head m6 macro i want the toggle button op the screen also to change from state.

At the moment the button is a toggle between Spindle and Router function.

It works, but when running the m6 macro the button stay's in its state (say spindle) and when the gcode has run with a toolchange, it's possible that the machine stands in router function.

I've tried to integrate a function to change this state, accordingly but the button does not react on the input.

I've used the togglename/button state and the up/down position of the switch to get the correct button position, but it's not working.
Also tried to integrate this in the screen script but no avail.

Code: [Select]
if ((rc == ZAxis) and (state == 1)) then
scr.SetProperty('togRouterSpindle', 'Button State', 'Up')

end

Keep Safe,

Adam
Re: Set propperties from button within a function
« Reply #1 on: April 13, 2020, 11:45:34 AM »
Instead of 'Up' and 'Down', use '0' and '1'

Offline DAAD

*
  •  103 103
    • View Profile
Re: Set propperties from button within a function
« Reply #2 on: April 15, 2020, 03:24:40 AM »
Hello,

Needed to figure out what was 1 and 0 but the button is working in some kind of way...
The function is set correctly (router/spindle) but the label state (the visual part of the button does not change.

for example:

The button stands in spindle position when starting an M6 run. The m6 run ends in router position.
The button still shows the spindle label, but is actually set on the router function if i click on it.

Any idea howto change the visual state of the button too? I think it has to do with screenscript refresh?



Re: Set propperties from button within a function
« Reply #3 on: April 15, 2020, 03:49:47 AM »
Do you have different labels set for the Up and Down states? they're not both set to show "Spindle" are they?

FYI '0' is up and '1' is down

Offline DAAD

*
  •  103 103
    • View Profile
Re: Set propperties from button within a function
« Reply #4 on: April 15, 2020, 03:52:11 AM »
Different labels for up and down:  Spindle and router
0 and 1 i found out the "hard way" :-) You would expect it to be the other way around.

Thanks for the help!
Re: Set propperties from button within a function
« Reply #5 on: April 15, 2020, 04:04:21 AM »
I see in your first post you have the condition  'if rc == zAxis and state == 1'  has this been changed since my reply in your other post regarding return codes?  Check this first as I suspect its not being called. If this seems ok, check the return codes on the scr. call. These have their own set of return codes different to the 'mc.' ones. (attached)

Offline DAAD

*
  •  103 103
    • View Profile
Re: Set propperties from button within a function
« Reply #6 on: April 15, 2020, 04:08:58 AM »
code is changed with integration of return code as you mentioned in the other topic.
code now is:

Code: [Select]
function zControl.CheckSpindle()
local axisID, rc = mc.mcMotorGetAxis(inst,Spindle) --Z axis maakt deel uit van variable rc om return code te bekomen
local h_OUTPUT4 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
local state = mc.mcSignalGetState(h_OUTPUT4)

if ((axisID == ZAxis) and (state == 1) and (rc==mc.MERROR_NOERROR)) then --If Zaxis is loaded with motor 2 spindle is active
mc.mcCntlSetLastError(inst, "Spindle already active, No swap required")
scr.SetProperty('togRouterSpindle', 'Button State', '0') -- label spindle is button UP
else zControl.UseSpindle()
end
end


I suppose i need to use the same trick to read out the rc code for the scr type of api?
Re: Set propperties from button within a function
« Reply #7 on: April 15, 2020, 04:30:32 AM »
Should (axisID == ZAxis) be (axisID == mc.Z_AXIS) ?

Offline DAAD

*
  •  103 103
    • View Profile
Re: Set propperties from button within a function
« Reply #8 on: April 15, 2020, 04:52:38 AM »
good tip!

Now i've made a local va ZAxis = 2 for the axisID
Result should be the same i guess.

Offline DAAD

*
  •  103 103
    • View Profile
Re: Set propperties from button within a function
« Reply #9 on: April 16, 2020, 02:42:17 PM »
problem persists...
tried some different things. After looking into some other code with a toggle button, i ended with this as a result. (artsoft tostring)

Return codes, still trying to grasp them...

Code: [Select]
function zControl.CheckSpindle()
local axisID, rc = mc.mcMotorGetAxis(inst,Spindle) --Z axis maakt deel uit van variable rc om return code te bekomen
local h_OUTPUT4 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
local state = mc.mcSignalGetState(h_OUTPUT4)
local rcode = scr.SetProperty('togRouterSpindle', 'Button State', tostring(0))
if rcode~=0 then
mc.mcCntlSetLastError (inst, "check screen error state"..rcode)
end

if ((axisID == mc.Z_AXIS) and (state == 1) and (rc==mc.MERROR_NOERROR)) then --If Zaxis is loaded with motor 2 spindle is active
mc.mcCntlSetLastError(inst, "Spindle already active, No swap required")
--scr.SetProperty('togRouterSpindle', 'Button State', tostring(0))
else zControl.UseSpindle()
end
end