I'm working on a plugin which reads the wattage from my APC. I'm not too familiar with C#/Visual C++ & Visual Studio so please forgive me if this is a noob question...
What I'm trying to do is use LibUsbDotNet to read values from my APC and then communicate them to my rainmeter skin. I created a simple C# test app which uses the LibUsbDotNet library to read the values and it works! The next step was to make a rainmeter Plugin...
I created this simple plugin here to do that for me:
Code: Select all
using System;
using System.Runtime.InteropServices;
using Rainmeter;
using LibUsbDotNet;
using LibUsbDotNet.Main;
namespace APCPlugin
{
internal class Measure
{
public static UsbDevice APC;
internal Measure()
{
APC = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(1309, 2));
}
internal void Reload(Rainmeter.API api, ref double maxValue)
{
APC = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(1309, 2));
}
internal double Update()
{
if (APC != null)
{
int transferred = 0;
byte[] buffer = new byte[2];
UsbSetupPacket setup = new UsbSetupPacket(0xA1, 0x01, 0x0350, 0, 0x0005);
bool result = APC.ControlTransfer(ref setup, buffer, 0x0040, out transferred);
return 865 * buffer[1] / 100; //super hardcoded for my APC, it works I've tested in a separate application
}
return 5.0; //Return this for testing, just to see if any value is reported
}
}
public static class Plugin
{
[DllExport]
public static void Initialize(ref IntPtr data, IntPtr rm)
{
data = GCHandle.ToIntPtr(GCHandle.Alloc(new Measure()));
}
[DllExport]
public static void Finalize(IntPtr data)
{
GCHandle.FromIntPtr(data).Free();
}
[DllExport]
public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
{
Measure measure = (Measure)GCHandle.FromIntPtr(data).Target;
measure.Reload(new Rainmeter.API(rm), ref maxValue);
}
[DllExport]
public static double Update(IntPtr data)
{
Measure measure = (Measure)GCHandle.FromIntPtr(data).Target;
return measure.Update();
}
}
}
Code: Select all
'Rainmeter.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Matt\AppData\Roaming\Rainmeter\Plugins\APC.dll'. Module was built without symbols.
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in APC.dll
Additional information: Could not load file or assembly 'LibUsbDotNet, Version=2.2.8.104, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Is there something I've done that obviously wrong in the code, or am I missing something in the bigger picture here? Thanks for the help!