PDA

View Full Version : VBScript to Lua translation



m.saviotti
July 7th, 2007, 01:54 AM
Hi, I'm trying to translate in Lua for Girder the following simple Vbs, used to control EIB/KNX field bus:

Dim GroupData,ConnectionObj,EdiMan
Dim EdiGuid,DeviceWriteError
Dim Data
Set EdiMan = CreateObject("FalconClientComponent.EdiManager")
Set GroupData = CreateObject("Falcon.GroupData")
Set ConnectionObj = CreateObject("Falcon.ConnectionObject")
EdiGuid = EdiMan.GetStandardEdiGuid (1,1)
ConnectionObj.Mode () = 5
DeviceOpenError = ConnectionObj.Open(EdiGuid)
Set GroupData.Connection = ConnectionObj
Data = GroupData.ReadSync ("0/1/1",3,7)
DeviceWriteError = GroupData.Write("0/1/1", 3, 7, True, "0")
Set EdiMan = Nothing
Set GroupData = Nothing
Set ConnectionObj = Nothing


Following Lua and Luacom manual I've create this Lua script:

EdiMan = luacom.CreateObject("FalconClientComponent.EdiManager")
GroupData = luacom.CreateObject("Falcon.GroupData")
ConnectionObj = luacom.CreateObject("Falcon.ConnectionObject")
EdiGuid = EdiMan:GetStandardEdiGuid (1,1)
ConnectionObj.Mode = 5
Doerror = ConnectionObj:Open(EdiGuid)
GroupData.Connection = ConnectionObj
Data = GroupData:ReadSync("0/1/1",3,7)
DeviceWriteError = GroupData:Write("0/1/1", 3, 7, True, "0")
EdiMan = nil
GroupData = nil
ConnectionObj = nil
collectgarbage()


The problem is the instruction (line 17) "GroupData.Connection = ConnectionObj" that generate the following error:

COM error:(.\src\library\tLuaCOM.cpp,403):Impossible to find member.
stack traceback:
[C]: ?
[string "Girder4-test.gml:\EIB\Scripting"]:17: in main chunk

I'm not able to find the error, can you please help me?

By

quixote
July 7th, 2007, 02:32 AM
It might help if you told them what you are attemping to do.

m.saviotti
July 8th, 2007, 01:56 AM
Ok, I have to control throug Girder (whith a simple lua script, for the moment, creating a plugin after) an electrical field bus named EIB/KNK, a system like X10, but more "professional" and complex. It can be controlled through a series of DLL libraries (named Falcon Libraries), i.e. to swich on a light, like in my previous example.
I've already a VBScripr working well, so I've studied Lua and Luacom in order to translate it.

First of all I have to create the objects:

EdiMan = luacom.CreateObject("FalconClientComponent.EdiManager")
GroupData = luacom.CreateObject("Falcon.GroupData")
ConnectionObj = luacom.CreateObject("Falcon.ConnectionObject")

Then I have to obtain the connection ID:

EdiGuid = EdiMan:GetStandardEdiGuid (1,1)

Then I've to assign the value to the property

ConnectionObj.Mode = 5

Now I open the connection and check:

Doerror = ConnectionObj:Open(EdiGuid)
-- Till now everithing is OK, the variable list show the correct value (0) for Doerror variable when the connection is open --

================================
Now the problem, I have to assigne to the Property GroupData.Connection the object ConnectionObj. In VBS I use the instruction Set, but in Lua I have no idea (I've also tried with Table Copy......). The simpliest solution seems to be:
----------------------------------------
GroupData.Connection = ConnectionObj
----------------------------------------

But the following actions (both are function or methods, not properties):

Data = GroupData:ReadSync("0/1/1",3,7)
DeviceWriteError = GroupData:Write("0/1/1", 3, 7, True, "0")
-- where "0/1/1" and "0" are the "group address" and the value of the light bulb and the other numbers are parameters not interesting here --

doesn't work at all (in the EIB/KNK debug software I can't see any external call, where in VBS I see everyyhing)

Sorry for the long post, but I wanted to describe everything at the best.

Rob H
July 8th, 2007, 04:31 AM
You could try


GroupData:SetConnection(ConnectionObj)

m.saviotti
July 8th, 2007, 05:11 AM
You could try


GroupData:SetConnection(ConnectionObj)

Sorry, it doesn't work:

[string "Girder4-test.gml:\EIB\Scripting"]:19: attempt to call method `SetConnection' (a nil value)
stack traceback:
[string "Girder4-test.gml:\EIB\Scripting"]:19: in main chunk