private void Disconnect() { if (mTcpDevice == null) { return; } mTcpDevice.Send("exit\r\n"); mTcpDevice.Disconnect(); mTcpDevice = null; }
void mTcpDevice_Disconnected(ConnectionState state) { UpdateState(state); SetMachineStatus("Stopped", Color.White); if (mTcpDevice == null) { return; } mTcpDevice.Connected -= new CncDeviceDelegate(mTcpDevice_Connected); mTcpDevice.Disconnected -= new CncDeviceDelegate(mTcpDevice_Disconnected); mTcpDevice.DataSent -= new CncDeviceDelegate(mTcpDevice_DataSent); mTcpDevice.DataReceived -= new CncDeviceResponseDelegate(mTcpDevice_DataReceived); mTcpDevice.ErrorRaised -= new CncDeviceDelegate(mTcpDevice_ErrorRaised); mTcpDevice = null; }
private void Connect() { if (mTcpDevice != null) { Disconnect(); } string cncMachine = GetConfig().GetString("cnc.address"); int cncPort = GetConfig().GetInt("cnc.port", 82); Assert.IsNotNull(cncMachine, "cnc.address parameter not defined"); mTcpDevice = new CncDeviceClient(cncMachine, cncPort, this); mTcpDevice.Connected += new CncDeviceDelegate(mTcpDevice_Connected); mTcpDevice.Disconnected += new CncDeviceDelegate(mTcpDevice_Disconnected); mTcpDevice.DataSent += new CncDeviceDelegate(mTcpDevice_DataSent); mTcpDevice.DataReceived += new CncDeviceResponseDelegate(mTcpDevice_DataReceived); mTcpDevice.ErrorRaised += new CncDeviceDelegate(mTcpDevice_ErrorRaised); ConnectionStatusLabel.Text = "Connecting..."; mTcpDevice.Connect(); }