PDA

View Full Version : Loading a Plugin From a Component



harleydude
June 12th, 2007, 10:43 AM
I pulled this code from the USBUIRT.Lua component file


local status,loaded = gir.PluginStatus(PluginID)

if not loaded then
gir.LoadPlugin (PluginID) -- load
local t = win.GetElapsedMilliseconds ()
while t + 3000 < win.GetElapsedMilliseconds () do
win.Sleep (200)
status,loaded = gir.PluginStatus(PluginID)
if status > 0 or loaded then
break
end
end
end

if status == 3 then
self:Event (self.Events.Error,'Unable to start the USBUIRT plugin')
end


The above works fine for the USBUIRT Plugin, however I believe there is a bit of a logic problem in the code, if t is set to GetElapsedMilliseconds then t + 3000 will not be less than GetElapsedMilliseconds upon entering the while loop. I changed the < to a > and got the results intended. However, I still having problems with the following code.


-- local xAPID = 261 is set higher up in the code

print ('Checking xAP Plugin Load Status')
local status,loaded = gir.PluginStatus(xAPID)
print ('Status',status,loaded)

if not loaded then
print ('Not loaded, attempting to load')
gir.LoadPlugin (xAPID) -- load
local t = win.GetElapsedMilliseconds ()
while t + 3000 > win.GetElapsedMilliseconds () do
win.Sleep (200)
status,loaded = gir.PluginStatus(xAPID)
print ('Status',status,loaded)
if status == 2 or loaded then
print('xAP Loaded')
break
end
end
end

print ('Loop completed',status,loaded)
if status == 3 then
self:Event (self.Events.Error,'Unable to start the xAP Automation plugin')
else
win.Sleep (1000)
self:Event (self.Events.Update,'xAP Automation plugin started')
xap.xApGirderDev = xap.NewDevice('promixis.girder','promixis.girder.' ..self.HostName,'FF430100')
xap.SetCB(function (...) return self:xApMessageDispatch(unpack(arg)) end)
end


When my component is enabled below is the Console output


Checking xAP Plugin Load Status
Status 0 false
Not loaded, attempting to load
Status 1 true
xAP Loaded
Loop completed 1 true
TreeScript (golua): ...Promixis\Girder5\luascript\components\xAPManage r.lua:194: attempt to index global `xap' (a nil value)
stack traceback:
...Promixis\Girder5\luascript\components\xAPManage r.lua:194: in function `Enable'
...iles\Promixis\Girder5\luascript\ComponentManage r.lua:305: in function `EnableComponent'
...\Girder5\/plugins/treescript/ComponentManager UI.lua:175: in function <...\Girder5\/plugins/treescript/ComponentManager UI.lua:159>


Below is 194 in my file:

xap.xApGirderDev = xap.NewDevice('promixis.girder','promixis.girder.' ..self.HostName,'FF430100')


However the xAP Automation plugin is loaded by the script. Since the above error does not allow my component to actually enable, I can tell CM to enable it and I see the following in the Console.

Checking xAP Plugin Load Status
Status 1 true
Loop completed 1 true


Everything looks good. I am clueless.

Promixis
June 12th, 2007, 05:07 PM
Rick,

I would wait for the global xap to be created, not the plugin status

harleydude
June 12th, 2007, 05:56 PM
Good point, I will give that a try.

Thanks

Promixis
June 14th, 2007, 04:20 PM
Good point, I will give that a try.

Thanks

Rick, the above will not work. You need to release the lua state for the plugin to be loaded.

The next iteration of the CM handles all of this automatically now.

harleydude
June 14th, 2007, 04:34 PM
Thats is what I found as well, I finally resorted to this


local status,loaded = gir.PluginStatus(xAPID)
if not loaded then
print ('xAPManager:CheckPluginStatus() Loading xAP Automation Plugin')
gir.LoadPlugin (xAPID) -- load
local ded = Classes.DelayedExecutionDispatcher:New (3000, function ()
self:CheckPluginStatus ()
end)
return
end

if not xap then
print('xAPManager:CheckPluginStatus() xAP Automation Plugin Not Loaded')
self:Event (self.Events.Status,'Unable to start the xAP Automation plugin')
else
self:Event (self.Events.Status,'xAP Automation plugin started')
xap.xApGirderDev = xap.NewDevice('promixis.girder','promixis.girder.' ..self.HostName,self.Settings.UID)
xap.SetCB(function (...) return self:xApMessageDispatch(unpack(arg)) end)
end

Promixis
June 14th, 2007, 04:41 PM
looks good

when the next rel comes out you can do something like....




local Requires = {
{
Type = 'Version',
Identifier = 'Pro',
},
{
Type = 'Plugin',
Identifier = 235,
Namespace = 'scheduler',
Wait = true,
},

}