private void ControllerDisconnected(object sender, EventArgs e)
        {
            currentSerialPortReader.ControllerStateChanged -= ControllerStateChanged;
            currentSerialPortReader.ControllerDisconnected -= ControllerDisconnected;

            currentSerialPortReader.Dispose();
            currentSerialPortReader = null;
            lastState = null;
        }
 public void Detatch()
 {
     if (currentSerialPortReader is not null)
     {
         currentSerialPortReader.Dispose();
         currentSerialPortReader = null;
         lastState = null;
     }
 }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    currentSerialPortReader?.Dispose();
                    currentSerialPortReader = null;
                    lastState = null;
                }

                disposedValue = true;
            }
        }
        public bool Attach(string port)
        {
            if (currentSerialPortReader is not null)
            {
                currentSerialPortReader.Dispose();
                currentSerialPortReader = null;
                lastState = null;
            }

            try
            {
                currentSerialPortReader = new Readers.SerialControllerReader <Readers.SNESControllerState>(port, Readers.SNESControllerState.Parse);
                currentSerialPortReader.ControllerStateChanged += ControllerStateChanged;
                currentSerialPortReader.ControllerDisconnected += ControllerDisconnected;
            }
            catch (Exception ex)
            {
                communication.SendWarningMessage($"Exception trying to bind ControllerManager to port {port}: {ex}");
                currentSerialPortReader = null;
            }

            return(currentSerialPortReader is not null);
        }