Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: DAAD on April 13, 2020, 10:54:33 AM

Title: Set propperties from button within a function
Post by: DAAD 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
Title: Re: Set propperties from button within a function
Post by: SwiftyJ on April 13, 2020, 11:45:34 AM
Instead of 'Up' and 'Down', use '0' and '1'
Title: Re: Set propperties from button within a function
Post by: DAAD 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?



Title: Re: Set propperties from button within a function
Post by: SwiftyJ 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
Title: Re: Set propperties from button within a function
Post by: DAAD 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!
Title: Re: Set propperties from button within a function
Post by: SwiftyJ 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)
Title: Re: Set propperties from button within a function
Post by: DAAD 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?
Title: Re: Set propperties from button within a function
Post by: SwiftyJ on April 15, 2020, 04:30:32 AM
Should (axisID == ZAxis) be (axisID == mc.Z_AXIS) ?
Title: Re: Set propperties from button within a function
Post by: DAAD 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.
Title: Re: Set propperties from button within a function
Post by: DAAD 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
Title: Re: Set propperties from button within a function
Post by: DAAD on May 04, 2020, 12:58:03 AM
I've got this code working from within a button at the moment.
If i click the button the state of the toggle is set propperly.
Now i want tho run it inside a macro so i can use it inside my M6 when i do a toolchange.
But then the code refuses to work. Nothing happens.

I thinks it's because this is a gui related code and the screen does not refresh when running a macro (or gcode file).

Is there a way i can refresh the screen to set this button when running a macro or gcode?

I tought of putting some script in the plc script, but because of the loop sequence, the button "flickers" when i trie to do that.

Keep Safe,

Adam




Code: [Select]
function zControl.ButtonState()
local axisID, mc.mcMotorGetAxis(inst,Spindle)
local h_OUTPUT4 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
local state = mc.mcSignalGetState(h_OUTPUT4)

if ((axisID == mc.Z_AXIS) and (state == 1) then
scr.SetProperty('togRouterSpindle', 'Button State', (0))
else
                       scr.SetProperty('togRouterSpindle', 'Button State', (1)

end
end
Title: Re: Set propperties from button within a function
Post by: SwiftyJ on May 05, 2020, 03:27:09 AM
You should learn to use the debugging features inside ZeroBrane to help identify reasons why code doesn't work

If its code from a module or screen load script I will normally copy the code and paste it into a script of temporary button that I created. First hit F7 to compile the code, this will highlight any initial errors in the Output window at the bottom.

After compilation is successful use F5 to start debugging and then F11 to step through the code line by line. You can right click on variables and add them to the Watch list so that you can see the values update as you step through the code. Any errors will be shown in the Output window at the bottom along with the line number that the error occurred on.