PDA

View Full Version : Need help convert VB 2005 Import to TB



steinie
04-09-2011, 03:29
i need help to convert VB 2005 Import to TB Declare.
If you know Vbasic maybe you can help me out?:o

[VB code]


Imports ActiveHomeScriptLib
Imports System
Module Module1
Dim WithEvents ActiveHomeObj As ActiveHome
<MTAThread()> Sub Main()

'create ActiveHome object
Try
ActiveHomeObj = CreateObject("X10.ActiveHome")
Catch exc As Exception
Console.WriteLine("err num: " & Str(Err.Number) & " '" & exc.ToString & "'")
Finally
End Try

'send a1 on
Try
ActiveHomeObj.SendAction("sendplc", "a1 on")
Catch exc As Exception
Console.WriteLine("err num: " & Str(Err.Number) & " '" & exc.ToString & "'")
Finally
End Try

'wait for events
Dim nRead
While True
System.Threading.Thread.Sleep(0)
nRead = Console.Read()
End While

End Sub

'events from ActiveHome: write out received event
Sub ActiveHome_RecvAction(ByVal bszRecv As Object _
, ByVal vParm1 As Object _
, ByVal vParm2 As Object _
, ByVal vParm3 As Object _
, ByVal vParm4 As Object _
, ByVal vParm5 As Object _
, ByVal vReserved As Object) Handles ActiveHomeObj.RecvAction
Console.WriteLine("RecvAction: " & bszRecv & " " & vParm1 & " " & vParm2 & " " & vParm3 & " " & vParm4 & " " & vParm5)
End Sub

End Module

[/code]

Petr Schreiber
05-09-2011, 22:57
If this is COM object, you might have a look at examples in ThinBASIC/SampleScripts/COM.

I wanted to help you with the translation, but sadly I do not have the X10.ActiveHome on my PC installed. To instantiate it, you would need something like:


Uses "COM"

' -- Create object
DWord retVal
DWord ActiveHomeObj = COM_CREATEOBJECT("X10.ActiveHome", RetVal)

' -- Call method (parameters should be supplied in form of Variant array)
Dim Params() As Variant
Params(1) = "sendplc"
Params(2) = "a1 on"
COM_CallMethod(ActiveHomeObj, "SendAction", 2, Params(1))

...


' -- Release it before script ends
COM_RELEASE(ActiveHomeObj)


But as I said, I cannot test the rest, as I do not have this interface on my PC. The mentioned sample scripts should help you, I hope.


Petr

steinie
06-09-2011, 19:33
OK Petr, Thanks for your help! :p
The send works with three minor changes -

Uses "COM" ' -- Create object
Dim RetVal As Variant '<---------------------
'DWord retVal
DWord ActiveHomeObj = COM_CREATEOBJECT("X10.ActiveHome", RetVal)
' -- Call method (parameters should be supplied in form of Variant array)
Dim Params(2) As Variant '<------------------
Params(1) = "sendplc"
Params(2) = "B09 off"
COM_CALLMETHOD(ActiveHomeObj, "SendAction", 2, Params(1), RetVal) '<-----

Will this cause an event to be generated for Receive?
or do I need a While loop to test it?

There are 2 Params to send and 6 Params for Receive.

More info here: http://www.activehomepro.com/sdk/sdk-info.html

Petr Schreiber
07-09-2011, 16:05
Hi Steinie,

I am sorry, but regarding receiving event, I never did this in ThinBASIC.
Maybe worth some time to check examples in SampleScripts/Oxygen/COM, my experience with COM is limited, maybe Charles Pegge could know more?


Petr