Hello Guest it is April 28, 2024, 02:21:11 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SwiftyJ

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 »
201
Mach4 General Discussion / Re: Switching tabs
« on: April 28, 2019, 06:53:02 AM »
If you want something to happen when the state of an output or input changes, the Signal Library is the place to do it. The signal library already exists in the default Mach4 Screen Load Script.

Code: [Select]
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = { --<Start of signal library

[mc.ISIG_INPUT0] = function (state)
--Code here executes when Input 0 changes state, either high to low, or low to high
--We can check the state of the input/output by using the 'state' variable that is passed into the function.
if (state == 1) then
--Do something when Input 0 is active
end
end, -- Don't forget to put a comma here.

} --<End of signal library

Any Mach4 inputs or outputs can be added to the signal library in the same format as above, just change the input/output name in the square brackets.

For changing the properties of screen controls there is the scr.SetProperty API call. The tab control has a 'Current Tab' property which we can use to change the tab that is shown.

First we get the name of the control from the Screen Tree Manager, in this case it's "nbGCodeMDI1". See the attachment for info on where to get this.
Code: [Select]
scr.SetProperty("nbGCodeMDI1", )Then we enter the name of the property we want to change as a string
Code: [Select]
scr.SetProperty("nbGCodeMDI1", "Current Tab", )Finally, the value we want to change it to. For the Current Tab property, the value of the first tab is "0", second tab is "1" etc.
Code: [Select]
scr.SetProperty("nbGCodeMDI1", "Current Tab", "1" )
Now combine the two things above,

Code: [Select]

[mc.ISIG_INPUT0] = function (state)
if (state == 1) then
--Change to MDI tab when Input 0 is high.
scr.SetProperty("nbGCodeMDI1", "Current Tab", "1" )
else
--Change to GCode tab when Input 0 is low.
scr.SetProperty("nbGCodeMDI1", "Current Tab", "0" )
end
end,

202
Mach4 General Discussion / Re: edit Cyclestop in screen
« on: April 25, 2019, 07:20:52 AM »
Remove CycleStop() from your button script so it just says:

Code: [Select]
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)

203
Are you not able to select the Register from the properties menu for the gauge control? (see attachment)

If you have not yet created a register, with mach disabled go to Configure>Plugins>Regfile and then add a new instance register and then restart mach. This will appear within the iRegs0 menu when you go to Diagnostics>Regfile. This will also appear in the Register property dropdown for the gauge control. You will need to write a value to the register for the gauge to update.

Alternatively you can use the scr.SetProperty which is used for modifying GUI controls
e.g.
Code: [Select]
scr.SetProperty('gau(1)', 'Value', '10')
Any control property can be edited using this, but it is always advisable to set values etc. using the proper methods.

You can also use wx.wxGauge, but this would required a lua panel if you want to embed it in the screen and gets a bit more confusing..

204
Mach4 General Discussion / Re: edit Cyclestop in screen
« on: April 25, 2019, 03:22:50 AM »
In your PLC script you should have the following code already if you're using the standard Mach4 screens. This bit of code monitors the state of mach, and when it is idle it will resume the coroutine from where it yielded.
Code: [Select]
-------------------------------------------------------
--  Coroutine resume
-------------------------------------------------------
if (wait ~= nil) and (machState == 0) then --wait exist and state == idle
local state = coroutine.status(wait)
    if state == "suspended" then --wait is suspended
        coroutine.resume(wait)
    end
end

The CycleStop() function will go in the screen load script. This will also turn off the COOLANT ON output, but you can change this to whatever output you have mapped for your coolant output.
Code: [Select]
function CycleStop()
local inst = mc.mcGetInstance()
local rc, hSig
mc.mcCntlCycleStop(inst)
mc.mcSpindleSetDirection(inst, 0)
hSig = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON)
if (hSig == mc.MERROR_NOERROR) then
mc.mcSignalSetState(hSig, mc.MC_OFF)
end
mc.mcCntlSetLastError(inst, "Cycle Stopped")
coroutine.yield() --This is where the function yields and the code in the PLC comes into play
rc = mc.mcCntlMdiExecute(inst, "G90 G53 Z0 Y0")
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error moving to Z0 Y0")
end
end

This will go in the button script for your stop button
Code: [Select]
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)

This worked for me in the simulator, but always take caution when trying bits of code off the internet!

205
Mach4 General Discussion / Re: edit Cyclestop in screen
« on: April 24, 2019, 04:35:34 AM »
I'd say you need run the CycleStop() function as a coroutine using the wait coroutine in the PLC, yield the coroutine after mc.mcCycleStop(inst) so that it waits for mach state to be idle, and then use the GCodeExecute API when it resumes.

206
You could try monitoring the state of the control using mcCntlGetState for when it is probing. 102 is File:Run:Probe and 202 is MDI:Run:Probe. You can then activate the output when it is either of these states.

207
Are you trying to incremental jog using the keyboard or onscreen jog controls?

208
Mach4 General Discussion / Re: 2 simple lines
« on: March 11, 2019, 03:57:43 PM »
I believe the state must be 'idle' for the axes to be homed. Therefore you will not be able to use your code in an mcode. If you use the following code in your m100 script and run it, you will most likely get a return value of -18. This is error: MERROR_NOT_NOW - The operation could not be completed at this time.

Code: [Select]
function m100()
--home material and arm
local inst = mc.mcGetInstance()
local rc = mc.mcAxisHome(inst, 0)
mc.mcCntlSetLastError(inst, tostring(rc))
end

if (mc.mcInEditor() == 1) then
m100()
end

209
Mach4 General Discussion / Re: Mach4 MPG axis stop after inc steps overflow
« on: February 24, 2019, 04:20:44 AM »
Would using mc.mcJogIsJogging to check that the axis is not jogging before issuing additional jog moves help?

Thanks

210
Mach4 General Discussion / Re: Message opening by Gcedit
« on: February 03, 2019, 04:33:25 AM »
There seems to be an issue when using 'Match Case' option when using Find or Replace functions in gcEdit.

Open the following file, where <account name> is your Windows user account name
C:\Users\<account name>\AppData\Roaming\gcEdit.ini

Scroll down to MatchCase=4 
Set MatchCase=0

This issue will reappear if you select 'Match Case' again. The match case function still works, its just an annoying message box

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 »