public static void Init(Form1 f) { try { theForm = f; logger("Initializing Vorze USB dongle..", true); changeCOMDevice = true; serialPort = new SerialPort(); serialPort.BaudRate = 19200; timer = new System.Windows.Forms.Timer(); timer.Interval = 20; timer.Tick += timer_Tick; InitialCommand(); vorzeDeviceNames = LoaddeviceNames(); UsbDongle newDongle = discoverUsbDongle(); if (newDongle != null) { vorzeDongle = newDongle; } changeCOMDevice = true; timer.Enabled = true; timer.Stop(); logger("initialization of Vorze USB dongle completed successfully.", true); } catch (Exception e) { logger("Error during Vorze USB dongle initialization, make sure the Vorze USB dongle is connected and installed properly.", false); logger(e.Message, true); } }
private static UsbDongle discoverUsbDongle() { List <UsbDongle> list = UsbDongle.discover().FindAll(d => vorzeDeviceNames.Contains(d.deviceName)); if (0 >= list.Count) { return(null); } return(list[0]); }
private static void updateUsbDongle() { Debug.WriteLine("Updating usb Vorze Dongle..."); lock (syncObject) { if (changeCOMDevice) { changeCOMDevice = false; UsbDongle newDongle = discoverUsbDongle(); if (newDongle != null) { vorzeDongle = newDongle; } } } }
private static void resetComPort() { lock (syncObject) { if (serialPort.IsOpen) { try { Thread.Sleep(100); serialPort.Close(); vorzeDongle = null; } catch (IOException) { } } if (discoverUsbDongle() != null) { openComPort(); } } }