/// <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);
        }
Exemplo n.º 2
0
        public DelcomBuildLight()
        {
            var deviceName      = new StringBuilder(Delcom.MAXDEVICENAMELEN);
            var doesDeviceExist = Delcom.DelcomGetNthDevice(Delcom.USBDELVI, 0, deviceName);

            if (doesDeviceExist == 0)
            {
                throw new IOException("Device does not exist");
            }
            _device = Delcom.DelcomOpenDevice(deviceName, 0);
        }
        public static uint OpenDelcomDevice()
        {
            int           Result;
            uint          hUSB;
            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.
            Result = Delcom.DelcomGetNthDevice(Delcom.USBDELVI, 0, DeviceName);

            hUSB = Delcom.DelcomOpenDevice(DeviceName, 0);                      // open the device

            return(hUSB);
        }