/// <summary>
 /// Endstop Status
 /// </summary>
 /// <param name="endstop"></param>
 public EndstopStatus(EndStop endstop)
 {
     Status = endstop;
 }
        /// <summary>
        /// Connect and get the INIT without events..
        /// Timeout on first responce is 10s
        /// The following has 4s (Test of SD is slow)
        ///
        /// </summary>
        public void Connect()
        {
            if (_serialPort.ConnectedTo.ToString() == "None")
            {
                try
                {
                    //TODO: TypeOfCursor cursorType = new TypeOfCursor(Cursors.WaitCursor);
                    //TODO: OnSending(cursorType);
                    IsPortOpen = false;
                    _serialPort.Disconnected += _serialPort_Disconnected;
                    _serialPort.Connected    += _serialPort_Connected;


                    _serialPort.CustomBaudRate = Convert.ToUInt32(BaudRate);
                    _serialPort.BaudRate       = SerialBaudRate.Custom;


                    // 8 batabits No parity 1 Stop Bit
                    _serialPort.DataWidth   = SerialDataWidth.Dw8Bits;
                    _serialPort.ParityBits  = SerialParityBits.None;
                    _serialPort.StopBits    = SerialStopBits.Sb1Bit;
                    _serialPort.AutoReceive = false;

                    CurrentPosition   = new Position();
                    EndStopStatus     = new EndStop();
                    ProbeResponceList = new List <Position>();

                    // Activate a true licence


                    if (!string.IsNullOrEmpty(Configuration.Decrypt(Configuration.GetInstance.LicenseKey)))
                    {
                        _serialPort.UnlockKey = "FA3450FEA2344897EFC34325BA391072";
                    }


                    _serialPort.NewLine     = "\n";
                    _serialPort.AutoReceive = false;
                    _serialPort.Open();

                    string dataReceived = "";
                    var    rec          = _serialPort.ReadLine(10); //TODO: Config of initial timeout
                    while (true)
                    {
                        var lastreceived = _serialPort.LastTimeReceived;

                        dataReceived += rec + Environment.NewLine;

                        var timeDiff = DateTime.Now - lastreceived;
                        if (timeDiff.Seconds >= 4)
                        {
                            break;                        //TODO: Config of timeout
                        }
                        rec = _serialPort.ReadLine(4);
                    }

                    if (!_serialPort.IsConnected())
                    {
                        return;
                    }
                    ParseInit(dataReceived);
                    //TODO: cursorType = new TypeOfCursor(Cursors.Default);
                    //TODO: OnSending(cursorType);
                }
                catch (Exception serialOpenException)
                {
                    MessageBox.Show($"The serialport {_serialPort.Port} can´t be opend!\n\n" +
                                    $"({serialOpenException.Message})"
                                    , @"Cant open the Serial port", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        ///     Report result of M119 EndstopStatus
        /// </summary>
        /// <param name="endstopStatusList"></param>
        private void OnM119EndStopStatus(EndStop endstopStatusList)
        {
            var handler = M119EndStopStatus;

            handler?.Invoke(this, endstopStatusList);
        }