Hello Guest it is June 14, 2025, 05:31:02 PM

Author Topic: Missing handle (but not missing) for output 96?  (Read 1349 times)

0 Members and 1 Guest are viewing this topic.

Missing handle (but not missing) for output 96?
« on: February 01, 2025, 06:35:56 PM »
OK, I'm getting some strange errors with Mach unable to retrieve a handle. for some code on a button

For some reason, whenever I try to get the handle for output 96, it gives me the following error:

Code: [Select]
Lua: Error while running chunk
C:/Mach4Hobby/Modules/bsTcFuncs.lua:144: wxLua: Expected a 'number' for parameter 2, but got a 'nil'.
Function called: 'mcSignalGetHandle(number, nil)'
01. mcSignalGetHandle(number, number, lightuserdata)
stack traceback:
[C]: in function 'mc.mcSignalGetHandle'
C:/Mach4Hobby/Modules/bsTcFuncs.lua:144: in function 'setGantrySafe'
C:/Mach4Hobby/Modules/bsTcFuncs.lua:136: in function 'bsTcFuncs.setGantrySafe'
C:\Mach4Hobby\ScreenScript.lua:3686: in function 'btn_161__Left_Down_Script'
Green Enable LED off

I'm not doing anything strange here in the button code:

Code: [Select]
inst = mc.mcGetInstance()
package.loaded.bsTcFuncs = nil
bstc = require "bsTcFuncs"
local position = "1"
bstc.tcSimpleMoveGantryToPos(position, "XYZ", "1", nil)
local iStatus = bstc.tcVerifyPosition(position)
if iStatus then
    bstc.bsMsgBox("Movement Complete")
    bstc.setGantrySafe(1)
end

and then the function in the module is here, problem line in red (the first function call worked perfectly)  don't worry about my little workaround for internal and external functions, works perfectly)

Code: [Select]
function bsTcFuncs.setGantrySafe(istate)
setGantrySafe(istate)
end

function setGantrySafe(istate)  --This needs to be set to safe before any arm moves
--Desc=Output #96
--Mapping=P1_ToolChanger/TC06_GANTRY_SAFE
--UserDesc=TC06_GANTRY_SAFE: 0(Not in ready position), 1(gantry in safe position, away from carousel)
local inst = mc.mcGetInstance()
Problem---> local hRegGan = mc.mcSignalGetHandle(inst, mc.ISIG_OUTPUT96) --Actual SigID is 1240
mc.mcCntlSetLastError(inst, ("TC06 Gantry Safe = 1 " ..hRegGan))
--local hRegGan = mc.mcSignalGetHandle(inst, 1240)
if( hRegGan ~= nil ) then
if (istate ==1) then
mc.mcSignalSetState(hRegGan, true) --Turn the output on
mc.mcCntlSetLastError(inst, "TC06 Gantry Safe = 1 ")
end
if (istate ==0) then
mc.mcSignalSetState(hRegGan, false) --Turn the output on
mc.mcCntlSetLastError(inst, "TC06 Gantry Safe = 0")
end
end
end

Oddly enough the output is enabled both in the GUI and in the machine.ini file.  I even have a button in my test gui that is assigned to the output and it also works perfectly.

Where do I go from here?
« Last Edit: February 01, 2025, 06:38:21 PM by brianthechemist »
Re: Missing handle (but not missing) for output 96?
« Reply #1 on: February 01, 2025, 06:45:49 PM »
Found it: 

local hRegGan = mc.mcSignalGetHandle(inst, mc.ISIG_OUTPUT96) 

should be

local hRegGan = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT96)