private void FormRoombaMovementPanel_FormClosing(object sender, FormClosingEventArgs e) { if (_robotController != null) { _robotController.Dispose(); _robotController = null; } ARC.FormMain.MovementPanel = null; EZBManager.PrimaryEZB.OnConnectionChange2 -= PrimaryEZB_OnConnectionChange2; EZBManager.MovementManager.OnMovement2 -= Movement_OnMovement2; EZBManager.MovementManager.OnSpeedChanged -= MovementManager_OnSpeedChanged; if (ARC.Scripting.ScriptManager.DoesExecutorExist(Text)) { var s = ARC.Scripting.ScriptManager.GetExecutor(Text); s.OnDone -= S_OnDone; s.OnError -= S_OnError; s.OnResult -= S_OnResult; s.OnStart -= S_OnStart; ARC.Scripting.ScriptManager.RemoveExecutor(Text); } }
private void PrimaryEZB_OnConnectionChange2(EZB sender, bool isConnected) { var portType = (Config.ConfigTitles.PortTypeEnum)_cf.STORAGE[Config.ConfigTitles.CONNECTION_TYPE]; if (portType == ConfigTitles.PortTypeEnum.PC_COM) { return; } try { if (isConnected) { init(); } else { if (_robotController != null) { _robotController.Dispose(); _robotController = null; } Invokers.SetAppendText(tbLog, true, "Disconnected"); } } catch (Exception ex) { Invokers.SetAppendText(tbLog, true, "Connection change: {0}", ex); } }
private void init() { if (InvokeRequired) { Invoke(new Action(() => init())); return; } tbLog.Clear(); if (_robotController != null) { _robotController.OnError -= _robotController_OnError; _robotController.OnButtonPressed -= _robotController_OnButtonPressed; _robotController.OnLog -= _robotController_OnLog; _robotController.OnStreamPacketCnt -= _robotController_OnStreamPacketCnt; _robotController.Dispose(); _robotController = null; } var portType = (Config.ConfigTitles.PortTypeEnum)_cf.STORAGE[Config.ConfigTitles.CONNECTION_TYPE]; IOCommunicator comm; if (portType == Config.ConfigTitles.PortTypeEnum.Software_Serial) { if (!EZBManager.PrimaryEZB.IsConnected) { throw new Exception("Not connected to EZB Index #0"); } var digitalPort = (Digital.DigitalPortEnum)_cf.STORAGE[Config.ConfigTitles.EZB_SERIAL_PORT]; var baudrate = (Uart.BAUD_RATE_ENUM)_cf.STORAGE[Config.ConfigTitles.BAUD_RATE_SERIAL]; tbLog.AppendText(string.Format("Connecting software serial port {0} @ {1}...", digitalPort, baudrate)); comm = new EZBDigitalIOCommunicator(digitalPort, baudrate); } else if (portType == Config.ConfigTitles.PortTypeEnum.HW_UART) { if (!EZBManager.PrimaryEZB.IsConnected) { throw new Exception("Not connected to EZB Index #0"); } var uartPort = Convert.ToInt16(_cf.STORAGE[Config.ConfigTitles.EZB_UART_PORT]); var baudRate = Convert.ToInt32(_cf.STORAGE[Config.ConfigTitles.BAUD_RATE_UART]); tbLog.AppendText(string.Format("Connecting HW UART {0} @ {1}...", uartPort, baudRate)); comm = new EZBUARTIOCommunicator(uartPort, baudRate); } else { var comPort = _cf.STORAGE[Config.ConfigTitles.PC_COM_PORT].ToString(); var baudRate = Convert.ToInt32(_cf.STORAGE[Config.ConfigTitles.BAUD_RATE_PC]); tbLog.AppendText(string.Format("Connecting {0} @ {1}...", comPort, baudRate)); comm = new SerialPortIOCommunicator(comPort, baudRate); } _robotController = new Create( comm, Convert.ToInt32(_cf.STORAGE[Config.ConfigTitles.SENSOR_POLL_TIME_MS]), Convert.ToBoolean(_cf.STORAGE[Config.ConfigTitles.NMS_POSITION_DATA])); _robotController.OnError += _robotController_OnError; _robotController.OnButtonPressed += _robotController_OnButtonPressed; _robotController.OnLog += _robotController_OnLog; _robotController.OnStreamPacketCnt += _robotController_OnStreamPacketCnt; _robotController.SetMode(Create2OI.Types.OperatingMode.FULL); cbSensorStream_CheckedChanged(null, null); doMotors(); Invokers.SetAppendText(tbLog, true, "Connected"); }