Exemplo n.º 1
0
        /// <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();
                }
            }
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        protected virtual void Cleanup()
        {
            if (cleanup)
            {
                return;
            }

            cleanup.Value = true;

            connection.Close();
            comObj.Dispose();
            ctSource.Dispose();
        }
Exemplo n.º 4
0
 public void CanFindCorectComPort()
 {
     var communicationObject = new CommunicationObject("COM4");
     communicationObject.Open();
     Assert.IsTrue(communicationObject.IsOpen);
     communicationObject.Dispose();
 }