Hello Guest it is October 14, 2024, 12:14:36 AM

Author Topic: Mach4 Quicky #2 Keyboard Plugin  (Read 10021 times)

0 Members and 1 Guest are viewing this topic.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
Mach4 Quicky #2 Keyboard Plugin
« on: December 31, 2015, 10:58:43 AM »
Using the keyboard Inputs in the PLC for Outputs

https://youtu.be/yzaf5pT0l50

The Code

Code: [Select]
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT63)) == 1 then
    mc.mcCntlFeedHold(inst)
else
 --   Do something else
end

DazTheGas
New For 2022 - Instagram: dazthegas

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #1 on: December 31, 2015, 11:56:31 AM »
Nice Daz!
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #2 on: January 01, 2018, 10:03:57 PM »
Very nice solution Daz and an excellent video.

I am considering building a complete USB interfaced operator panel and will need over 60 inputs, as I didn't want to tie up almost all the inputs in M4 I found a way to read from the keyboard plugin directly rather than mapping the inputs to the I/O table.

I realized that the PMC script could read directly from the keyboard plugin but was limited as what I could write to so I borrowed the code from the PMC script and put it in the PLC script in the same place you added yours.

Here it is;

Code: [Select]
local hIo, hReg, hSig, rc
local mInst = 0

local function Read_Io(path)
    hIo = 0
    rc = mc.MERROR_NOERROR
    hIo, rc = mc.mcIoGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        local state = 0
        state, rc = mc.mcIoGetState(hIo)
        if (rc == mc.MERROR_NOERROR) then
            return state
        end
    end
    return 0
end

if(Read_Io("Keyboard/input0") == 1) then -- "input0" is the name of the mapped key in the keyboard plugin
  scr.SetProperty('slideFRO', 'Value', tostring(100)); -- Sets federate override to 100%
end

Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #3 on: July 06, 2018, 05:06:50 PM »
Using the keyboard Inputs in the PLC for Outputs

https://youtu.be/yzaf5pT0l50

The Code

 HOW DO I CHANGE THIS TO WORK AS  ''Enable", or "Cycle Start"
i tried changing the text around to cycle start or enable  but it throws errors, i got the rest working using your youtube vid but to change it to other button functions i seem to be unable to get around the lua scripts

Code: [Select]
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT63)) == 1 then
    mc.mcCntlFeedHold(inst)
else
 --   Do something else
end

DazTheGas

Offline DazTheGas

*
  •  778 778
  • DazTheGas
Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #4 on: July 07, 2018, 02:48:51 AM »
You would simply use different API commands such as mc.mcCntlCycleStart or mc.mcCntlEnable, in the docs directory you will find a help file called Mach4CoreAPI which contains all references to the LUA API.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #5 on: July 07, 2018, 11:28:27 AM »
Ok i will try that
Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #6 on: July 07, 2018, 05:14:44 PM »
You would simply use different API commands such as mc.mcCntlCycleStart or mc.mcCntlEnable, in the docs directory you will find a help file called Mach4CoreAPI which contains all references to the LUA API.

DazTheGas
so i tried this an still it gives errors,,..

if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT2)) == 1 then
   mc.mcCntlEnable(inst)
else
 --   Do something else

Error while running chunk
C:\Mach4Hobby\ScreenScript.lua:573: wxLua: Expected a 'number' for parameter 2, but got a 'no value'.
Function called: 'mcCntlEnable(number)'
01. mcCntlEnable(number, number)
stack traceback:
   [C]: in function 'mcCntlEnable'
   C:\Mach4Hobby\ScreenScript.lua:573: in function <C:\Mach4Hobby\ScreenScript.lua:442>


end

« Last Edit: July 07, 2018, 05:17:14 PM by jbraddock »
Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #7 on: July 07, 2018, 07:23:16 PM »
Hi,

From API.chm:
Quote
LUA Syntax:
rc = mc.mcCntlEnable(
   number mInst,
   number state)
And the number <state> is described:
Quote
state A BOOL specifying the desired control state. TRUE for enabled

Thus your API call needs to be:

mc.mcCntlEnable(inst,1)

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Quicky #2 Keyboard Plugin
« Reply #8 on: July 07, 2018, 07:26:37 PM »
Hi,
might add that this thread is about Daz's video and he might appreciate that a discussion of Lua syntax be conducted in another
thread, probably in the main Mach4 Discussion board.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'