public static string ReadUniqueId(BaseDevice device) { string uniqueId = string.Empty; if (device.TwiKfdtoolDevice.ComPort == string.Empty) { throw new ArgumentException("No device selected"); } AdapterProtocol ap = null; try { ap = new AdapterProtocol(device.TwiKfdtoolDevice.ComPort); ap.Open(); ap.Clear(); byte[] id = ap.ReadUniqueId(); if (id.Length == 0) { uniqueId = "NONE"; } else { uniqueId = BitConverter.ToString(id).Replace("-", string.Empty); } } catch (Exception) { throw; } finally { try { if (ap != null) { ap.Close(); } } catch (System.IO.IOException ex) { Logger.Warn("could not close serial port: {0}", ex.Message); } } return(uniqueId); }