/// <summary> /// Find and open a Delcom device. this.deviceHandle is set upon success. /// </summary> /// <returns>true on success.</returns> private bool OpenDevice() { if (this.deviceHandle != InvalidDevcieHandle) { this.CloseDevice(); } StringBuilder deviceName = new StringBuilder(Delcom.MAXDEVICENAMELEN); // Search for the first match USB device, For USB IO Chips use Delcom.USBIODS // With Generation 2 HID devices, you can pass a TypeId of 0 to open any Delcom device. int findResult = Delcom.DelcomGetNthDevice(Delcom.USBDELVI, 0, deviceName); if (findResult == 0) { Trace.TraceError("Device was not found"); } else { uint newDeviceHandle = Delcom.DelcomOpenDevice(deviceName, 0); if (newDeviceHandle == InvalidDevcieHandle) { Trace.TraceError("Device was found, but failed to be connected. device = {0}", deviceName.ToString()); } else { this.deviceHandle = newDeviceHandle; // Disable auto confirmation mode where the buzzer will sound when the button is pressed. Delcom.DelcomEnableAutoConfirm(this.deviceHandle, 0); } } return(this.deviceHandle != InvalidDevcieHandle); }
/// <summary> /// Constructor /// </summary> /// <param name="stateMachineInputCallback">delegate to call when there's an event to report</param> public DelcomLight(MainAppLogic.EnqueueStateMachineInput stateMachineInputCallback, TimeSpan holdTime) { hUSB = DelcomLightWrapper.TryOpeningDelcomDevice(); Delcom.DelcomEnableAutoConfirm(hUSB, 0); // Make sure we always start turned off DelcomLightWrapper.DelcomLEDAllAction(hUSB, DelcomLightWrapper.LightStates.Off); // remember the delegate so we can invoke when we get input this.stateMachineInputCallback = stateMachineInputCallback; //Initialize hold threshold from argument passed from Main this.holdThreshold = holdTime; // start a background thread to poll the device for input BackgroundWorker bgw1 = new BackgroundWorker(); bgw1.DoWork += delegate { this.BackgroundPollingWorker(); }; bgw1.RunWorkerAsync(); }