Machsupport Forum
Mach Discussion => Mach4 General Discussion => Mach4 Videos => Topic started 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
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT63)) == 1 then
mc.mcCntlFeedHold(inst)
else
-- Do something else
end
DazTheGas
-
Nice Daz!
-
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;
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
-
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
if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT63)) == 1 then
mc.mcCntlFeedHold(inst)
else
-- Do something else
end
DazTheGas
-
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
-
Ok i will try that
-
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
-
Hi,
From API.chm:
LUA Syntax:
rc = mc.mcCntlEnable(
number mInst,
number state)
And the number <state> is described:
state A BOOL specifying the desired control state. TRUE for enabled
Thus your API call needs to be:
mc.mcCntlEnable(inst,1)
Craig
-
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