2 using System.Collections.Generic;
4 using System.Runtime.InteropServices;
35 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
36 private static extern void PacSetCallbacks(PAC_ATTACHED_CALLBACK pacAttachedCallback, PAC_REMOVED_CALLBACK pacRemovedCallback);
38 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
39 private static extern int PacInitialize();
41 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
42 private static extern void PacShutdown();
44 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
45 [
return: MarshalAs(UnmanagedType.Bool)]
46 private static extern bool PacSetLEDStates(
int Index, ushort data);
48 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
49 [
return: MarshalAs(UnmanagedType.Bool)]
50 private static extern bool PacSetLEDState(
int Index,
int port, [MarshalAs(UnmanagedType.Bool)]
bool state);
52 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
53 [
return: MarshalAs(UnmanagedType.Bool)]
54 private static extern bool Pac64SetLEDStates(
int Index,
int group, byte data);
56 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
57 [
return: MarshalAs(UnmanagedType.Bool)]
58 private static extern bool Pac64SetLEDState(
int Index,
int group,
int port, [MarshalAs(UnmanagedType.Bool)]
bool state);
60 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
61 private static extern bool Pac64SetLEDStatesRandom(
int Index);
63 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
64 [
return: MarshalAs(UnmanagedType.Bool)]
65 private static extern bool Pac64SetLEDIntensities(
int Index, byte[] data);
67 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
68 [
return: MarshalAs(UnmanagedType.Bool)]
69 private static extern bool Pac64SetLEDIntensity(
int Index,
int port, byte intensity);
71 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
72 [
return: MarshalAs(UnmanagedType.Bool)]
73 private static extern bool Pac64SetLEDFadeTime(
int Index, byte fadeTime);
75 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
76 [
return: MarshalAs(UnmanagedType.Bool)]
77 private static extern bool Pac64SetLEDFlashSpeeds(
int Index, byte flashSpeed);
79 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
80 [
return: MarshalAs(UnmanagedType.Bool)]
81 private static extern bool Pac64SetLEDFlashSpeed(
int Index,
int port, byte flashSpeed);
83 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
84 [
return: MarshalAs(UnmanagedType.Bool)]
85 private static extern bool Pac64StartScriptRecording(
int Index);
87 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
88 [
return: MarshalAs(UnmanagedType.Bool)]
89 private static extern bool Pac64StopScriptRecording(
int Index);
91 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
92 [
return: MarshalAs(UnmanagedType.Bool)]
93 private static extern bool Pac64SetScriptStepDelay(
int Index, byte stepDelay);
95 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
96 [
return: MarshalAs(UnmanagedType.Bool)]
97 private static extern bool Pac64RunScript(
int Index);
99 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
100 [
return: MarshalAs(UnmanagedType.Bool)]
101 private static extern bool Pac64ClearFlash(
int Index);
103 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
104 [
return: MarshalAs(UnmanagedType.Bool)]
105 private static extern bool Pac64SetDeviceId(
int Index,
int newId);
107 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
108 private static extern int PacGetDeviceType(
int Index);
110 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
111 private static extern int PacGetVendorId(
int Index);
113 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
114 private static extern int PacGetProductId(
int Index);
116 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
117 private static extern int PacGetVersionNumber(
int Index);
119 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
120 private static extern void PacGetVendorName(
int Index, StringBuilder VendorName);
122 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
123 private static extern void PacGetProductName(
int Index, StringBuilder ProductName);
125 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
126 private static extern void PacGetSerialNumber(
int Index, StringBuilder SerialNumber);
128 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
129 private static extern void PacGetDevicePath(
int Index, StringBuilder DevicePath);
131 [DllImport(
"PacDrive.dll", CallingConvention = CallingConvention.StdCall)]
132 [
return: MarshalAs(UnmanagedType.Bool)]
133 private static extern bool PacProgramUHID(
int Index, StringBuilder FileName);
138 private delegate
void PAC_ATTACHED_CALLBACK(
int Index);
139 private delegate
void PAC_REMOVED_CALLBACK(
int Index);
141 public delegate
void PacAttachedDelegate(
int Index);
142 public delegate
void PacRemovedDelegate(
int Index);
144 public event PacAttachedDelegate OnPacAttached = null;
145 public event PacRemovedDelegate OnPacRemoved = null;
147 [MarshalAs(UnmanagedType.FunctionPtr)]
148 PAC_ATTACHED_CALLBACK PacAttachedCallbackPtr = null;
150 [MarshalAs(UnmanagedType.FunctionPtr)]
151 PAC_REMOVED_CALLBACK PacRemovedCallbackPtr = null;
154 private int m_numDevices = 0;
157 private static readonly Lazy<PacDriveSingleton> lazy =
new Lazy<PacDriveSingleton>(() =>
new PacDriveSingleton());
166 PacAttachedCallbackPtr =
new PAC_ATTACHED_CALLBACK(PacAttachedCallback);
167 PacRemovedCallbackPtr =
new PAC_REMOVED_CALLBACK(PacRemovedCallback);
169 PacSetCallbacks(PacAttachedCallbackPtr, PacRemovedCallbackPtr);
173 private void PacAttachedCallback(
int Index)
177 if (OnPacAttached != null)
178 OnPacAttached(Index);
181 private void PacRemovedCallback(
int Index)
185 if (OnPacRemoved != null)
189 private void Initialize()
191 m_numDevices = PacInitialize();
203 #region PacDrive & UHID Led methods
207 return PacSetLEDStates(Index, Data);
212 return PacSetLEDState(Index, Port, State);
219 for (
int i = 0; i < Data.Length; i++)
220 if (Data[i]) dataSend |= (ushort)(1 << i);
222 return PacSetLEDStates(Index, dataSend);
226 #region PacLed64 methods
229 return Pac64SetLEDState(Index, Group, Port, State);
234 return Pac64SetLEDStates(Index, Group, Data);
241 for (
int i = 0; i < 8; i++)
243 OK &= Pac64SetLEDStates(Index, i + 1, Data[i]);
252 for (
int i = 0; i < Data.Length; i++)
253 if (Data[i]) dataSend |= (byte)(1 << i);
255 return Pac64SetLEDStates(Index, Group, dataSend);
260 return Pac64SetLEDStatesRandom(Index);
265 return Pac64SetLEDIntensities(Index, Data);
270 return Pac64SetLEDIntensity(Index, Port, Intensity);
275 return Pac64SetLEDFadeTime(Index, FadeTime);
280 return Pac64SetLEDFlashSpeeds(Index, (byte)FlashSpeed);
285 return Pac64SetLEDFlashSpeed(Index, Port, (byte)FlashSpeed);
290 return Pac64StartScriptRecording(Index);
295 return Pac64StopScriptRecording(Index);
300 return Pac64SetScriptStepDelay(Index, StepDelay);
305 return Pac64RunScript(Index);
310 return Pac64ClearFlash(Index);
315 return Pac64SetDeviceId(Index, NewId);
320 string S = GetDevicePath(Index);
323 int IdPos = S.IndexOf(
"&pid_140");
331 if (
int.TryParse(S.Substring(IdPos, 1), out Id))
342 for (
int i = 0; i < NumDevices; i++)
344 if (PacLed64GetDeviceId(i) == Id)
361 return PacGetVendorId(Index);
366 return PacGetProductId(Index);
371 return PacGetVersionNumber(Index);
376 StringBuilder sb =
new StringBuilder(256);
378 PacGetVendorName(Index, sb);
380 return sb.ToString();
385 StringBuilder sb =
new StringBuilder(256);
387 PacGetProductName(Index, sb);
389 return sb.ToString();
394 StringBuilder sb =
new StringBuilder(256);
396 PacGetSerialNumber(Index, sb);
398 return sb.ToString();
403 StringBuilder sb =
new StringBuilder(256);
405 PacGetDevicePath(Index, sb);
407 return sb.ToString();
416 List<int> L =
new List<int>();
419 for (
int i = 0; i < NumDevices; i++)
423 L.Add(PacLed64GetDeviceId(i));
438 List<int> L =
new List<int>();
441 for (
int i = 0; i < NumDevices; i++)
461 public int NumDevices
463 get {
return m_numDevices; }
bool PacLed64StopScriptRecording(int Index)
int PacLed64GetIndexForDeviceId(int Id)
DeviceType GetDeviceType(int Index)
bool PacLed64ClearFlash(int Index)
bool PacLed64SetLEDStates(int Index, int Group, bool[] Data)
Singleton version of the PacDrive class found in the PacDrive SDK.
bool PacLed64SetScriptStepDelay(int Index, byte StepDelay)
bool PacLed64SetLEDFlashSpeed(int Index, int Port, FlashSpeed FlashSpeed)
bool PacLed64SetLEDStatesRandom(int Index)
List< int > PacLed64GetIdList()
Gets the Ids of the PacLed64 controllers which are connected to the system.
string GetProductName(int Index)
int PacLed64GetDeviceId(int Index)
string GetVendorName(int Index)
int GetVendorId(int Index)
bool PacLed64SetLEDStates(int Index, byte[] Data)
int GetProductId(int Index)
The PacDrive is a simple output controller with 16 digital/on off outputs.
bool PacDriveUHIDSetLEDStates(int Index, ushort Data)
bool PacDriveUHIDSetLEDState(int Index, int Port, bool State)
int GetVersionNumber(int Index)
bool PacLed64SetLEDState(int Index, int Group, int Port, bool State)
int PacDriveGetIndex()
Gets the Ids of the first PacDrive controller which is connected to the system.
bool PacLed64SetLEDIntensities(int Index, byte[] Data)
bool PacLed64SetLEDFlashSpeeds(int Index, FlashSpeed FlashSpeed)
bool PacLed64StartScriptRecording(int Index)
bool PacDriveUHIDSetLEDStates(int Index, bool[] Data)
bool PacLed64SetLEDIntensity(int Index, int Port, byte Intensity)
string GetSerialNumber(int Index)
bool PacLed64RunScript(int Index)
bool PacLed64SetDeviceId(int Index, int NewId)
string GetDevicePath(int Index)
bool PacLed64SetLEDFadeTime(int Index, byte FadeTime)
bool PacLed64SetLEDStates(int Index, int Group, byte Data)