Wrapper for C# plugin development!
Re: Wrapper for C# plugin development!
I’ve been trying to play with this all day, and I believe there might be an issue with the way we were instructued to set it up.
If you turn on ‘Settings-Tracing … ->Device’ and check the Output to system window, you will see that compiling either of the samples will result in the “Unable to find device initialization function (HBDeviceModuleInit) for Device DLL Module (path of the module in the plugins\devices dir)”
And yes, I double and triple checked, the HBDotNet.dll is in the \housebot folder!
Richard, I saw the same errors you did, so I started adding sysbeeps to early phases of the module, and they never got called, which made me turn on tracing (which is awesome, thanks Scott).
Dlmorgan, can you please post the sources to the HBDotNet and HBDotNetbridge dll’s?
Being able to see how everything is glued together would be very helpful in resolving these scenarios, or in possibly providing improvements if required.
Has anyone else gotten theses examples to load successfully?
If you turn on ‘Settings-Tracing … ->Device’ and check the Output to system window, you will see that compiling either of the samples will result in the “Unable to find device initialization function (HBDeviceModuleInit) for Device DLL Module (path of the module in the plugins\devices dir)”
And yes, I double and triple checked, the HBDotNet.dll is in the \housebot folder!
Richard, I saw the same errors you did, so I started adding sysbeeps to early phases of the module, and they never got called, which made me turn on tracing (which is awesome, thanks Scott).
Dlmorgan, can you please post the sources to the HBDotNet and HBDotNetbridge dll’s?
Being able to see how everything is glued together would be very helpful in resolving these scenarios, or in possibly providing improvements if required.
Has anyone else gotten theses examples to load successfully?
_______
Jonathan
Jonathan
-
- HouseBot Guru Extraordinaire
- Posts: 1121
- Joined: Tue Sep 28, 2004 7:49 am
- Location: The Netherlands
Re: Wrapper for C# plugin development!
Glad to see I am not the only one having trouble setting this up. I was also wondering if other posters in this thread had succesfully setup the examples but never got an answer. If you do figure it out, I would really like the info so I can get some stuff to work which cannot be done using vbscript.
Re: Wrapper for C# plugin development!
I haven't had any problems. I tried the sample and have written a few small things. I believe Osler has used it too, perhaps he'll chime in. BTW, I don;t believe Dlmorgan wrote the plugin, he just knows or has access to the person who did. I too however would like to see the source if the author would release it.
Terry
Terry
Re: Wrapper for C# plugin development!
Terry, good to hear it worked for you, did you follow the instructions to the letter, or is there anything unique about your deployment for the dll's?
Since I'm using C# express, and it had to convert the solutions from C# 2005, I'm wondering if there's a binding or setting Richard and I are not doing to get the thing to build right. Any pointers?
TIA
Since I'm using C# express, and it had to convert the solutions from C# 2005, I'm wondering if there's a binding or setting Richard and I are not doing to get the thing to build right. Any pointers?
TIA
_______
Jonathan
Jonathan
Re: Wrapper for C# plugin development!
I haven't had time to play with it too much. I did get it to create a device with properties successfully. Have you all checked out the source code posted by allanstevens for his weather plugin?
Osler
Osler
-
- HouseBot Guru Extraordinaire
- Posts: 1121
- Joined: Tue Sep 28, 2004 7:49 am
- Location: The Netherlands
Re: Wrapper for C# plugin development!
I also used C# Express. Maybe that's a pointer.JonFo wrote:Since I'm using C# express, and it had to convert the solutions from C# 2005, I'm wondering if there's a binding or setting Richard and I are not doing to get the thing to build right. Any pointers?
TIA
@Roussell: What did you use to compile the example?
Re: Wrapper for C# plugin development!
I used the 2008 express editions as well, along with the 3.5 framework.
I don't remember having to do anything special (for c#), I'll rebuild the samples tonight and make a note of anything out of the ordinary.
Terry
I don't remember having to do anything special (for c#), I'll rebuild the samples tonight and make a note of anything out of the ordinary.
Terry
-
- HouseBot Special Member
- Posts: 409
- Joined: Tue Jul 13, 2004 9:13 am
- Location: Tigard, OR
Re: Wrapper for C# plugin development!
I'm out of town on vacation right now so I can't do much right now. I'll try to check in when I get back though and see if I can help.
Re: Wrapper for C# plugin development!
Hi Dave, thanks we look forward to your input.
In the meantime, I found some information that should help.
First, the tracing error I listed above “Unable to find device initialization function (HBDeviceModuleInit) for Device DLL Module (path of the module in the plugins\devices dir)” is an expected message for any .dll plugin built with .Net.
Here’s why:
Housebot uses C++ invocation methods for dynamically loaded modules. So what it does is scan the plugins\devices directory for any .dll, loading each one and invoking the HBDeviceModuleInit interface.
If that interface is not present in that DLL, one gets the error message listed above.
The way the HBDotNet wrappers seem to operate (and I’m guessing here, as I don’t have sources) is to provide the following:
HBDotNetBridge.dll, which is placed in the plugins\devices folder is the ‘glue’ between the standard windows interfaces and the .Net invocation world.
So it implements the required HouseBot interfaces, including HBDeviceModuleInit.
It is during that invocation, that it [likely] does the following:
Load the helper library HBDotNet.dll from the app directory, bind to it and then scans the plugins\devices directory looking for .Net compliant DLL’s and loading and initializing them in turn.
The HDotnetBridge.dll is essentially a loader and a glue that provides the right interface to HB and maps these to corresponding .Net implementations in either HBDotnet.DLL or the subclasses implemented in your .Net DLL.
So to recap, the \plugins\devices directory gets scanned and ALL DLL’s present are opened twice, once by Housebot, and once by the HBDotNetbridge.
When Housebot encounters a .Net dll, it will generate that tracing error, but no problem, that’s expected.
A nice enhancement to HBDotNetBridge would be to add tracing of the names of the DLL’s it did load.
In the meantime, I found some information that should help.
First, the tracing error I listed above “Unable to find device initialization function (HBDeviceModuleInit) for Device DLL Module (path of the module in the plugins\devices dir)” is an expected message for any .dll plugin built with .Net.
Here’s why:
Housebot uses C++ invocation methods for dynamically loaded modules. So what it does is scan the plugins\devices directory for any .dll, loading each one and invoking the HBDeviceModuleInit interface.
If that interface is not present in that DLL, one gets the error message listed above.
The way the HBDotNet wrappers seem to operate (and I’m guessing here, as I don’t have sources) is to provide the following:
HBDotNetBridge.dll, which is placed in the plugins\devices folder is the ‘glue’ between the standard windows interfaces and the .Net invocation world.
So it implements the required HouseBot interfaces, including HBDeviceModuleInit.
It is during that invocation, that it [likely] does the following:
Load the helper library HBDotNet.dll from the app directory, bind to it and then scans the plugins\devices directory looking for .Net compliant DLL’s and loading and initializing them in turn.
The HDotnetBridge.dll is essentially a loader and a glue that provides the right interface to HB and maps these to corresponding .Net implementations in either HBDotnet.DLL or the subclasses implemented in your .Net DLL.
So to recap, the \plugins\devices directory gets scanned and ALL DLL’s present are opened twice, once by Housebot, and once by the HBDotNetbridge.
When Housebot encounters a .Net dll, it will generate that tracing error, but no problem, that’s expected.
A nice enhancement to HBDotNetBridge would be to add tracing of the names of the DLL’s it did load.
_______
Jonathan
Jonathan
-
- HouseBot Special Member
- Posts: 409
- Joined: Tue Jul 13, 2004 9:13 am
- Location: Tigard, OR
Re: Wrapper for C# plugin development!
I realized that I actually have the source for the project on the laptop I took with me on vacation! Peter had previously given me permission to post this so here it is. There are two zip files. One contains the original source as Peter sent me and one contains my current build.
Peter and I fixed a number of issues when I was first testing this. I was just learning C# at the time though so the changes I made may not have been the best. This will allow you to compare the original and the source to see what I changed (I never made any changes to the bridge code). If any of you make changes I would appreciate it if you could send them to me so I can incorporate them back into my code.
-- Dave
Peter and I fixed a number of issues when I was first testing this. I was just learning C# at the time though so the changes I made may not have been the best. This will allow you to compare the original and the source to see what I changed (I never made any changes to the bridge code). If any of you make changes I would appreciate it if you could send them to me so I can incorporate them back into my code.
-- Dave
- Attachments
-
- HBDotNet (updated).zip
- (86.06 KiB) Downloaded 1469 times
-
- HBDotNet_src.zip
- (973.21 KiB) Downloaded 1474 times
Re: Wrapper for C# plugin development!
Dave, thanks a lot. This really helps.
Will keep you appraised of any tweaks.
Will keep you appraised of any tweaks.
_______
Jonathan
Jonathan
Re: Wrapper for C# plugin development!
Hi All,
I have made a WOL device so that I can make my bedsite PC WakeUp when needed. For this I used the HBDotNet Plug-in. Now I have two questions.
1. Why does my device give an error on startup. (Re-assinging for device [WakeOnLan]. Why are there multiple defaults?)
2. Why is the device property not updated from my code? It only updates when I change an other value.
I hope that someone can help me.
Thanks
Martijn.
The C#-code:
I have made a WOL device so that I can make my bedsite PC WakeUp when needed. For this I used the HBDotNet Plug-in. Now I have two questions.
1. Why does my device give an error on startup. (Re-assinging for device [WakeOnLan]. Why are there multiple defaults?)
2. Why is the device property not updated from my code? It only updates when I change an other value.
I hope that someone can help me.
Thanks
Martijn.
The C#-code:
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using HBDotNet;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Globalization;
namespace WakeupOnLan
{
[HBDevice("WakeOnLan")]
public class Class1 : HBDeviceBase
{
private Thread _thread;
public override bool OnInit(bool enabled)
{
if (enabled) OnEnable();
return base.OnInit(enabled);
}
public override void OnShutdown()
{
if (_thread != null) _thread.Abort();
base.OnShutdown();
}
public override bool OnRegisterProperties()
{
Properties.Add(new HBProperty("Mac address", "Mac address", true, "00301BBDF0CE", eIOType.ioInputAndOutput, true, true, true, false, ePropertyType.ptAlpha, ""));
Properties.Add(new HBProperty("Host name", "Host name", true, "", eIOType.ioInputAndOutput, true, true, true, false, ePropertyType.ptAlpha, ""));
Properties.Add(new HBProperty("Slave status", "Slave status", false, "Standby", eIOType.ioInputAndOutput, true, true, true, false, ePropertyType.ptAlpha, ""));
HBModule.CreateDevicePropertyValue("Slave status", "Running");
HBModule.CreateDevicePropertyValue("Slave status", "Standby");
HBModule.CreateDevicePropertyValue("Slave status", "Off");
Properties.Add(new HBProperty("Action", "Action", false, "Idle", eIOType.ioInputAndOutput, true, true, true, false, ePropertyType.ptAlpha, ""));
HBModule.CreateDevicePropertyValue("Action", "WOL");
HBModule.CreateDevicePropertyValue("Action", "Idle");
return base.OnRegisterProperties();
}
public override bool OnEnable()
{
_thread = new Thread(ThreadFunc);
_thread.Start();
return base.OnEnable();
}
public override bool OnDisable()
{
if (_thread != null) _thread.Abort();
_thread = null;
return base.OnDisable();
}
public override void OnAboutBox()
{
MessageBox.Show("This plugin enables Wakeup On LAN for Housebot using Magic Packet");
}
protected override bool OnPropertyChangeRequest(HBDotNet.HBProperty hbProperty, string newValue)
{
if (hbProperty.Name == "Action" && newValue == "WOL")
{
string macAddr = Properties.GetPropertyByName("Mac address").CurrentValue;
// Convert MAC address to Hex bytes
long value = long.Parse(macAddr, NumberStyles.HexNumber, CultureInfo.CurrentCulture.NumberFormat);
byte[] macBytes = BitConverter.GetBytes(value);
Array.Reverse(macBytes);
byte[] macAddress = new byte[6];
for (int i = 0; i <= 5; i++)
macAddress[i] = macBytes[i + 2];
//Construct the Magic packet
List<byte> packet = new List<byte>();
//Trailer of 6 FF packets
for (int i = 0; i < 6; i++)
packet.Add(0xFF);
//Repeat the MAC address (which is 6 bytes) 16 times
for (int i = 0; i < 16; i++)
packet.AddRange(macAddress);
//Send the Magic packet to broadcast address
UdpClient client = new UdpClient();
//Any UDP port will work. We use 7 here.
client.Connect("192.168.1.255", 7);
client.Send(packet.ToArray(), packet.Count);
}
Properties.GetPropertyByName("Action").CurrentValue = "Idle";
return base.OnPropertyChangeRequest(hbProperty, newValue);
}
public void ThreadFunc()
{
}
}
}
-
- HouseBot Special Member
- Posts: 409
- Joined: Tue Jul 13, 2004 9:13 am
- Location: Tigard, OR
Re: Wrapper for C# plugin development!
Hi Martijn,
You have two default properties because you set the "Default" parameter to true for the first two properties (it's the third parameter in the HBProperty call). There should only be ONE default property per device.
I'm not exactly sure what you are asking in question 2. Which property are you referring to and what are you expecting to happen?
== Dave
You have two default properties because you set the "Default" parameter to true for the first two properties (it's the third parameter in the HBProperty call). There should only be ONE default property per device.
I'm not exactly sure what you are asking in question 2. Which property are you referring to and what are you expecting to happen?
== Dave
Re: Wrapper for C# plugin development!
Hi Dave.
Thanks.
Propably this is a novice question. In my code I set the Property Action to Idle. HB only refreses this after I change a other device setting.
It there a reference document?
Martijn
Thanks.
Propably this is a novice question. In my code I set the Property Action to Idle. HB only refreses this after I change a other device setting.
Code: Select all
Properties.GetPropertyByName("Action").CurrentValue = "Idle";
Martijn
Re: Wrapper for C# plugin development!
There appears to be a problem with initial device creation if you are trying to allow a user to populate property values via the set-up dialog box on initial device creation. I am able to create one device using the dialog box, but if I try to create a second device with a different name, HB crashes as you are going through and setting the initial property values via the dialog box. The problem is in the following sub:
The work-around is to not use the dialog boxes for initial property value input. I can get multiple devices created if I simply leave the dialog text out of the Properties.Add call:
If anyone has fixed this problem with the HBDotNet.dll, please post an updated copy. I am using the latest copy posted with a creation date of 10/30/2009.
Osler
Code: Select all
Public Overloads Overrides Function OnRegisterProperties() As Boolean
Properties.Add(New HBProperty("TCIPAddress", "TCIPAddress", False, "0.0.0.0", eIOType.ioInputAndOutput, True, _
True, True, False, ePropertyType.ptAlpha, "Input the IP Address."))
Return MyBase.OnRegisterProperties()
End Function
Code: Select all
Public Overloads Overrides Function OnRegisterProperties() As Boolean
Properties.Add(New HBProperty("TCIPAddress", "TCIPAddress", False, "0.0.0.0", eIOType.ioInputAndOutput, True, _
True, True, False, ePropertyType.ptAlpha, ""))
Osler