public static SerialPortMgt GetInstance()
 {
     if (instance == null)
     {
         lock (lockobj)
         {
             if (instance == null)
             {
                 instance = new SerialPortMgt();
             }
         }
     }
     return(instance);
 }
 public void ClosePorts()
 {
     lock (lockobj)
     {
         foreach (SerialPort port in this.PortList.Values)
         {
             try
             {
                 port.Close();
             }
             catch (Exception)
             {
             }
         }
         this.PortList.Clear();
         instance = null;
     }
 }