I am looking for some tips on the following issue.
I have several classes that are wrappers for many parts of USB equipment - such as programmable bus power supplies, label printers, data acquisition modules, USB to serial converters, etc.
Each of these classes implements the IHardwareDevice interface, defined below ...
public interface IHardwareDevice { string VID { get; } string PID { get; } } // Example IHardwareDevice implementation public class PowerSupply : IHardwareDevice { public string VID { get { return "0123"; } } public string PID { get { return "3210"; } } }
This interface allows each USB device to specify its own vendor and product identifier.
I also have a static DeviceManager class that uses the SetupDixxx device installation functions to detect the presence of any of the USB devices listed above. This class also has the ability to enable or disable the specified device.
A brief overview of the class is as follows:
public static class DeviceManager { public static T Find<T>() where T : IHardwareDevice, new() {
I considered using HardwareDeviceAttribute to decorate each class (the attribute must contain VID and PID), but I decided against this.
In addition, I want each of the USB device classes to have its own properties - for example, PortName for a serial USB converter or PathName for a HID device (to allow CreateFile, ReadFile and WriteFile), etc. All of them should be filled out from the values ββread from the registry branch of individual devices (again, using the calls to the SetupDixxx function). I reviewed the IHardwareDevice interface IHardwareDevice to enable the InitializeDevice method, which will be called by DeviceManager, but this will require access to several unmanaged structures in the hardware class, which seems undesirable. Another option is to decorate the user properties of the USB device, indicating which of them should be filled with DeviceManager .
Now, probably, my question will be - is this or will it be a good implementation of what I want to achieve? Are there any obvious obvious improvements that I'm missing? All the code works, so from the point of view of suitability this is absolutely normal, but is there a more efficient and effective implementation - will the Factory template (or any other) help me in this case?
Thanks in advance, K