Hello Guest it is May 06, 2021, 08:21:34 PM

Author Topic: ok lua lost on screen button  (Read 339 times)

0 Members and 1 Guest are viewing this topic.

Offline mark4

*
  •  167 167
    • View Profile
ok lua lost on screen button
« 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
Re: ok lua lost on screen button
« Reply #1 on: March 18, 2020, 01:37:49 AM »
Hi,
theres some confusion happening here.

The first two lines are:
Code: [Select]
local inst = mc.mcGetInstance()
local ToolDrumAtSpindle = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9)

and the fourth line is:
Code: [Select]
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:
Code: [Select]
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


My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  365 365
    • View Profile

Offline mark4

*
  •  167 167
    • View Profile
Re: ok lua lost on screen button
« Reply #3 on: March 18, 2020, 05:44:18 PM »
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

Offline mark4

*
  •  167 167
    • View Profile
Re: ok lua lost on screen button
« Reply #4 on: March 18, 2020, 10:53:04 PM »
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

Offline mark4

*
  •  167 167
    • View Profile
Re: ok lua lost on screen button
« Reply #5 on: March 19, 2020, 02:51:19 PM »
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.