/// <summary> /// Уведомляет серверный обработчик о завершении работы и закрывает подключение. /// </summary> protected async Task DisconnectFromHandler(Connection connection, StopMode stopMode) { bool useExclusiveAccess = false; Connection usingConnection = connection; if (stopMode == StopMode.Hard) { usingConnection = mainConnection; useExclusiveAccess = true; } if (connection.IsConnected) { CommunicationObject comObj = new CommunicationObject(usingConnection, useExclusiveAccess); try { comObj.SetData(NetSharpProtocol.Commands.STOP_HANDLER, new HandlerStopData(connection.HandlerID, stopMode)); await comObj.SendAsync().ConfigureAwait(false); } finally { comObj.Dispose(); connection.Close(); } } }
public void CanMoveServo(byte id, CommunicationObject sender) { var movment1 = new MovmentComandAX12(id, 0x0ff, 0x150); var movment2 = new MovmentComandAX12(id, 0x1ff, 0x150); var instructionPacket = new InstructionPacketSyncMovment(sender, movment1); instructionPacket.Send(); Thread.Sleep(2000); instructionPacket = new InstructionPacketSyncMovment(sender, movment2); instructionPacket.Send(); sender.Dispose(); }
protected virtual void Cleanup() { if (cleanup) { return; } cleanup.Value = true; connection.Close(); comObj.Dispose(); ctSource.Dispose(); }
public void CanFindCorectComPort() { var communicationObject = new CommunicationObject("COM4"); communicationObject.Open(); Assert.IsTrue(communicationObject.IsOpen); communicationObject.Dispose(); }