Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Analias on July 24, 2014, 11:32:29 PM
-
I'm having a an odd problem within my screen PLC script. I don't know if it's a Lua issue or something about the PLC script.
I have two local modules that I have created, SigLib.mcc and MyStdMill.mcc. Both I import using a require in the screen startup script. I make SigLib calls in the screen startup and signal scripts, and it works flawlessly. I only make MyStdMill calls in the screen PLC script. Even though debugging shows the table containing the module is there (it has a non zero value), all my function calls cause an error since they are nil value.
I thought that anything imported in the screen startup script should be seen in the PLC script. Is this not the case?
-Freeman
-- Startup script
function GetMachDir ()
local inst = mc.mcGetInstance();
return mc.mcCntlGetMachDir (inst);
end
local machDir = GetMachDir();
package.path = "./?.lua;" ..
machDir .. "/?.dll;" ..
machDir .. "/Modules/?.mcc;" ..
machDir .. "/Profiles/MyStdMill/Modules/?.mcc"
SigLib = require "SigLib"
MySM = require "MyStdMill"
-- PLC script
MySM.plcScreenSetName(inst)
MySM.plcAxisScaling(inst, 'droMySMScaleX', 'iRegs0/xScale')
MySM.plcAxisScaling(inst, 'droMySMScaleY', 'iRegs0/yScale')
MySM.plcAxisScaling(inst, 'droMySMScaleZ', 'iRegs0/zScale')
MySM.plcAxisScaling(inst, 'droMySMScaleA', 'iRegs0/aScale')
-- MystdMill.mcc Module
local MyStdMill = {}
function MyStdMill.plcScreenSetName (inst)
-- code abbreviated
end
function MyStdMill.plcAxisScaling(inst, dro, reg)
-- code abbreviated
end
return MyStdMill
-
I should also mention that the following test script runs and calls MySM.plcScreenSetName() just fine:
function GetMachDir ()
local inst = mc.mcGetInstance();
return mc.mcCntlGetMachDir (inst);
end
local machDir = GetMachDir();
package.path = "./?.lua;" ..
machDir .. "/?.dll;" ..
machDir .. "/Modules/?.mcc;" ..
machDir .. "/Profiles/MyStdMill/Modules/?.mcc"
MySM = require "MyStdMill"
SigLib = require "SigLib"
function test ()
local inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, "package.path = " .. package.path)
mc.mcCntlSetLastError(inst, "MySM = " .. tostring(MySM))
SigLib.AddSignalHandler(mc.OSIG_HOMED_X, function (state)
mc.mcCntlSetLastError(inst, "state : " .. tostring(state))
end)
SigLib.DispatchSignal (mc.OSIG_HOMED_X, 1)
MySM.plcScreenSetName(inst)
end
if (mc.mcInEditor() == 1) then
test()
end
-Freeman
-
Uhmmm (grrrrrr.....) - A restart of Mach 4 fixed the problem.
Sorry, nothing to see here - please move along. No pictures please. No ma'am, it's just the village idiot...
-Freeman
-
Hey Freeman, the DSC 3.0 module already does all that stuff, and much more, it would save you some time.......
Scott
-
Hey Freeman, the DSC 3.0 module already does all that stuff, and much more, it would save you some time.......
Scott
Scott, have you seen my latest response to your DSC 3.0 thread? I still can't import the module. Have you been able to use it with build 1900 or later? I haven't tried with build 1915 yet. It still appears to be a compile version issue. Could you recompile under build 1915 and send me the mcc file?
I've been forced to duplicate much of what DSC 3.0 does :-(
-Freeman
Sent from my Xoom using Tapatalk
-
see DSC 3.0 again, in tool box, I had to recompile it under 1900+, and fix an undocumented lua bug in 5.2 (their documentation is WRONG, on the lua users manual website for 5.2), Steve was able to search out and find another group that found this same issue with the fix!!!
Try it agian, BTW: Ya-Nvr-No has tryied the new compiled version, and it is running for him as well and in his screen sets!!
Scott