Beispiel #1
0
        /// <summary>
        /// Called when the device is INITIALLY connected.  This sets the mini device to accessory mode,
        /// at which point the mini device disconnects.
        /// </summary>
        private Boolean DeviceInitiallyConnected()
        {
            lock (DeviceInitSyncLock)
            {
                TransportLog("Entering DeviceInitiallyConnected: " + Thread.CurrentThread.GetHashCode());
                Boolean initialized = false;

                if (MyUsbDevice == null || !MyUsbDevice.IsOpen)
                {
                    UsbDevice TempMyUsbDevice = null;
                    try
                    {
                        // Find and open the usb device.
                        foreach (UsbDeviceFinder merchUsbFinder in MerchantUsbFinders)
                        {
                            TempMyUsbDevice = UsbDevice.OpenUsbDevice(merchUsbFinder);

                            if (TempMyUsbDevice != null) // if it matches, go on...
                            {
                                break;
                            }
                        }

                        // If the device is open and ready
                        if (TempMyUsbDevice != null && TempMyUsbDevice.IsOpen)
                        {
                            initialized = MiniInitializer.initializeDeviceConnectionAccessoryMode(TempMyUsbDevice);
                        }
                        else
                        {
                            TransportLog("Error finding device in merchant mode");
                        }
                    }
                    catch (Exception ex)
                    {
                        TransportLog(ex.Message);
                    }
                    TransportLog("Exiting DeviceInitiallyConnected initialized=" + initialized);
                }
                else
                {
                    initialized = true;
                }

                if (initialized)
                {
                    onDeviceConnected();
                }
                return(initialized);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when the device is INITIALLY connected.  This sets the mini device to accessory mode,
        /// at which point the mini device disconnects.
        /// </summary>
        private bool DeviceInitiallyConnected()
        {
            lock (DeviceInitSyncLock)
            {
                TransportLog("Entering DeviceInitiallyConnected: " + Thread.CurrentThread.GetHashCode());
                Boolean initialized = false;

                if (MyUsbDevice == null || !MyUsbDevice.IsOpen || !MyUsbDevice.UsbRegistryInfo.IsAlive)
                {
                    // If the device is open and  we no longer have this device in the bus enumeration, close it to try to
                    // get it back to a sane state
                    if (MyUsbDevice != null && !MyUsbDevice.UsbRegistryInfo.IsAlive)
                    {
                        if (MyUsbDevice.IsOpen)
                        {
                            MyUsbDevice.Close();
                        }
                    }

                    UsbDevice TempMyUsbDevice = null;
                    try
                    {
                        // Find and open the usb device.
                        foreach (UsbDeviceFinder merchUsbFinder in MerchantUsbFinders.ToArray())
                        {
                            TempMyUsbDevice = UsbDevice.OpenUsbDevice(merchUsbFinder);

                            if (TempMyUsbDevice != null) // if it matches, go on...
                            {
                                break;
                            }
                        }

                        // If the device is open and ready
                        if (TempMyUsbDevice != null && TempMyUsbDevice.IsOpen)
                        {
                            initialized = MiniInitializer.initializeDeviceConnectionAccessoryMode(TempMyUsbDevice);
                        }
                        else
                        {
                            TransportLog("Error finding device in merchant mode");
                        }
                    }
                    catch (Exception ex)
                    {
                        TransportLog(ex.Message);
                        Console.WriteLine("DeviceInitiallyConnected : " + ex.Message);
                    }
                    TransportLog("Exiting DeviceInitiallyConnected initialized=" + initialized);
                }
                else
                {
                    initialized = true;
                }

                if (initialized)
                {
                    onDeviceConnected();
                }

                return(initialized);
            }
        }