PDA

View Full Version : Calling Girder Events from another program



quixote
September 17th, 2006, 08:58 PM
Can someone please tell me if this code will work with Girder 4?


Set GirderEvent = CreateObject("Girder.GirderEvent")
GirderEvent.Device = 18
GirderEvent.EventString = "MyEvent"
GirderEvent.Payload(1) = payload
GirderEvent.Send()

I'm supposed to be using C#. Thanks.

Rob H
September 17th, 2006, 11:50 PM
That looks like VB rather than C# to me

quixote
September 18th, 2006, 05:52 AM
Oh. That's embarassing.


Can you please give me the translation? I'm kind of hopeless at this stuff -- I already have a really hard time with lua.

quixote
September 18th, 2006, 05:21 PM
I found this:

The following VB code:

Public Sub TestLateBind()
Dim o As Object = CreateObject("SomeClass")
o.SomeMethod(arg1, arg2)
w = o.SomeFunction(arg1, arg2)
w = o.SomeGet
o.SomeSet = w
End Sub

Converts to the following C# code, using this approach:

public void TestLateBind()
{
System.Type oType = System.Type.GetTypeFromProgID("SomeClass");
object o = System.Activator.CreateInstance(oType);
oType.InvokeMember("SomeMethod", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] {arg1, arg2});
w = oType.InvokeMember("SomeFunction", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] {arg1, arg2});
w = oType.InvokeMember("SomeGet", System.Reflection.BindingFlags.GetProperty, null, o, null);
oType.InvokeMember("SomeSet", System.Reflection.BindingFlags.SetProperty, null, o, new object[] {w});
}


but I can't make sense of it. Is all of that really necessary to convert a simple VB code to C#? It seems a little ridiculous.

quixote
September 18th, 2006, 06:46 PM
Apparently, the translation is as simple as:

Girder.GirderEvent GirderEvent = new Girder.GirderEvent();
GirderEvent.Device = 18;
GirderEvent.EventString = "MyEvent";
GirderEvent.Payload(1) = payload;
GirderEvent.Send();
but now it's telling my that the name or namespace "Girder" cannot be found.
I've also tried gir.GirderEvent instead of Girder.GirderEvent.

PLEASE HELP!

Rob H
September 19th, 2006, 02:42 AM
I'm afraid I don't really know enough C# to write it, just to read it. Someone else must know more about this

quixote
September 19th, 2006, 06:34 AM
This is what I have so far, using reflection tools. I'm not sure if it's correct, but I'm getting error messages about not being able to find the namespace.



System.Reflection.Assembly.LoadFrom(@"C:\Program Files\Promixis\Girder\GirderX.dll");
System.Type oType = System.Type.GetTypeFromProgID("Girder.GirderEvent");
object o = System.Activator.CreateInstance(oType);
oType.InvokeMember("Device", System.Reflection.BindingFlags.SetProperty, null, o, new object[] {18});
oType.InvokeMember("EventString", System.Reflection.BindingFlags.SetProperty, null, o, new object[] {"Event"});
oType.InvokeMember("Payload(1)", System.Reflection.BindingFlags.SetProperty, null, o, new object[] {Payload});
oType.InvokeMember("Send", System.Reflection.BindingFlags.InvokeMethod, null, o, null);

Girder.GirderEvent GirderEvent = new Girder.GirderEvent();
GirderEvent.Device = 18;
GirderEvent.EventString = "Event";
GirderEvent.Payload(1) = Payload;
GirderEvent.Send();


If you can take a look at this, I could really use the initial help on this project. Thanks

Ron
September 19th, 2006, 07:41 AM
Alright here comes the solution :-)

1. Throw out above code.

2. Start a new C# project.

3. Project / Add Reference / Com / GirderX 1.0 Type Library

4. Add code:



GIRDERXLib.GirderClass x = new GIRDERXLib.GirderClass();
x.TriggerEvent("hello",200,"pl1","pl2","pl3",0);

quixote
September 19th, 2006, 08:01 AM
Alright here comes the solution :-)

1. Throw out above code.

2. Start a new C# project.

3. Project / Add Reference / Com / GirderX 1.0 Type Library

4. Add code:



GIRDERXLib.GirderClass x = new GIRDERXLib.GirderClass();
x.TriggerEvent("hello",200,"pl1","pl2","pl3",0);


I'll try that when I get back from work.

THANK YOU SO MUCH!!!! I'm really anxious to get this working. I'm trying to use a Verbot ( www.verbots.com ) with Girder. I'll let you know how it goes.

Agonostis
September 19th, 2006, 01:43 PM
Now when will we be able to use the girderX object to get information back from girder ;-)?

Ron
September 19th, 2006, 01:47 PM
not any time soon. That would require a TCP/IP connection over the comserver. Slowing down that object enormously.

quixote
September 22nd, 2006, 08:13 PM
Alright here comes the solution :-)

1. Throw out above code.

2. Start a new C# project.

3. Project / Add Reference / Com / GirderX 1.0 Type Library

4. Add code:



GIRDERXLib.GirderClass x = new GIRDERXLib.GirderClass();
x.TriggerEvent("hello",200,"pl1","pl2","pl3",0);


Apparently, (according to one of the developers over at Conversive: Verbots) this script is not possible to implement in C#. Supposedly I need to use something like this:

System.Reflection.Assembly.LoadFrom(@"C:\program files\promixis\girder\girderx.dll");
System.Type oType = System.Type.GetTypeFromProgID("GIRDERXLib.GirderClass");
object o = System.Activator.CreateInstance(oType);
oType.InvokeMember("Device", System.Reflection.BindingFlags.SetProperty, null, o, new object[] {18});
oType.InvokeMember("EventString", System.Reflection.BindingFlags.SetProperty, null, o, new object[] {"(Event)"});
oType.InvokeMember("Send", System.Reflection.BindingFlags.InvokeMethod, null, o, null);
oType.InvokeMember("TriggerEvent", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] {"(Event)",200,"pl1","pl2","pl3",0});
I am setting the Event name as a variable from inside the program.
I still can't get it to work, but I'm certain that I'm just missing a small detail. If there is anything that is obviously wrong with this code, please PLEASE anyone let me know. Thanks.

quixote
September 23rd, 2006, 02:02 AM
If no one can answer this question, then maybe I'll look into an alternative.
How many more milliseconds would it take to execute a Event.exe command?
Just a side thought (albeit an unfavorable solution).