khun
January 8th, 2008, 11:36 PM
Hi!
I haven't yet gotten the setOutputState of the PhidgetInterfaceKit to work after upgrading to G5 and Phidget 2.1 COM. All my Phidget code follows, near the end is the PhidgetSetOutput function, which doesn't work. Note that there is no error message, the problem is that the call doesn't trigger any reaction. Or to be precise, sometimes it does, but it doesn't correspond with the parameters sent to it!
-- ensure only run once
if PI then
return
end
require 'DelayedEventClass'
PI = luacom.CreateObject ("Phidget21COM.PhidgetInterfaceKit")
PI:Open(-1)
PIEvents = {}
PDelayedEvents = {}
function PIEvents:OnAttach()
print ("Attached")
print ("Phidget Interface ".. tostring (PI.IsAttached))
print ("Serial ".. PI.SerialNumber)
print ("Version ".. PI.DeviceVersion)
print ("Inputs "..PI.NumInputs)
print ("Outputs "..PI.NumOutputs)
print ("Sensors "..PI.NumSensors)
for k = 1, PI.NumInputs do
PDelayedEvents [k] = DelayedEventClass:New (50,nil,'PhidgetsInput:'..k,18)
end
end
function PIEvents:OnDetach()
print ("Detached")
end
function PIEvents:OnError(Description, SCODE)
print ("Error",Description,SCODE)
end
function PIEvents:OnInputChange(Index, NewState)
Index = Index + 1
print ("Input " .. Index, "State ",tostring(NewState))
if NewState then
PDelayedEvents [Index]:Start ()
else
PDelayedEvents [Index]:Cancel ()
end
end
function PIEvents:OnOutputChange(Index, NewState)
print ("Output " .. Index, "State "..tostring(NewState))
end
function PIEvents:OnSensorChange(Index, SensorValue)
print ("Sensor " .. Index, "Value "..SensorValue)
end
function PhidgetSetOutput(Nr, mode)
print("PI:setOutputState(" .. Nr .. ", " .. tostring(mode) .. ")")
PI:setOutputState(Nr, mode)
end
luacom.Connect (PI,PIEvents)
function PIDestroy()
PI:close()
PI = nil
PIEvents = nil
PDelayedEvents = nil
collectgarbage()
end
gir.AddScriptResetCallback(PIDestroy)
Any help will be appreciated, the heating system of my house is out of function until this works and it's literally freezing outside!
Question: how does luacom know what kind of parameter setOutputState wants? It should receive a long and a boolean, but I understand lua only works with double floating numbers?
Best regards,
Knut
I haven't yet gotten the setOutputState of the PhidgetInterfaceKit to work after upgrading to G5 and Phidget 2.1 COM. All my Phidget code follows, near the end is the PhidgetSetOutput function, which doesn't work. Note that there is no error message, the problem is that the call doesn't trigger any reaction. Or to be precise, sometimes it does, but it doesn't correspond with the parameters sent to it!
-- ensure only run once
if PI then
return
end
require 'DelayedEventClass'
PI = luacom.CreateObject ("Phidget21COM.PhidgetInterfaceKit")
PI:Open(-1)
PIEvents = {}
PDelayedEvents = {}
function PIEvents:OnAttach()
print ("Attached")
print ("Phidget Interface ".. tostring (PI.IsAttached))
print ("Serial ".. PI.SerialNumber)
print ("Version ".. PI.DeviceVersion)
print ("Inputs "..PI.NumInputs)
print ("Outputs "..PI.NumOutputs)
print ("Sensors "..PI.NumSensors)
for k = 1, PI.NumInputs do
PDelayedEvents [k] = DelayedEventClass:New (50,nil,'PhidgetsInput:'..k,18)
end
end
function PIEvents:OnDetach()
print ("Detached")
end
function PIEvents:OnError(Description, SCODE)
print ("Error",Description,SCODE)
end
function PIEvents:OnInputChange(Index, NewState)
Index = Index + 1
print ("Input " .. Index, "State ",tostring(NewState))
if NewState then
PDelayedEvents [Index]:Start ()
else
PDelayedEvents [Index]:Cancel ()
end
end
function PIEvents:OnOutputChange(Index, NewState)
print ("Output " .. Index, "State "..tostring(NewState))
end
function PIEvents:OnSensorChange(Index, SensorValue)
print ("Sensor " .. Index, "Value "..SensorValue)
end
function PhidgetSetOutput(Nr, mode)
print("PI:setOutputState(" .. Nr .. ", " .. tostring(mode) .. ")")
PI:setOutputState(Nr, mode)
end
luacom.Connect (PI,PIEvents)
function PIDestroy()
PI:close()
PI = nil
PIEvents = nil
PDelayedEvents = nil
collectgarbage()
end
gir.AddScriptResetCallback(PIDestroy)
Any help will be appreciated, the heating system of my house is out of function until this works and it's literally freezing outside!
Question: how does luacom know what kind of parameter setOutputState wants? It should receive a long and a boolean, but I understand lua only works with double floating numbers?
Best regards,
Knut