Hello Guest it is March 29, 2024, 08:41:18 AM

Author Topic: v2336 Keyboard Simulator plugin  (Read 2916 times)

0 Members and 1 Guest are viewing this topic.

v2336 Keyboard Simulator plugin
« on: June 05, 2015, 01:17:25 PM »
...the working one

Attached is the keyboard simulator plugin from m4 ver. 2336.

Just delete the keyboard sim from your plugin folder and paste this one in. It works like a charm. I have 30 inputs mapped to functions.

Below is some sample code to put into your signal table/library in the screen load up script. You can map keys straight from m4 input tabs under configuration for jogging. You can really do a lot with it.

I would recommend when you map a key to have the Caps Lock on. This way when you type the keyboard sim doesn't interfere.

I can manipulate mach4 using the keyboard simulator with my Bluetooth keyboard away from the computer. It is also good to simulate probe inputs to test code with using the Mach4 Simulator plugin (as a motion controller sim).

--josh

Code: [Select]
--Keyboard Sim 'Return' w/Caps Lock on to enable Mach 4.
    sigLib[mc.ISIG_INPUT60] = function (state)
        local inst = mc.mcGetInstance ()
        local hSig = mc.mcSignalGetHandle (inst, mc.OSIG_MACHINE_ENABLED)
        local sigState = mc.mcSignalGetState (hSig)

        if state == 1 then
            if sigState == 0 then
            mc.mcSignalSetState (hSig, 1)
            elseif sigState == 1 then
            mc.mcSignalSetState (hSig, 0)
            end
        end
    end

    --Keyboard Sim 'C' w/Caps Lock on to center table.
    sigLib[mc.ISIG_INPUT61] = function (state)
        local inst = mc.mcGetInstance ()
        local gCode = ""
        if state == 1 then
            gCode = "G00 G90 X9.0 Y2.0 Z0.0 \n"
            mc.mcCntlMdiExecute (inst, gCode)
        end
    end

    --Keyboard Sim 'Esc' for Estop.
    sigLib[mc.ISIG_INPUT62] = function (state)
        local inst = mc.mcGetInstance ()
        local rc = 0
        mc.mcCntlEStop (inst, 1)
    end

    --Keyboard Sim 'H' w/Caps Lock on to home all axes.
    sigLib[mc.ISIG_INPUT63] = function (state)
        local inst = mc.mcGetInstance ()
        if state == 1 then
            mc.mcAxisHomeAll (inst)
        end

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: v2336 Keyboard Simulator plugin
« Reply #1 on: June 05, 2015, 08:13:27 PM »
well done
Re: v2336 Keyboard Simulator plugin
« Reply #2 on: June 06, 2015, 12:06:49 AM »
thanx Dan!

...here's the hot key package I got so far. still working on that auto tool sequence tho.

--josh

Code: [Select]
--Probe input.
    sigLib[mc.ISIG_INPUT0] = function (state)
        local inst = mc.mcGetInstance ()
        if state == 1 then 
            mc.mcCntlCycleStop(inst)
            for i=1, myAxes do mc.mcMotorIsStill (inst, i)end
        end
    end
--Tool setter input
    sigLib[mc.ISIG_INPUT1] = function (state)
        local inst = mc.mcGetInstance ()
        if state == 1 then
            for i=0, myAxes do mc.mcJogVelocityStop (inst,i) end
        end
    end
--Keyboard Sim '2' w/Caps Lock on for auto tool zero sequence
    sigLib[mc.ISIG_INPUT58] = function (state)
        local inst = mc.mcGetInstance ()
        local hSig = mc.mcSignalGetHandle (inst, mc.OSIG_TOOL_CHANGE)
        local sigState = mc.mcSignalGetState (hSig)

        if state == 1 then
            if sigState == 0 then
                mc.mcSignalSetState (hSig, 1)
                flag[1] = 1
            elseif sigState == 1 then
                mc.mcSignalSetState (hSig, 0)
                flag[1] = 0
            end
        end
    end
--Keyboard Sim '1' w/Caps Lock on for start tool setter calibration.
    sigLib[mc.ISIG_INPUT59] = function (state)
        local inst = mc.mcGetInstance ()
        local hSig = mc.mcSignalGetHandle (inst, mc.OSIG_OUTPUT30)
        local sigState = mc.mcSignalGetState (hSig)

        if state == 1 then
            if sigState == 0 then
                mc.mcSignalSetState (hSig, 1)
                flag[1] = 1
            elseif sigState == 1 then
                mc.mcSignalSetState (hSig, 0)
                flag[1] = 0
            end
        end
    end
--Keyboard Sim 'F1' w/Caps Lock on to enable Mach 4.
    sigLib[mc.ISIG_INPUT60] = function (state)
        local inst = mc.mcGetInstance ()
        if state == 1 then
            mc.mcCntlEnable (inst, 1)
        end
    end
--Keyboard Sim 'C' w/Caps Lock on to center table.
    sigLib[mc.ISIG_INPUT61] = function (state)
        local inst = mc.mcGetInstance ()
        local gCode = ""
        if state == 1 then
            gCode = "G00 G90 G53 Z0.0 \n"
            gCode = gCode .."G53 X9.0 Y2.0 \n"
            mc.mcCntlMdiExecute (inst, gCode)
        end
    end
--Keyboard Sim 'Esc' for Estop.
    sigLib[mc.ISIG_INPUT62] = function (state)
        local inst = mc.mcGetInstance ()
        local rc = 0
        if state == 1 then
            mc.mcCntlEStop (inst, 1) 
        end
    end
--Keyboard Sim 'H' w/Caps Lock on to home all axes.
    sigLib[mc.ISIG_INPUT63] = function (state)
        local inst = mc.mcGetInstance ()
        if state == 1 then
            mc.mcAxisHomeAll (inst)
        end
    end

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: v2336 Keyboard Simulator plugin
« Reply #3 on: June 06, 2015, 12:30:44 AM »
for the people who don`t know can you add where the codes you have posted goes, I know you have added it above but some people don't read instructions all the time
« Last Edit: June 06, 2015, 12:40:25 AM by daniellyall »
Re: v2336 Keyboard Simulator plugin
« Reply #4 on: June 06, 2015, 12:40:56 AM »
idk Dan...what do you mean?

one other thing though, 'myAxes' in the script is a my global variable of my total number of enabled axes. So wherever you see myAxes just replace it with 11 or whatever number you want....

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: v2336 Keyboard Simulator plugin
« Reply #5 on: June 06, 2015, 12:46:48 AM »
i am a bit dyslexic forgot to prof read before hitting post