示例#1
0
        internal static actionResult DestroyPort(SerialPortStream port)
        {
            var ar = new actionResult();

            if (!port.IsAlive())
            {
                ar.setError("Port already closed.");
                return(ar);
            }

            if (port == Plugin.SelectedPort)
            {
                Plugin.MainCtl.Log($"=========== {port.PortName}: log end ===========", false);
            }
            string portLongName = Plugin.OpenedPorts.First(kvp => kvp.Value == port).Key;

            Plugin.OpenedPorts.Remove(portLongName);
            if (port.IsOpen)
            {
                port.Close();
            }
            port.Dispose();
            // ReSharper disable once RedundantAssignment
            port = null;
            Plugin.MainCtl.UpdatePortsListView();
            ar.setInfo("Port closed.");
            Plugin.HostInstance.log(nameof(Serial) + ": destroyed port: " + portLongName);
            return(ar);
        }