Hello Guest it is April 18, 2024, 12:57:28 AM

Author Topic: Keyboard Inputs Enabled or Disabled Handle  (Read 5914 times)

0 Members and 1 Guest are viewing this topic.

Re: Keyboard Inputs Enabled or Disabled Handle
« Reply #10 on: January 04, 2017, 05:18:39 PM »
As of right now, I've got a physical button with the same code as the Keyboard Enable button in the jogging tab, and I've moved that Keyboard button to the file ops tab so the operator won't have to change tabs to see the change in color of the button.
Chad Byrd

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Keyboard Inputs Enabled or Disabled Handle
« Reply #11 on: January 04, 2017, 05:42:37 PM »
The code Steve posted earlier will do exactly that when combined with the SigLib, just assing to a input signal ie..

Code: [Select]
[mc.ISIG_INPUT10] = function (state) -- your choice of input
local hIo = mc.mcIoGetHandle(inst, "Keyboard/Enable")
    if (state == 1) then   
mc.mcIoSetState(hIo, 1) -- Turn the keyboard enable output on.  The keyboard plugin will now accept keyboard input.
    else
mc.mcIoSetState(hIo, 0) -- Turn the keyboard enable output off.  The keyboard plugin will not accept keyboard input.
    end
end,

DazTheGas
New For 2022 - Instagram: dazthegas

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Keyboard Inputs Enabled or Disabled Handle
« Reply #12 on: January 04, 2017, 07:30:15 PM »
You can get the state of the keyboard plugin with the output.  However, since it may not reflect the state of the keyboard plugin at startup, you have to set it to something first.  This is why that call was made the FIRST time the PLC script ran.  Then, once the output is set to on or off, you can then get the output state and it will reflect the status of the keyboard plugin.

Now, there are two outputs that the keyboard plugin exports.  Keyboard/Enable and Keyboard/EnableKeyboardJog.  One enables/disables the entire keyboard key mapping and the other will just disable the jog key mappings but leave the rest of the key mapping working (keyboard must be enabled). 

So it can work.  But...  The register is the better way in case one ever just wants to check if the keyboard mappings are enabled without setting that status first.  In any case, there will be a register called "KeyboardControl/Enabled" that will reflect the state of the keyboard mappings.  If you set that register to 1, it will enable the mapping.  Setting it to 0 will disable all of the mappings.  Reading it will always reflect the status of the mappings. 

Steve

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Keyboard Inputs Enabled or Disabled Handle
« Reply #13 on: January 04, 2017, 07:32:45 PM »
The Keyboard plugin was one of the first plugins we developed.  So it was made prior to the advent of the Mach Register concept.  Just a FYI as to why it is like the way it was.  :)
Re: Keyboard Inputs Enabled or Disabled Handle
« Reply #14 on: August 08, 2018, 06:36:00 PM »
I just did this very thing recently by adding a record to the Keyboard Inputs plugin and using that to trigger the action through the screen PLC script.  My thanks to DazTheGas as I figured this out after watching his 'Mach4 Quicky #2 Keyboard Plugin' video: https://youtu.be/yzaf5pT0l50

1) Assign functions to keys:

Configure->Plugins->Keyboard_Inputs
Add input
InputName: EnableMach
Key: E (for Enable)
CTRL+ALT+SHIFT all checked so that this is not going to happen by accident
Lock key: none
Function: none

I also added similar Inputs for DisableMach (D key), StartCycle (S), HaltCycle (H, because S was already taken and I didn't want to use it as a toggle), and ResetCycle (R).

2)Map the keyboard inputs to Mach inputs:

Configure->Control->Inputs Signals
Input #6 (only because it was the next one available after several of my ESS inputs)
Mapping Enabled: checked
Device: keyboard (from dropdown)
Input Name: EnableMach (from dropdown)

I repeated above using Inputs #7-10 for DisableMach, StartCycle, HaltCycle, and ResetCycle respectively.


3) Add the following code to the screen PLC script immediately following the end of the 'PLC First Run' section:

Code: [Select]
-------------------------------------------------------
--PE3696 ENABLE Mach: CTRL+ALT+SHIFT+E[nable]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT6)) == 1 then
mc.mcCntlEnable(inst,1)
else
 --   Do something else
end

-------------------------------------------------------
--PE3696 DISABLE Mach: CTRL+ALT+SHIFT+D[isable]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT7)) == 1 then
mc.mcCntlEnable(inst,0)
else
 --   Do something else
end

-------------------------------------------------------
--PE3696 START CYCLE: CTRL+ALT+SHIFT+S[tart]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT8)) == 1 then
mc.mcCntlCycleStart (inst)
else
 --   Do something else
end

-------------------------------------------------------
--PE3696 STOP CYCLE: CTRL+ALT+SHIFT+H[alt]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT9)) == 1 then
mc.mcCntlCycleStop (inst)
else
 --   Do something else
end

-------------------------------------------------------
--PE3696 RESET CYCLE: CTRL+ALT+SHIFT+R[eset]
-------------------------------------------------------
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT10)) == 1 then
      mc.mcCntlCycleStop (inst)
  mc.mcCntlReset (inst)
else
 --   Do something else
end


You will have to enable Keyboard Inputs on the Jogging Tab.  You can do this automatically at Mach startup by adding the following code inside the end of the 'PLC First Run' section of the screen PLC script:
Code: [Select]
-------------------------------------------------------
--PE3696 Enable Keyboard on startup
-------------------------------------------------------
local hKeyboardState = mc.mcRegGetHandle(inst, "KeyboardControl/Enabled");
local KeyboardState = mc.mcRegGetValue(hKeyboardState);

if (KeyboardState == 0) then;
KeyboardInputsToggle()
else;
--Do something else
end;


This may be a primitive way of accomplishing all of these actions but it works for me.  I'm new to Lua and Mach4, so please tell me if this method is risky or if there is a vastly simpler way of doing it.

-Paul

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Keyboard Inputs Enabled or Disabled Handle
« Reply #15 on: August 08, 2018, 08:33:45 PM »
Using the PMC is even easier.  Do the same creation of inputs in the the keyboard plugin and map them directly to the desired action in the PMC.  You don't have to map them to Mach signals this way. 

Steve
Re: Keyboard Inputs Enabled or Disabled Handle
« Reply #16 on: September 09, 2018, 08:37:18 AM »
+1 on the PMC.
No Lua required.
Great if you already have an understanding of ladder logic!

Mike
We never have the time or money to do it right the first time, but we somehow manage to do it twice and then spend the money to get it right.