Ejemplo n.º 1
0
        /// <summary>
        /// Put up a dialog box to show information about RedRat3.
        /// </summary>
        private void rr3InfoMenuItem_Click(object sender, System.EventArgs e)
        {
            // Obtain and display info about the RR3.
            string msg = null;

            if (redRat3 == null)
            {
                msg = "No RedRat3 connected.";
            }
            else
            {
                // Obtain information from RR3 to display....
                USBDeviceInfo devInfo = (USBDeviceInfo)redRat3.DeviceInformation;

                StringBuilder sb = new StringBuilder();
                sb.Append(devInfo.ToString() + "\n");
                sb.Append("Hardware Version: " + devInfo.ProductName + "." + devInfo.ProductVersion + "\n");
                sb.Append("Firmware Version: " + redRat3.FirmwareVersion);
                sb.Append("\nSerial Number: " + devInfo.SerialNo);
                sb.Append("\nLocation: " + redRat3.LocationInformation);

                msg = sb.ToString();
            }

            MessageBox.Show(msg,
                            "RedRat3 Info.",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the device via LibUSB, and sets the refresh interval of the controller data
        /// </summary>
        /// <param name="Interval">The interval that the device is polled for information.</param>
        public void Init(int Interval)
        {
            //ErrorCode ec = ErrorCode.None;


            //HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\USB\VID_0A7B&PID_D000\6&688a3b8&0&1\Device Parameters\DeviceInterfaceGUIDs
            USBDeviceInfo[] details = USBDevice.GetDevices("{5C2B3F1A-E9B8-4BD6-9D19-8A283B85726E}");
            USBDeviceInfo   match   = details.First(info => info.VID == 0x0A7B && info.PID == 0xD000);

            MyUsbDevice = new USBDevice(match);
            reader      = MyUsbDevice.Interfaces.First().InPipe;
            writer      = MyUsbDevice.Interfaces.First().OutPipe;

            byte[] buf = new byte[64];

            reader.Read(buf);//can't remember why I do this.

            ButtonMasks.InitializeMasks();

            SetPollingInterval(Interval);
            pollTimer.Elapsed += new ElapsedEventHandler(pollTimer_Elapsed);
            pollTimer.Start();

            TestLEDs();
            if (updateGearLights)
            {
                GearLightsRefresh((int)unchecked ((sbyte)buf[25]));
            }
            RefreshLEDState();
        }
        /// <summary>
        /// Initializes the device via LibUSB, and sets the refresh interval of the controller data
        /// </summary>
        /// <param name="Interval">The interval that the device is polled for information.</param>
        public void Init(int Interval)
        {
            //ErrorCode ec = ErrorCode.None;

            //zadig creates a new device GUID everytime you install, so I placed file in
            //C:\Users\salds_000\Documents\Visual Studio 2013\Projects\steel_batallion-64\steelbattalionnet\winusb\usb_driver
            //check inf file for guid. Right clicking the inf file installs it.

            //after installation you can find this in regedit
            //HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\USB\VID_0A7B&PID_D000\6&688a3b8&0&1\Device Parameters\DeviceInterfaceGUIDs
            USBDeviceInfo[] details = USBDevice.GetDevices("{5C2B3F1A-E9B8-4BD6-9D19-8A283B85726E}");
            USBDeviceInfo   match   = details.First(info => info.VID == 0x0A7B && info.PID == 0xD000);

            MyUsbDevice = new USBDevice(match);
            reader      = MyUsbDevice.Interfaces.First().InPipe;
            writer      = MyUsbDevice.Interfaces.First().OutPipe;

            byte[] buf = new byte[64];

            reader.Read(buf);//can't remember why I do this.

            ButtonMasks.InitializeMasks();

            SetPollingInterval(Interval);
            pollTimer.Elapsed += new ElapsedEventHandler(pollTimer_Elapsed);
            pollTimer.Start();

            TestLEDs();
            if (updateGearLights)
            {
                GearLightsRefresh((int)unchecked ((sbyte)buf[25]));
            }
            RefreshLEDState();
        }
Ejemplo n.º 4
0
        internal WinusbAppiDev(USBDeviceInfo di)
        {
            // TODO: Отлавливать исключения WinUsbNet
            try
            {
                Device     = new USBDevice(di);
                DevicePath = di.DevicePath;

                ReadPipe = Device.Pipes.First(p => p.IsIn);
                ReadPipe.Policy.PipeTransferTimeout = 100;
                ReadPipe.Policy.AutoClearStall      = true;
                ReadPipe.Flush();

                WritePipe = Device.Pipes.First(p => p.IsOut);
                WritePipe.Policy.PipeTransferTimeout = 100;

                lock (OpenedDevicesLocker)
                {
                    OpenedDevices.Add(this);
                }
            }
            catch (USBException e)
            {
                throw new AppiConnectoinException(e);
            }
        }
Ejemplo n.º 5
0
 private void DeviceCombo_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (this.deviceCombo.SelectedItem != null)
     {
         this.selectedDevice = (USBDeviceInfo)this.deviceCombo.SelectedItem;
     }
 }
Ejemplo n.º 6
0
        public void FindDeviceByDeviceInterfaceGuid()
        {
            USBDeviceInfo[] dies = USBDevice.GetDevices("{AA40624D-0F4B-4F4F-8E23-BA4209EE3AF2}");
            USBDeviceInfo   di   = dies[0];
            USBDevice       dev  = new USBDevice(di.DevicePath);

            Assert.AreEqual("Konvolucio Bt", dev.Descriptor.Manufacturer);
            dev.Dispose();
        }
 private void Button4_Click(object sender, EventArgs e)
 {
     string[] dinfo = { };
     deviceInfoLabel.Text = "No trigger device\r\n(Unplug and) plug in desired trigger device";
     devinfo     = dinfo;
     currentDevs = USBDeviceInfo.GetUSBDevices();
     prevDevs    = USBDeviceInfo.GetUSBDevices();
     resetDeviceButton.Enabled = false;
     usbFinder.Enabled         = true;
 }
 public void OnUSBDeviceInfoChanged(USBDeviceInfo deviceInfo)
 {
     if (DeviceInfo != deviceInfo)
     {
         LogInfo("USB Device Info changed");
         DeviceInfo = deviceInfo;
         if (IsCloseEnabled)
         {
             CloseAsync();
         }
     }
 }
Ejemplo n.º 9
0
        public void loadComboBoxUSBDeviceInfo()
        {
            this.comboBoxUSBDeviceInfo.Items.Clear();
            this.comboBoxUSBDeviceInfo.SelectedValuePath = "Key";
            this.comboBoxUSBDeviceInfo.DisplayMemberPath = "Value";

            foreach (USB usb in USBDeviceInfo.getDiskNames())
            {
                this.comboBoxUSBDeviceInfo.Items.Add(new KeyValuePair <string, string>(usb.deviceID, usb.deviceID + " " + usb.caption));
            }

            this.comboBoxUSBDeviceInfo.SelectedIndex = 0;
        }
Ejemplo n.º 10
0
        /*ExpectedMessage = "A szemaforhoz rendelt határidő lejárt. (A kivétel HRESULT-értéke: 0x80070079)")]*/
        public void ReadTimeoutTest()
        {
            Assert.Catch <System.Runtime.InteropServices.COMException>(() =>
            {
                USBDeviceInfo[] dies = USBDevice.GetDevices("{A5DCBF10-6530-11D2-901F-00C04FB951ED}");
                USBDeviceInfo di     = dies.FirstOrDefault(n => n.Manufacturer == "STMicroelectronics");
                USBDevice dev        = new USBDevice(di.DevicePath);

                dev.Pipes[0x81].Policy.PipeTransferTimeout = 1000;
                byte[] result = new byte[512];
                dev.Pipes[0x81].Read(result);
                dev.Dispose();
            });
        }
Ejemplo n.º 11
0
        public void SendCanMsg()
        {
            const byte CAN_MSG_EP_OUT_ADDR = 0x02;

            USBDeviceInfo[] dies = USBDevice.GetDevices("{AA40624D-0F4B-4F4F-8E23-BA4209EE3AF2}");
            USBDeviceInfo   di   = dies[0];

            byte[]    status = new byte[] { 0xAA, 0x55, 0xFF };
            USBDevice dev    = new USBDevice(di.DevicePath);

            dev.Pipes[CAN_MSG_EP_OUT_ADDR].Policy.PipeTransferTimeout = 1000;
            dev.Pipes[CAN_MSG_EP_OUT_ADDR].Write(status);
            dev.Dispose();
        }
Ejemplo n.º 12
0
            public USBDeviceInfo GetUSBDeviceInfoForDebugUnit(string reason)
            {
                USBDeviceInfo[] details = USBDevice.GetDevices(ARM_LTD_WINUSB_GUID);
                LogInfo("{0}. Enumerated {1} ARM LTD device(s)", reason, details.Length);
                if (details.Length > 0)
                {
                    foreach (USBDeviceInfo detail in details)
                    {
                        LogInfo("USBDeviceInfo.DevicePath {0}", detail.DevicePath);
                    }
                }
                USBDeviceInfo match = details.FirstOrDefault(info => info.VID == ARM_LTD_VID && info.PID == ARM_LTD_PID);

                return(match);
            }
Ejemplo n.º 13
0
        public void OpenClose()
        {
            USBDeviceInfo[] dies = USBDevice.GetDevices("{A5DCBF10-6530-11D2-901F-00C04FB951ED}");
            USBDeviceInfo   di   = dies.FirstOrDefault(n => n.Manufacturer == "STMicroelectronics");
            USBDevice       dev  = new USBDevice(di.DevicePath);

            Assert.AreEqual("STMicroelectronics", dev.Descriptor.Manufacturer);
            dev.Dispose();
            dev = new USBDevice(di.DevicePath);
            Assert.AreEqual("STMicroelectronics", dev.Descriptor.Manufacturer);
            dev.Dispose();
            dev = new USBDevice(di.DevicePath);
            Assert.AreEqual("STMicroelectronics", dev.Descriptor.Manufacturer);
            dev.Dispose();
        }
Ejemplo n.º 14
0
        public void ScanPorts()
        {
            // find USB devices first, if possible (may not work with all Windows machines....!)
            string ArduinoPort = null;

            try
            {
                List <USBDeviceInfo> devices = new List <USBDeviceInfo>();
                var searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort");


                foreach (var device in searcher.Get())
                {
                    //devices.Add(new USBDeviceInfo(
                    USBDeviceInfo usbInfo = new USBDeviceInfo(
                        (string)device.GetPropertyValue("DeviceID"),
                        //(string)device.GetPropertyValue("PNPDeviceID"),
                        //(string)device.GetPropertyValue("Description"),
                        //(string)device.GetPropertyValue("Name")
                        //));
                        (string)device.GetPropertyValue("Name")
                        );
                    if (usbInfo.Name.Contains("rduino"))
                    {
                        ArduinoPort = usbInfo.DeviceID;
                    }
                }
            }
            catch
            { // well at leat we tried....
            }


            if (ArduinoPort != null)
            {
                _currentSerialSettings.PortName = ArduinoPort;
            }
            else
            {
                // Finding installed serial ports on hardware
                _currentSerialSettings.PortNameCollection = SerialPort.GetPortNames();
                // If serial ports is found, we select the first found
                if (_currentSerialSettings.PortNameCollection.Length > 0)
                {
                    _currentSerialSettings.PortName = _currentSerialSettings.PortNameCollection[0];
                }
            }
        }
Ejemplo n.º 15
0
 private void Timer1_Tick(object sender, EventArgs e)
 {
     prevDevs    = currentDevs;
     currentDevs = USBDeviceInfo.GetUSBDevices();
     if ((currentDevs != prevDevs) && (currentDevs.Count >= prevDevs.Count))
     {
         for (int i = 0; i < currentDevs.Count; i++)
         {
             if (!prevDevs.Contains(currentDevs[i]))
             {
                 string[] usbinfo = { currentDevs[i].DeviceID, currentDevs[i].PnpDeviceID, currentDevs[i].Description };
                 devinfo = usbinfo;
                 deviceInfoLabel.Text      = "Trigger device: " + devinfo[2] + "(Device ID: " + devinfo[0] + ")";
                 usbFinder.Enabled         = false;
                 resetDeviceButton.Enabled = true;
                 break;
             }
         }
     }
 }
Ejemplo n.º 16
0
        public void PipeWriteRead()
        {
            USBDeviceInfo[] dies = USBDevice.GetDevices("{A5DCBF10-6530-11D2-901F-00C04FB951ED}");
            USBDeviceInfo   di   = dies.FirstOrDefault(n => n.Manufacturer == "STMicroelectronics");
            USBDevice       dev  = new USBDevice(di.DevicePath);

            byte[] send = new byte[] {
                0xF1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };

            byte[] result = new byte[512];
            byte[] expect = new byte[] { 0x23, 0x80, 0x83, 0x04, 0x48, 0x37 };

            dev.Pipes[0x02].Write(send);
            int readLen = dev.Pipes[0x81].Read(result);

            Assert.AreEqual(expect.Length, readLen);

            dev.Dispose();
        }
Ejemplo n.º 17
0
 private void RadioButton16_CheckedChanged(object sender, EventArgs e)
 {
     if (usbRadio.Checked == true)
     {
         usbPanel.Visible = true;
         if (devinfo.Length == 0)
         {
             currentDevs               = USBDeviceInfo.GetUSBDevices();
             prevDevs                  = USBDeviceInfo.GetUSBDevices();
             usbFinder.Enabled         = true;
             resetDeviceButton.Enabled = false;
         }
         else
         {
             resetDeviceButton.Enabled = true;
         }
     }
     else
     {
         usbPanel.Visible = false;
     }
 }
Ejemplo n.º 18
0
        public void InitDevice(ushort vid, ushort pid)
        {
            this.vid = vid;
            this.pid = pid;

            USBDeviceInfo[] details = USBDevice.GetDevices(guid);
            if (details == null)
            {
                return;
            }

            try {
                deviceInfo = details.First(info => info.VID == vid && info.PID == pid);
                if (deviceInfo != null)
                {
                    device = new USBDevice(deviceInfo);
                    iface  = device.Interfaces.Find(USBBaseClass.HID);
                    enableNumLock();
                    StartMonitoring();
                }
            } catch (System.InvalidOperationException) {
                iface = null;
            }
        }
Ejemplo n.º 19
0
        void LumiaNotifier_Arrival(object sender, USBEvent e)
        {
            try
            {
                if ((e.DevicePath.IndexOf("VID_0421&", StringComparison.OrdinalIgnoreCase) >= 0) ||
                    (e.DevicePath.IndexOf("VID_045E&", StringComparison.OrdinalIgnoreCase) >= 0))
                {
                    if ((e.DevicePath.IndexOf("&PID_0660&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) ||
                        (e.DevicePath.IndexOf("&PID_0713&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) || // for Spec B
                        (e.DevicePath.IndexOf("&PID_0A01&MI_04", StringComparison.OrdinalIgnoreCase) >= 0))   // for Spec B (650)
                    {
                        CurrentInterface = PhoneInterfaces.Lumia_Label;
                        CurrentModel     = new NokiaPhoneModel(e.DevicePath);
                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        LogFile.Log("Mode: Label", LogType.FileAndConsole);
                        NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                    }
                    else if ((e.DevicePath.IndexOf("&PID_0661", StringComparison.OrdinalIgnoreCase) >= 0) ||
                             (e.DevicePath.IndexOf("&PID_06FC", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_06FC is for Lumia 930
                             (e.DevicePath.IndexOf("&PID_0A00", StringComparison.OrdinalIgnoreCase) >= 0))   // vid_045e & pid_0a00 & mi_03 = Lumia 950 XL normal mode
                    {
                        if (((USBNotifier)sender).Guid == OldCombiInterfaceGuid)
                        {
                            NewInterfaceWaitHandle.Reset();
                            if (USBDevice.GetDevices(NewCombiInterfaceGuid).Count() > 0)
                            {
                                return;
                            }
                            else
                            {
                                // Old combi-interface was detected, but new combi-interface was not detected.
                                // This could mean 2 things:
                                // - It is a WP80 phone, which has only this old combi-interface to talk to.
                                // - It is a WP81 / W10M phone, which has an unresponsive old combi-interface and we need to wait for the new combi-interface to arrive.
                                // We will wait maximum 1 sec for the new interface. If it doesn't arrive we will start talking on this old interface.
                                // We will start a new thread, because if this thread is blocked, no new devices will arrive.
                                string DevicePath = e.DevicePath;
                                ThreadPool.QueueUserWorkItem(s =>
                                {
                                    if (!NewInterfaceWaitHandle.WaitOne(1000))
                                    {
                                        // Waithandle not set.
                                        // So new interface did not arrive.
                                        // So we assume we need to talk to this old interface.

                                        CurrentInterface = PhoneInterfaces.Lumia_Normal;
                                        CurrentModel     = new NokiaPhoneModel(DevicePath);
                                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                                        LogFile.Log("Mode: Normal", LogType.FileAndConsole);
                                        NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                                    }
                                });
                            }
                        }
                        else
                        {
                            NewInterfaceWaitHandle.Set();

                            CurrentInterface = PhoneInterfaces.Lumia_Normal;
                            CurrentModel     = new NokiaPhoneModel(e.DevicePath);
                            LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                            LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                            LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                            LogFile.Log("Mode: Normal", LogType.FileAndConsole);
                            NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                        }
                    }
                    else if ((e.DevicePath.IndexOf("&PID_066E", StringComparison.OrdinalIgnoreCase) >= 0) ||
                             (e.DevicePath.IndexOf("&PID_0714", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_0714 is for Lumia 930
                             (e.DevicePath.IndexOf("&PID_0A02", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_045E&PID_0A02 is for Lumia 950
                             (e.DevicePath.IndexOf("&PID_05EE", StringComparison.OrdinalIgnoreCase) >= 0))   // VID_0421&PID_05EE is for early RX100
                    {
                        CurrentModel = new NokiaFlashModel(e.DevicePath);
                        ((NokiaFlashModel)CurrentModel).InterfaceChanged += InterfaceChanged;

                        FlashAppType type = FlashAppType.FlashApp;
                        try
                        {
                            type = ((NokiaFlashModel)CurrentModel).GetFlashAppType();
                            LogFile.Log("Flash App Type: " + type.ToString(), LogType.FileOnly);
                        }
                        catch
                        {
                            LogFile.Log("Flash App Type could not be determined, assuming " + type.ToString(), LogType.FileOnly);
                        }

                        switch (type)
                        {
                        case FlashAppType.BootManager:
                        {
                            CurrentInterface = PhoneInterfaces.Lumia_Bootloader;
                            LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                            LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                            LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                            LogFile.Log("Mode: Bootloader", LogType.FileAndConsole);
                            NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                            break;
                        }

                        case FlashAppType.FlashApp:
                        {
                            ((NokiaFlashModel)CurrentModel).DisableRebootTimeOut();
                            CurrentInterface = PhoneInterfaces.Lumia_Flash;
                            LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                            LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                            LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                            LogFile.Log("Mode: Flash", LogType.FileAndConsole);
                            NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                            break;
                        }

                        case FlashAppType.PhoneInfoApp:
                        {
                            CurrentInterface = PhoneInterfaces.Lumia_Bootloader;
                            LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                            LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                            LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                            LogFile.Log("Mode: Bootloader (Phone Info)", LogType.FileAndConsole);
                            NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                            break;
                        }
                        }
                    }
                }
                else if ((e.DevicePath.IndexOf(@"DISK&VEN_QUALCOMM&PROD_MMC_STORAGE", StringComparison.OrdinalIgnoreCase) >= 0) ||
                         (e.DevicePath.IndexOf(@"DISK&VEN_MSFT&PROD_PHONE_MMC_STOR", StringComparison.OrdinalIgnoreCase) >= 0) ||
                         ((e.DevicePath.Length == @"\\.\E:".Length) && (e.DevicePath.StartsWith(@"\\.\")) && (e.DevicePath.EndsWith(":"))))
                {
#if DEBUG
                    LogFile.Log("Mass storage arrived: " + e.DevicePath, LogType.FileOnly);
                    LogFile.Log("Start new thread for getting metadata.", LogType.FileOnly);
#endif

                    // This function is possibly called by an USB notification WndProc.
                    // It is not possible to invoke COM objects from a WndProc.
                    // MassStorage uses ManagementObjectSearcher, which is a COM object.
                    // Therefore we use a new thread.
                    ThreadPool.QueueUserWorkItem(s =>
                    {
                        lock (ModelLock)
                        {
                            if (!(CurrentModel is MassStorage))
                            {
                                // Wait 1 second to make sure MainOS is loaded
                                // In case of multiple drive letters being assigned to the phone by the user
                                // MainOS may take a while to show up and we may accidentally catch up a letter that is
                                // not for MainOS.
                                Task.Delay(1000).Wait();

                                MassStorage NewModel = new MassStorage(e.DevicePath);

                                if (NewModel.Drive != null) // When logical drive is already known, we use this model. Or else we wait for the logical drive to arrive.
                                {
                                    CurrentInterface = PhoneInterfaces.Lumia_MassStorage;
                                    CurrentModel     = NewModel;
                                    LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                                    LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                                    LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                                    LogFile.Log("Mode: Mass storage mode", LogType.FileAndConsole);
                                    if (!string.IsNullOrEmpty(Qcom9006DevicePath))
                                    {
                                        LogFile.Log("Found 9006 device previously", LogType.FileOnly);
                                        LogFile.Log("Attaching 9006 device", LogType.FileOnly);
                                        NewModel.AttachQualcommSerial(Qcom9006DevicePath);
                                    }
                                    NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                                }
                            }
                        }
                    });
                }
                else if (e.DevicePath.IndexOf("VID_05C6&", StringComparison.OrdinalIgnoreCase) >= 0) // Qualcomm device
                {
                    if (e.DevicePath.IndexOf("&PID_9008", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        USBDeviceInfo DeviceInfo = USBDevice.GetDevices(((USBNotifier)sender).Guid).Where((d) => string.Compare(d.DevicePath, e.DevicePath, true) == 0).FirstOrDefault();

                        if ((DeviceInfo.BusName == "QHSUSB_DLOAD") || (DeviceInfo.BusName == "QHSUSB__BULK") || ((DeviceInfo.BusName == "") && (LastInterface != PhoneInterfaces.Qualcomm_Download))) // TODO: Separate for Sahara!
                        {
                            CurrentInterface = PhoneInterfaces.Qualcomm_Download;
                            CurrentModel     = new QualcommSerial(e.DevicePath);
                            NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                            LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                            LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                            LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                            if (DeviceInfo.BusName == "")
                            {
                                LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole);
                            }
                            else
                            {
                                LogFile.Log("Mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole);
                            }
                        }
                        else if ((DeviceInfo.BusName == "QHSUSB_ARMPRG") || ((DeviceInfo.BusName == "") && (LastInterface == PhoneInterfaces.Qualcomm_Download)))
                        {
                            CurrentInterface = PhoneInterfaces.Qualcomm_Flash;
                            CurrentModel     = new QualcommSerial(e.DevicePath);
                            NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                            LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                            LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                            LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                            if (DeviceInfo.BusName == "")
                            {
                                LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole);
                            }
                            else
                            {
                                LogFile.Log("Mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole);
                            }
                        }
                    }
                    else if (e.DevicePath.IndexOf("&PID_9006", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        // This is part of the Mass Storage inteface.
                        // It is a slightly different version of the Qualcomm Emergency interface, which is implemented in SBL3.
                        // One important difference is that the base address for sending a loader is not 0x2A000000, but it is 0x82F00000.

                        Qcom9006DevicePath = e.DevicePath;

                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + Qcom9006DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        LogFile.Log("Mode: Qualcomm Emergency 9006", LogType.FileAndConsole);

                        if (CurrentModel is MassStorage)
                        {
                            LogFile.Log("Found Mass Storage device previously", LogType.FileOnly);
                            LogFile.Log("Attaching 9006 device", LogType.FileOnly);
                            ((MassStorage)CurrentModel).AttachQualcommSerial(Qcom9006DevicePath);
                        }
                    }
                    else if (e.DevicePath.IndexOf("&PID_F006", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        // This is part of the charging inteface.

                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        LogFile.Log("Mode: Qualcomm Emergency Charging F006", LogType.FileAndConsole);
                    }
                }
            }
            catch (Exception Ex)
            {
                LogFile.LogException(Ex);
                CurrentModel     = null;
                CurrentInterface = null;
            }
        }
Ejemplo n.º 20
0
 public WinusbAppiDeviceSlot(USBDeviceInfo OnUsbDeviceInfo)
 {
     DeviceInfo = OnUsbDeviceInfo;
 }
Ejemplo n.º 21
0
        void LumiaNotifier_Arrival(object sender, USBEvent e)
        {
            try
            {
                if (e.DevicePath.IndexOf("VID_0421&PID_0660&MI_04", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    CurrentInterface = PhoneInterfaces.Lumia_Label;
                    CurrentModel     = new NokiaPhoneModel(e.DevicePath);
                    LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                    LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                    LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                    LogFile.Log("Mode: Label", LogType.FileAndConsole);
                    NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                }
                else if ((e.DevicePath.IndexOf("VID_0421&PID_0661", StringComparison.OrdinalIgnoreCase) >= 0) ||
                         (e.DevicePath.IndexOf("VID_0421&PID_06FC", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_06FC is for Lumia 930
                         (e.DevicePath.IndexOf("vid_045e&pid_0a00", StringComparison.OrdinalIgnoreCase) >= 0))   // vid_045e & pid_0a00 & mi_03 = Lumia 950 XL normal mode
                {
                    if (((USBNotifier)sender).Guid == OldCombiInterfaceGuid)
                    {
                        NewInterfaceWaitHandle.Reset();
                        if (USBDevice.GetDevices(NewCombiInterfaceGuid).Count() > 0)
                        {
                            return;
                        }
                        else
                        {
                            // Old combi-interface was detected, but new combi-interface was not detected.
                            // This could mean 2 things:
                            // - It is a WP80 phone, which has only this old combi-interface to talk to.
                            // - It is a WP81 / W10M phone, which has an unresponsive old combi-interface and we need to wait for the new combi-interface to arrive.
                            // We will wait maximum 1 sec for the new interface. If it doesn't arrive we will start talking on this old interface.
                            // We will start a new thread, because if this thread is blocked, no new devices will arrive.
                            string DevicePath = e.DevicePath;
                            ThreadPool.QueueUserWorkItem(s =>
                            {
                                if (!NewInterfaceWaitHandle.WaitOne(1000))
                                {
                                    // Waithandle not set.
                                    // So new interface did not arrive.
                                    // So we assume we need to talk to this old interface.

                                    CurrentInterface = PhoneInterfaces.Lumia_Normal;
                                    CurrentModel     = new NokiaPhoneModel(DevicePath);
                                    LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                                    LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                                    LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                                    LogFile.Log("Mode: Normal", LogType.FileAndConsole);
                                    NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                                }
                            });
                        }
                    }
                    else
                    {
                        NewInterfaceWaitHandle.Set();

                        CurrentInterface = PhoneInterfaces.Lumia_Normal;
                        CurrentModel     = new NokiaPhoneModel(e.DevicePath);
                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        LogFile.Log("Mode: Normal", LogType.FileAndConsole);
                        NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                    }
                }
                else if ((e.DevicePath.IndexOf("VID_0421&PID_066E", StringComparison.OrdinalIgnoreCase) >= 0) ||
                         (e.DevicePath.IndexOf("VID_0421&PID_0714", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_0714 is for Lumia 930
                         (e.DevicePath.IndexOf("VID_045E&PID_0A02", StringComparison.OrdinalIgnoreCase) >= 0))   // VID_045E&PID_0A02 is for Lumia 950
                {
                    CurrentModel = new NokiaFlashModel(e.DevicePath);
                    ((NokiaFlashModel)CurrentModel).InterfaceChanged += InterfaceChanged;

                    // Attempt to request a param.
                    // When it succeeds we have full Flash mode.
                    // When it fails we are in a limited Flash mode, like Bootmanager or Hardreset-screen.
                    // Limited Flash mode only supports boot-commands; not querying info.
                    byte[] QueryResult = ((NokiaFlashModel)CurrentModel).ReadParam("SS");
                    if (QueryResult == null)
                    {
                        CurrentInterface = PhoneInterfaces.Lumia_Bootloader;
                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        LogFile.Log("Mode: Bootloader", LogType.FileAndConsole);
                        NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                    }
                    else
                    {
                        ((NokiaFlashModel)CurrentModel).DisableRebootTimeOut();
                        CurrentInterface = PhoneInterfaces.Lumia_Flash;
                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        LogFile.Log("Mode: Flash", LogType.FileAndConsole);
                        NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                    }
                }
                else if ((e.DevicePath.IndexOf(@"disk&ven_qualcomm&prod_mmc_storage", StringComparison.OrdinalIgnoreCase) >= 0) ||
                         (e.DevicePath.IndexOf(@"DISK&VEN_MSFT&PROD_PHONE_MMC_STOR", StringComparison.OrdinalIgnoreCase) >= 0))
                {
#if DEBUG
                    LogFile.Log("Mass storage arrived: " + e.DevicePath, LogType.FileOnly);
                    LogFile.Log("Start new thread for getting metadata.", LogType.FileOnly);
#endif

                    // This function is possibly called by an USB notification WndProc.
                    // It is not possible to invoke COM objects from a WndProc.
                    // MassStorage uses ManagementObjectSearcher, which is a COM object.
                    // Therefore we use a new thread.
                    ThreadPool.QueueUserWorkItem(s => {
                        lock (ModelLock)
                        {
                            if (!(CurrentModel is MassStorage))
                            {
                                MassStorage NewModel = new MassStorage(e.DevicePath);
                                if (NewModel.Drive != null) // When logical drive is already known, we use this model. Or else we wait for the logical drive to arrive.
                                {
                                    CurrentInterface = PhoneInterfaces.Lumia_MassStorage;
                                    CurrentModel     = NewModel;
                                    LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                                    LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                                    LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                                    LogFile.Log("Mode: Mass storage mode", LogType.FileAndConsole);
                                    NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                                }
                            }
                        }
                    });
                }
                else if ((e.DevicePath.Length == @"\\.\E:".Length) && (e.DevicePath.StartsWith(@"\\.\")) && (e.DevicePath.EndsWith(":")))
                {
#if DEBUG
                    LogFile.Log("Mass storage arrived: " + e.DevicePath, LogType.FileOnly);
                    LogFile.Log("Start new thread for getting metadata.", LogType.FileOnly);
#endif
                    // This function is possibly called by an USB notification WndProc.
                    // It is not possible to invoke COM objects from a WndProc.
                    // MassStorage uses ManagementObjectSearcher, which is a COM object.
                    // Therefore we use a new thread.
                    ThreadPool.QueueUserWorkItem(s =>
                    {
                        lock (ModelLock)
                        {
                            if (!(CurrentModel is MassStorage))
                            {
                                MassStorage NewModel = new MassStorage(e.DevicePath);
                                if (NewModel.Drive != null) // When logical drive is already known, we use this model. Or else we wait for the logical drive to arrive.
                                {
                                    CurrentInterface = PhoneInterfaces.Lumia_MassStorage;
                                    CurrentModel     = NewModel;
                                    LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                                    LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                                    LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                                    LogFile.Log("Mode: Mass storage mode", LogType.FileAndConsole);
                                    NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                                }
                            }
                        }
                    });
                }
                else if (e.DevicePath.IndexOf("VID_05C6&PID_9008", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    USBDeviceInfo DeviceInfo = USBDevice.GetDevices(((USBNotifier)sender).Guid).Where((d) => string.Compare(d.DevicePath, e.DevicePath, true) == 0).FirstOrDefault();

                    if ((DeviceInfo.BusName == "QHSUSB_DLOAD") || (DeviceInfo.BusName == "QHSUSB__BULK") || ((DeviceInfo.BusName == "") && (LastInterface != PhoneInterfaces.Qualcomm_Download))) // TODO: Separate for Sahara!
                    {
                        CurrentInterface = PhoneInterfaces.Qualcomm_Download;
                        CurrentModel     = new QualcommSerial(e.DevicePath);
                        NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        if (DeviceInfo.BusName == "")
                        {
                            LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole);
                        }
                        else
                        {
                            LogFile.Log("Mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole);
                        }
                    }
                    else if ((DeviceInfo.BusName == "QHSUSB_ARMPRG") || ((DeviceInfo.BusName == "") && (LastInterface == PhoneInterfaces.Qualcomm_Download)))
                    {
                        CurrentInterface = PhoneInterfaces.Qualcomm_Flash;
                        CurrentModel     = new QualcommSerial(e.DevicePath);
                        NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel));
                        LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                        LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                        LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                        if (DeviceInfo.BusName == "")
                        {
                            LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole);
                        }
                        else
                        {
                            LogFile.Log("Mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole);
                        }
                    }
                }
                else if (e.DevicePath.IndexOf("VID_05C6&PID_9006", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    // This is part of the Mass Storage inteface.
                    // It is a slightly different version of the Qualcomm Emergency interface, which is implemented in SBL3.
                    // One important difference is that the base address for sending a loader is not 0x2A000000, but it is 0x82F00000.

                    LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly);
                    LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly);
                    LogFile.Log("Connected device: Lumia", LogType.FileAndConsole);
                    LogFile.Log("Mode: Qualcomm Emergency 9006", LogType.FileAndConsole);
                }
            }
            catch (Exception Ex)
            {
                LogFile.LogException(Ex);
                CurrentModel     = null;
                CurrentInterface = null;
            }
        }
Ejemplo n.º 22
0
        private async void upgrade_process()
        {
            if (lstDevice.Items.Count == 1)
            {
                lstDevice.SelectAll();
            }

            if (lstDevice.SelectedItem != null)
            {
                upgrade_status = UPGRADE_STATUS.start;
                update_ui();

                bool bFormat = false;

                USBDeviceInfo item = (USBDeviceInfo)lstDevice.SelectedItems[0];
                if (cbxUpgradeFormat.IsChecked == true)
                {
                    await Task.Run(() => {
                        bFormat = format_device(item.DiskName);
                    });
                }
                else
                {
                    bFormat = true;
                }

                if (bFormat == true)
                {
                    if (cbbModels.SelectedItem != null && cbbLanguage.SelectedItem != null)
                    {
                        ModelInfo    model = (ModelInfo)cbbModels.SelectedItem;
                        LanguageInfo lan   = (LanguageInfo)cbbLanguage.SelectedItem;

                        try
                        {
                            await Task.Run(() => {
                                upgrade_device(item.DiskName, model, lan);
                            });

                            MessageBoxResult messageBoxResult = MessageBox.Show("업그레이드가 완료되었습니다, 안전하게 장치를 꺼내시겠습니까?", "Remove device confirmation", System.Windows.MessageBoxButton.YesNo);
                            if (messageBoxResult == MessageBoxResult.Yes)
                            {
                                bool remove_safe = RemoveDriveTools.RemoveDrive(item.DiskName);
                                if (remove_safe)
                                {
                                    MessageBox.Show("연결된 장치를 분리하셔도 됩니다.");
                                    // dispatch_usbList();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select Model and Langauge");
                    }
                }

                upgrade_status = UPGRADE_STATUS.end;
                update_ui();
            }
            else
            {
                MessageBox.Show("Select device!");
            }
        }
Ejemplo n.º 23
0
 internal X20DeviceInfo(USBDeviceInfo d, string serialNumber)
 {
     _d                = d;
     SerialNumber      = serialNumber;
     DeviceDescription = _d.DeviceDescription;
 }
Ejemplo n.º 24
0
        //----- Constructors -----

        /*
         * public USBIO(String Guid) : base(Guid)
         * {
         * SingleUSBDevice aSingleDevice = new SingleUSBDevice(Guid);
         * if (aSingleDevice != null)
         *  aSpectrometer = aSingleDevice.myDevice;
         * }
         */

        public USBIO(USBDeviceInfo deviceInfo) : base(deviceInfo)
        {
            aSpectrometer = (USBDevice)this;
        }
Ejemplo n.º 25
0
        public BBDMercury16Input(USBDeviceInfo selectedDevice = null) : base(4000, 8)
        {
            string expectedDeviceID = $"USB\\VID_{DEVICE_VID}&PID_{DEVICE_PID}";

            // libusbK implementation
            //int deviceCount = 0;
            //KLST_DEVINFO_HANDLE deviceInfo;
            //LstK lst = new LstK(KLST_FLAG.NONE);

            //lst.Count(ref deviceCount);
            //while (lst.MoveNext(out deviceInfo))
            //{
            //    Console.WriteLine("libusbk: " + deviceInfo.DeviceInterfaceGUID.ToLower());
            //}

            //lst.Free();


            // DotNetLibUsb
            //var deviceList = LibUsbDotNet.LibUsb.LibUsbDevice.AllDevices.ToArray();
            //foreach (var deviceInfoLUDN in deviceList)
            //{
            //    Console.WriteLine("libusb: " + deviceInfoLUDN.DeviceInterfaceGuids[0].ToString().ToLower() + " - " + deviceInfoLUDN.Device.Info.ProductString);
            //}

            //if (this.deviceInfo == null)
            //{
            //    throw new System.IO.IOException("There is no BBD Mercury-16 connected on any of the USB ports.");
            //}

            //if (deviceInfo.Device.Open())
            //{
            //    reader = deviceInfo.Device.OpenEndpointReader(LibUsbDotNet.Main.ReadEndpointID.Ep01);
            //    writer = deviceInfo.Device.OpenEndpointWriter(LibUsbDotNet.Main.WriteEndpointID.Ep01);
            //}

            // WinUSB.NET
            if (selectedDevice == null)
            {
                // GUID is an example, specify your own unique GUID in the .inf file
                USBDeviceInfo[] connectedDevices = USBDevice.GetDevices(DEVICE_INTERFACE_GUID);

                if (connectedDevices.Length == 0)
                {
                    throw new System.IO.IOException("There is no BBD Mercury-16 connected on any of the USB ports.");
                }

                selectedDevice = connectedDevices[0];

                //USBNotifier notifier = new USBNotifier(null, DEVICE_INTERFACE_GUID);
            }

            // Find your device in the array
            usbDevice    = new USBDevice(selectedDevice);
            usbInterface = usbDevice.Interfaces.Find(USBBaseClass.PersonalHealthcare);

            var phdPacket = ReadIEEE11073Pakcet(usbInterface.InPipe);

            // stop streaming data
            usbInterface.OutPipe.Write(new byte[] { 0xF0, 0x01, 0x00, 0x00 });

            CellSettings cellSettings = new CellSettings();

            while (cellSettings.SystemClock == 0)
            {
                // get the cell settings
                usbInterface.OutPipe.Write(new byte[] { 0xF0, 0x03, 0x00, 0x00 });
                cellSettings = ReadPacket <CellSettings>(usbInterface.InPipe, 0xF004, 10);
            }

            // set the modified cell settings
            //cellSettings.SampleRate /= 4;
            //WritePacket<CellSettings>(usbInterface.OutPipe, 0xF009, cellSettings);

            // start streaming data
            usbInterface.OutPipe.Write(new byte[] { 0xF0, 0x02, 0x00, 0x00 });

            if ((cellSettings.ChannelCount != 8) && (cellSettings.ChannelCount != 16) && (cellSettings.ChannelCount != 24))
            {
                throw new Exception($"The number of channels reported by Mercury-16 ({cellSettings.ChannelCount}) is invalid!");
            }


            //this.SamplesPerSecond = cellSettings.SampleRate;
            for (int i = 0; i < cellSettings.ChannelCount; i++)
            {
                this.SetChannel(i, new SinglePrecisionDataChannel(this.SamplesPerSecond, this.SamplesPerSecond * 5));
            }

            this.BufferSize          = Math.Max(this.BufferSize, this.SamplesPerSecond * this.ChannelCount * 2 / targetFPS);
            this.GoertzelOutputs     = new List <float> [this.ChannelCount];
            this.GoertzelFrequency01 = cellSettings.GoertzelFrequency01;
            this.GoertzelFrequency02 = cellSettings.GoertzelFrequency02;
            this.GoertzelFrequency03 = cellSettings.GoertzelFrequency03;

            Task usbPollTask = Task.Run(() =>
            {
                while (PollUSBData(this))
                {
                }
            });
        }
Ejemplo n.º 26
0
        private async void upgrade_task()
        {
            ModelInfo    model = (ModelInfo)cbbModels.SelectedItem;
            LanguageInfo lan   = (LanguageInfo)cbbLanguage.SelectedItem;

            load_manual($"{model.id}.{LanguageResources.Instance.CultureName.Substring(0, 2)}.html");

            try
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                upgrade_status = UPGRADE_STATUS.start;
                update_ui();

                USBDeviceInfo item    = (USBDeviceInfo)lstDevice.SelectedItems[0];
                bool          bFormat = false;
                if (cbxUpgradeFormat.IsChecked == true)
                {
                    await Task.Run(() => {
                        bFormat = format_device(item.DiskName, model.id, model.fileSystem, model.quickFormat, model.clusterSize);
                    });
                }

                // Check Drive size

                /*
                 * DriveInfo drive_info = new DriveInfo(item.DiskName);
                 * if (model.size != drive_info.TotalSize)
                 * {
                 *  Application.Current.Dispatcher.Invoke(() => {
                 *      prgbUpgrade.Value = 0;
                 *      prgbUpgradeText.Foreground = Brushes.Red;
                 *      prgbUpgradeText.Text = "Upgrade Fail: Invalid disk drive size! retry Format";
                 *  });
                 * }
                 */

                await Task.Run(() => {
                    upgrade_device(item.DiskName, model, lan);
                });

                /*
                 * MessageBoxResult messageBoxResult = MessageBox.Show("Upgrade completed, do you want to safely eject your device?", "Remove device confirmation", System.Windows.MessageBoxButton.YesNo);
                 * if (messageBoxResult == MessageBoxResult.Yes)
                 * {
                 *  bool remove_safe = RemoveDriveTools.RemoveDrive(item.DiskName);
                 *  if (remove_safe)
                 *  {
                 *      MessageBox.Show("You can also disconnect the connected device.");
                 *      // dispatch_usbList();
                 *  }
                 * }
                 */
                if (stopWatch.IsRunning)
                {
                    stopWatch.Stop();
                }
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

                Application.Current.Dispatcher.Invoke(() => {
                    prgbUpgrade.Value    = upgrade_count;
                    prgbUpgradeText.Text = $"Completed({elapsedTime})";
                    load_manual($"{model.id}.{LanguageResources.Instance.CultureName.Substring(0, 2)}.complete.html");
                });
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Application.Current.Dispatcher.Invoke(() => {
                    prgbUpgrade.Value          = 0;
                    prgbUpgradeText.Foreground = Brushes.Red;
                    prgbUpgradeText.Text       = "Upgrade Fail:" + e.Message;
                });
            }
            finally
            {
                upgrade_status = UPGRADE_STATUS.end;
                update_ui();
            }
        }
Ejemplo n.º 27
0
 public MicroluxDevice(string name, USBDeviceInfo info)
 {
     SerialNumber = name;
     Info         = info;
 }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            // {
            //     byte[] bin = File.ReadAllBytes(@"c:\Projects\MOAP\RandD\VK_PyOCD\VK_pyOCD_Ported\Targets\STM32F7x_1024.bin");
            //     Debug.Assert(bin.Length % 4 == 0);
            //     UInt32[] uints = new UInt32[bin.Length / 4];
            //     Buffer.BlockCopy(bin, 0, uints, 0, bin.Length);
            //     foreach (UInt32 uin in uints)
            //     {
            //         Trace.TraceInformation("0x{0:X8}", uin);
            //     }
            // }

            // // List<IDapAccessLink> links = DapAccessLink.get_connected_devices();
            // // Debug.Assert(links.Count > 0);

            // GUID is an example, specify your own unique GUID in the .inf file
            USBDeviceInfo[] details = USBDevice.GetDevices("{CDB3B5AD-293B-4663-AA36-1AAE46463776}");
            USBDeviceInfo   match   = details.First(info => info.VID == 0xC251 && info.PID == 0xF00A);
            BackendWinUsb   backend = new BackendWinUsb(match);
            IDapAccessLink  link    = new DapAccessLink("WINUSB1", backend); // links.First();

            // IDapAccessLink link = links.First();
            link.open();
            link.set_clock(300000); // Typically 1.8..2.0 MHz is fastest speed allowed
            link.connect();
            ////link.set_deferred_transfer(true);
            link.set_deferred_transfer(false);
            {
                var ver = link.identify(EDapInfoIDByte.FW_VER);
                if (ver is string)
                {
                    ver = ((string)ver).TrimEnd('\0');
                }
                Trace.TraceInformation("CMSIS-DAP Firmware Version: {0}", ver);
            }

            {
                object capabilities = link.identify(EDapInfoIDByte.CAPABILITIES);
                //                 Available transfer protocols to target:
                //
                //                 Info0 - Bit 0: 1 = SWD Serial Wire Debug communication is implemented (0 = SWD Commands not implemented).
                // Info0 - Bit 1: 1 = JTAG communication is implemented (0 = JTAG Commands not implemented).
                // Serial Wire Trace(SWO) support:
                //
                //                 Info0 - Bit 2: 1 = SWO UART - UART Serial Wire Output is implemented (0 = not implemented).
                // Info0 - Bit 3: 1 = SWO Manchester - Manchester Serial Wire Output is implemented (0 = not implemented).
                // Command extensions for transfer protocol:
                //
                // Info0 - Bit 4: 1 = Atomic Commands - Atomic Commands support is implemented (0 = Atomic Commands not implemented).
                // Time synchronisation via Test Domain Timer:
                //
                // Info0 - Bit 5: 1 = Test Domain Timer -debug unit support for Test Domain Timer is implemented (0 = not implemented).
                // SWO Streaming Trace support:
                //
                // Info0 - Bit 6: 1 = SWO Streaming Trace is implemented (0 = not implemented).
                UInt16 flags = (capabilities is byte) ? (byte)capabilities : (UInt16)capabilities;
                if ((flags & 0x0001) != 0)
                {
                    Trace.TraceInformation("CAPABILITY: SWD Serial Wire Debug communication is implemented");
                }
                if ((flags & 0x0002) != 0)
                {
                    Trace.TraceInformation("CAPABILITY: JTAG communication is implemented");
                }
                if ((flags & 0x0004) != 0)
                {
                    Trace.TraceInformation("CAPABILITY: SWO UART - UART Serial Wire Output is implemented");
                }
                if ((flags & 0x0008) != 0)
                {
                    Trace.TraceInformation("CAPABILITY: SWO Manchester - Manchester Serial Wire Output is implemented");
                }
                if ((flags & 0x0010) != 0)
                {
                    Trace.TraceInformation("CAPABILITY: Atomic Commands - Atomic Commands support is implemented");
                }
                if ((flags & 0x0020) != 0)
                {
                    Trace.TraceInformation("CAPABILITY: Test Domain Timer -debug unit support for Test Domain Timer is implemented");
                }
                if ((flags & 0x0040) != 0)
                {
                    Trace.TraceInformation("CAPABILITY: SWO Streaming Trace is implemented");
                }
            }

            string uniqueID = link.get_unique_id();

            Targets.Target_W7500.W7500 w = new Targets.Target_W7500.W7500(link);
            //Targets.Target_STM32F7x_1024.STM32F7x_1024 w = new Targets.Target_STM32F7x_1024.STM32F7x_1024(link);
            w.init();
            w.halt();
            {
                ETargetState s = w.getState();
                Debug.Assert(s == ETargetState.TARGET_HALTED);
            }
            w.resetStopOnReset();
            {
                ETargetState s = w.getState();
                Debug.Assert(s == ETargetState.TARGET_HALTED);
            }

            {
                UInt32 idcode = w.readIDCode();
                //                     STM32                   Wiznet
                Debug.Assert(idcode == 0x5BA02477 || idcode == 0x0bb11477);
            }
            //58.341]  < sequence name = "DebugCoreStart" Pname = "" disable = "false" info = "" >
            //      [15:43:58.341] < block atomic = "false" info = "" >
            //      [15:43:58.341]
            w.write32(0xE000EDF0, 0xA05F0001);                                        // Enable Core Debug via DHCSR
                                                                                      //[15:43:58.342]        // -> [Write32(0xE000EDF0, 0xA05F0001)] (__dp=0, __ap=0)
                                                                                      //[15:43:58.342] Write32(0xE0042004, DbgMCU_CR);                                         // DBGMCU_CR: Configure MCU Debug
                                                                                      // [15:43:58.342]        // -> [Write32(0xE0042004, 0x00000007)] (__dp=0, __ap=0)
            w.write32(0xE0042004, 0x00000007);
            //[15:43:58.342] Write32(0xE0042008, DbgMCU_APB1_Fz);                                    // DBGMCU_APB1_FZ: Configure APB1 Peripheral Freeze Behavior
            //[15:43:58.343]        // -> [Write32(0xE0042008, 0x00000000)] (__dp=0, __ap=0)
            w.write32(0xE0042008, 0x00000000);
            //[15:43:58.343] Write32(0xE004200C, DbgMCU_APB2_Fz);                                    // DBGMCU_APB1_FZ: Configure APB2 Peripheral Freeze Behavior
            w.write32(0xE004200C, 0x00000000);
            //[15:43:58.343]        // -> [Write32(0xE004200C, 0x00000000)] (__dp=0, __ap=0)
            //[15:43:58.343]    </block>
            //[15:43:58.344]  </sequence>


            //#define PERIPH_BASE            0x40000000U /*!< Base address of : AHB/ABP Peripherals                                                   */
            // AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000U)
            // RCC_BASE              (AHB1PERIPH_BASE + 0x3800U)
            /* Reset the RCC clock configuration to the default reset state ------------*/
            /*!< RCC clock control register,                                  Address offset: 0x00 */
            /* Set HSION bit */
            // w.write32(0x40023800, 1);// RCC->CR |= (uint32_t)0x00000001;
            // /* Reset CFGR register RCC clock configuration register,                            Address offset: 0x08 */
            // w.write32(0x40023808, 0); //RCC->CFGR = 0x00000000;
            //                           // /* Reset HSEON, CSSON and PLLON bits */
            // w.write32(0x40023800, 0xFEF6FFFF); //RCC->CR &= (uint32_t)0xFEF6FFFF;
            //                                    /* Reset PLLCFGR register RCC PLL configuration register,                              Address offset: 0x04 */
            //
            // w.write32(0x40023804, 0x24003010); // RCC->PLLCFGR = 0x24003010;
            //                                    /* Reset HSEBYP bit */
            // w.write32(0x40023800, w.read32(0x40023804)() & 0xFFFBFFFF); //// RCC->CR &= (uint32_t)0xFFFBFFFF;
            //                                                             /* Disable all interrupts RCC clock interrupt register,                                Address offset: 0x0C */
            //
            // w.write32(0x4002380C, 0); // RCC->CIR = 0x00000000;



            // 0xE0042000 DEBUG_MCU base
            // 0x08 APB1FZ
            w.write32(0xE0042008, 0); // DbgMCU_APB1_Fz = 0x00000000;
            w.write32(0xE004200C, 0); // DbgMCU_APB2_Fz = 0x00000000;

            //UInt32 scbVtor = w.read32(0xE000ED08)();
            // 0xE000ED08 // SCB->VTOR vector table offset
            w.write32(0xE000ED08, 0x20010000);

            {
                /////
                //// #define SCB_SHCSR_MEMFAULTENA_Pos          16U                                            /*!< SCB SHCSR: MEMFAULTENA Position */
                //// #define SCB_SHCSR_MEMFAULTENA_Msk          (1UL << SCB_SHCSR_MEMFAULTENA_Pos)             /*!< SCB SHCSR: MEMFAULTENA Mask */
                //// SHCSR;                  /*!< Offset: 0x024 (R/W)  System Handler Control and State Register */
                //unchecked
                //{
                //    w.write32(0xE000ED24, (UInt32)~(1 << 16));
                //}
                //w.write32(0xE000ED94, 0); // MPU->CR disable
                UInt32 mpuEnabled = w.read32(0xE000ED94)();
            }



            w.write32(0xE0042004, 0x00000007);
            //w.write32(0xE0042004, 0x00000027);

            // # Stop watchdog counters during halt
            // # DBGMCU_APB1_FZ |= DBG_IWDG_STOP | DBG_WWDG_STOP
            //w.write32(0xE0042008, 0x00001800 );
            //w.write32(0xE004200C, 0x00001800);

            {
                // 0xE000EDF0 Core Debug base
                // 0x00C DEMCR
                // Core Debug -> DEMCR & ~ (1 << DEMCR_MON_EN_Pos )  bit offset 16
                UInt32 demcr = w.read32(0xE000EDFC)();
                demcr &= ~((UInt32)1 << 16);
                w.write32(0xE000EDFC, demcr);
            }

            //Flash.Flash flash = new Targets.Target_STM32F7x_1024.Flash_STM32F7x_1024(w);
            Flash.Flash flash = new Targets.Target_W7500.Flash_w7500(w);
            flash.setFlashAlgoDebug(false); // flash.setFlashAlgoDebug(true);

            w.setFlash(flash);
            {
                w.flash.init();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                w.flash.eraseAll();
                sw.Stop();
                // Trace.TraceInformation("Chip erase speed is {0:0.000} s", sw.Elapsed.TotalSeconds);
            }
            {
                List <byte> l  = new List <byte>();
                Stopwatch   sw = new Stopwatch();
                sw.Start();
                //l.AddRange(w.readBlockMemoryUnaligned8(0x00000000, 49508));
                l.AddRange(w.readBlockMemoryUnaligned8(0x00000000, 128 * 1024));
                sw.Stop();
                Trace.TraceInformation("Reading speed is {0:0.000} kB/s", ((double)128 * 1024 / 1024.0) / sw.Elapsed.TotalSeconds);
                if (l.Any(b => b != 0xFF))
                {
                    Trace.TraceError("Erasing failed ..");
                }
                ;
                //byte[] bytes = l.ToArray();
                //File.WriteAllBytes(@"C:\temp\flash.bin", bytes);
            }

            //
            byte[] bytes = File.ReadAllBytes(@"c:\temp\flash.bin");
            {
                w.flash.flashBinary(
                    bytes,
                    smart_flash: false,
                    chip_erase: true, // meaning that chip erase is already done
                    fast_verify: false);
            }


            {
                List <byte> l  = new List <byte>();
                Stopwatch   sw = new Stopwatch();
                sw.Start();
                l.AddRange(w.readBlockMemoryUnaligned8(0x00000000, (UInt32)bytes.Length));
                //l.AddRange(w.readBlockMemoryUnaligned8(0x08000000, (UInt32)bytes.Length));
                sw.Stop();
                Trace.TraceInformation("Reading speed is {0:0.000} kB/s", ((double)bytes.Length / 1024.0) / sw.Elapsed.TotalSeconds);
                var ar = l.ToArray();
                File.WriteAllBytes(@"C:\TEMP\BIN.BIN", ar);
            }

            /*
             *
             * //var i = w.isRunning();
             * // w.setBreakpoint(0x00007840);
             * // w.resume();
             * // while (!w.isHalted())
             * // {
             * //     Trace.TraceInformation("... waiting for breakpoint ...");
             * //     //Thread.Sleep(1);
             * // }
             * //w.flush();
             * //var isRunning = w.isRunning();
             * //Debug.Assert(!isRunning);
             * //w.halt();
             * //var isHalted = w.isHalted();
             * //Debug.Assert(isHalted);
             * // w.removeBreakpoint(0x00007840);
             * {
             *  Stopwatch sw = new Stopwatch();
             *  sw.Start();
             *  //// for (int i = 0; i < 1000; i++)
             *  //// {
             *  ////     //var x = CoreSight.CortexM.CORE_REGISTER;
             *  ////     UInt32 pc = w.readCoreRegister("pc");
             *  ////     //Trace.TraceInformation("pc: {0:X8}", pc);
             *  ////     w.step(true);
             *  //// }
             *  double totalBytes = 0;
             *  for (int i = 0; i < 10; i++)
             *  {
             *      List<UInt32> z = w.readBlockMemoryAligned32(0x20000000, 0x1000);
             *      totalBytes += z.Count * 4;
             *  }
             *  sw.Stop();
             *  Trace.TraceInformation("Reading speed is {0:0.000} bytes/s", totalBytes / sw.Elapsed.TotalSeconds);
             * }
             * //var i = w.isRunning();
             */
        }