Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: mark4 on March 17, 2020, 10:28:09 PM
-
Hello
I am just confused and have read so much that I am even more lost. LOL
Can somebody help
I want a screen button to read input 9 and if input 9 is off then turn on output 8
until input 9 is on. then turn off output 8. seemed simple
The object is a tool changer manual button to go to the spindle so you click the button and
if the tool holder is at park then the switch "input 9" is off so turn the motor on "output 8"
when the "input 9" turns on turn the motor "output 8" off.
This is what i have so far notice their are two different as not sure which signal get handle are the proper form.
And the signal get state if then loop just has to be all kinds of wrong
local inst = mc.mcGetInstance()
local ToolDrumAtSpindle = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9)
local ToolDrumToSpindle = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
if mc.mcSignalGetState(ToolDrumAtSpindle ==1 ) then
mc.mcSignalSetState(ToolDrumToSpindle,0)
else
mc.mcSignalSetState(ToolDrumToSpindle,1)
end
--local inst = mc.mcGetInstance()
--local ToolDrumAtSpindle = mc.ISIG_INPUT9
--local ToolDrumToSpindle = mc.OSIG_OUTPUT8
-- if mc.mcSignalGetState(ToolDrumAtSpindle,1) then
-- mc.mcSignalSetState(ToolDrumToSpindle,0)
-- else
-- mc.mcSignalSetState(ToolDrumToSpindle,1)
--end
Never did a button before except to just turn on or off an input.
Thank you
Mark
-
Hi,
theres some confusion happening here.
The first two lines are:
local inst = mc.mcGetInstance()
local ToolDrumAtSpindle = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9)
and the fourth line is:
if mc.mcSignalGetState(ToolDrumAtSpindle ==1 ) then
As you have written it 'TooDrumAtSpindle' is a HANDLE.....not a variable. Whereas in the fourth line you are treating in confused fashion,
for example you have written ToolDrumAtSpindle==1......what does that mean?. I can see what you are trying to do but you are confusing
a HANDLE and a VARIABLE.
Try this:
local inst=mc.mcGet Instance()
local ToolDrumAtSpindleHANDLE=mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9)
local ToolDrumToSpindleHANDLE = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
local ToolDrumAtSpindle=mc.mcSignalGetState(ToolDrumAtSpindleHANDLE)
if (ToolDrumAtSpindle ==1 ) then
mc.mcSignalSetState(ToolDrumToSpindleHANDLE,0)
else
mc.mcSignalSetState(ToolDrumToSpindleHANDLE,1)
end
So to correctly populate a variable requires a two step process, first you get the HANDLE, that is equivalent to the memory
address of the signal, then you use the mcSignalGetState(handle) to read the contents of that memory location.
To set an output you use the output signals HANDLE and the data or state which you wish to apply.
Craig
-
Mark4
This might help.
https://www.machsupport.com/forum/index.php?topic=39763.msg266718#msg266718
-
I have read the lua for dummies thanks for the info.
However I still have a slight problem the code I managed to get to work on a button and in the
screen load script as a function.
-------------------------------------------------------------
-- tool drum to spindle
-------------------------------------------------------------
function ToolDrumToSpindle()
--local inst=mc.mcGet Instance()
local ToolDrumAtSpindleHANDLE=mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9)
local ToolDrumToSpindleHANDLE = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
local ToolDrumAtSpindle=mc.mcSignalGetState(ToolDrumAtSpindleHANDLE)
if (ToolDrumAtSpindle ==1 ) then
mc.mcSignalSetState(ToolDrumToSpindleHANDLE,0)
end
if (ToolDrumAtSpindle ==0) then
mc.mcSignalSetState(ToolDrumToSpindleHANDLE,1)
end
end
The problem is it doesnt shut off. so I need output 8 to turn on and move a motor as long as input 9 end of stroke switch is off. Then turn the motor output 8 off when input 9 triggers. if i click the button it will shut off but it wont shut off on input 9.
Thank you
Mark
-
I wonder if the problem is i am emulating input 9 so it 1/2 works it wont let it start unless it is off. But once it turns on it doesnt turn off output eight. I will try it with the real switch tomorrow. And hope for the best. The seperate if/then loops were simply to try to get it to shut off and didnt work. Of course.
Mark
-
I worked it out and here are the working results.
local inst = mc.mcGetInstance()
local ToolDrumAtSpindle = mc.mcSignalGetHandle(inst,mc.ISIG_INPUT9)
local ToolDrumToSpindle = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT8)
local ToolDrumAtSpind = mc.mcSignalGetState(ToolDrumAtSpindle)
mc.mcSignalSetState(ToolDrumToSpindle, 1)
local retcode = mc.mcSignalWait(inst,mc.ISIG_INPUT9, mc.WAIT_MODE_HIGH,5)
if retcode == mc.MERROR_TIMED_OUT then
mc.mcSignalSetState(ToolDrumToSpindle,0)
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "drum stuck")
end
mc.mcSignalSetState(ToolDrumToSpindle,0)
needed the wait.