简体   繁体   English

尝试调用全局“Sicherheitskreis”(一个 nil 值)堆栈回溯

[英]Attempt to call global "Sicherheitskreis" (a nil value ) stack traceback

I'm trying to secure the doors of my CNC with switchs that send a Signal to my Laptop (I got Mach 4 on it).我试图用向我的笔记本电脑发送信号的开关来保护我的 CNC 的门(我有 4 马赫)。 I created this Code that should make the Spindle stay still if the doors aren't locked, but I always get an error that says :我创建了这个代码,如果门没有锁定,它应该使主轴保持静止,但我总是收到一个错误消息:

[string""]1576 attempt to call global 'SicherheitsKreis' (a Nil value) stack traceback:

I've tried to move the Code around and read topics on this, but Nothing works.我试图移动代码并阅读有关此的主题,但没有任何效果。 Does someone have a solution ?有人有解决方案吗? Here's all my Code :这是我所有的代码:

function SicherheitsKreis(Schliesserstate, Oeffnerstate)
   if (Schliesserstate ==0 and Oeffnerstate ==1 ) then 
     mc.mcSpindleSetDirection(inst,0)
   elseif (Schliesserstate == 1 and Oeffnerstate == 0 ) then 
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
     local sigState = mc.mcSignalGet State(sigh);
     if (sigState == 1) then 
       mc.mcSpindleSetDirection(inst,0)
     else 
       mc.mcSpindleSetDirection(inst,1);
     end
   else 
     mc.mcSpindleSetDirection(inst,0)
     end
end 

if (mc.mcInEditor() == 1) then
    SicherheitsKreis()
end

The Code that I'm using to call SicherheitsKreis is :我用来调用 SicherheitsKreis 的代码是:

local inst = mc.mcGetInstance()
local hsigSchliesser = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT8);
local hsigOeffner = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT9);
local Schliesserstate = mc.mcSignalGetState(hsigSchliesser);
local Oeffnerstate = mc.mcSignalGetState(hsigSchliesser); 
 SicherheitsKreis(Schliesserstate, Oeffnerstate)

This Script is typed in Mach 4 and the function is saved as am function (nach4 has free m function that the user can customize) in the Memory of Mach 4 (for my Computer it is m146)这个脚本是在 Mach 4 中输入的,并且该函数在 Mach 4 的内存中保存为 am 函数(nach4 有用户可以自定义的免费 m 函数)(我的电脑是 m146)

Your code:您的代码:

function SicherheitsKreis(Schliesserstate, Oeffnerstate)
...
end

First possibility is that code is in some other function or other element, so it is not global.第一种可能性是代码在某个其他函数或其他元素中,因此它不是全局的。 Second possibility is that you run SicherheitsKreis(Schliesserstate, Oeffnerstate) before loading this part of code.第二种可能性是您在加载这部分代码之前运行SicherheitsKreis(Schliesserstate, Oeffnerstate) Third (very uncommon) is that you override it by SicherheitsKreis = nil or equivalent.第三个(非常不常见)是你用SicherheitsKreis = nil或等价物覆盖它。 There is no other possibilities.没有其他可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM