Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Videos => Topic started by: DazTheGas on December 31, 2015, 10:58:43 AM

Title: Mach4 Quicky #2 Keyboard Plugin
Post by: DazTheGas 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
Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: Chaoticone on December 31, 2015, 11:56:31 AM
Nice Daz!
Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: karcher 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

Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: jbraddock 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
Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: DazTheGas 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
Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: jbraddock on July 07, 2018, 11:28:27 AM
Ok i will try that
Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: jbraddock 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

Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: joeaverage 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
Title: Re: Mach4 Quicky #2 Keyboard Plugin
Post by: joeaverage 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