Example #1
0
        public async Task DisconnectAsync()
        {
            lock (this)
            {
                if (!Connected)
                {
                    AddStatusMessage(StatusMessageTypes.Warning, "Can not disconnected - Not Connected");
                    return;
                }

                Mode      = OperatingMode.Disconnected;
                Connected = false;

                MachinePosition   = new Vector3();
                WorkspacePosition = new Vector3();

                Status                  = "Disconnected";
                DistanceMode            = ParseDistanceMode.Absolute;
                Unit                    = ParseUnit.Metric;
                Plane                   = ArcPlane.XY;
                UnacknowledgedBytesSent = 0;

                lock (_queueAccessLocker)
                {
                    _toSend.Clear();
                    _toSendPriority.Clear();
                    _sentQueue.Clear();
                }
            }

            if (_port != null)
            {
                await _port.CloseAsync();

                AddStatusMessage(StatusMessageTypes.Info, "Closed Serial Port");
                _port = null;
            }

            if (_socketClient != null)
            {
                await _socketClient.CloseAsync();

                _socketClient.Dispose();
                _socketClient = null;
            }

            if (this._cancelSource != null)
            {
                _cancelSource.Cancel();
                _cancelSource = null;
            }

            AddStatusMessage(StatusMessageTypes.Info, "Disconnected");
        }
Example #2
0
        protected override async Task RunService(CancellationToken stoppingToken)
        {
            var(success, errorMessage) = await Helpers.Retry(async() =>
            {
                await client.ConnectAsync(conf.CsIP, conf.CsPort, stoppingToken);
                return(true);
            }, ConnectRetries, RetryIntervalMs, stoppingToken);

            if (!success)
            {
                logger.Error($"No connection could be made. Error: {errorMessage}");
                lifetime.StopApplication();
                return;
            }

            (bool receivedMessage, Message message) = await client.ReceiveAsync(stoppingToken);

            while (!stoppingToken.IsCancellationRequested && receivedMessage)
            {
                bool sended = await queue.SendAsync(message, stoppingToken);

                if (!sended)
                {
                    logger.Warning($"SocketService| Message id: {message.MessageID} has been lost");
                }
                (receivedMessage, message) = await client.ReceiveAsync(stoppingToken);
            }
            await client.CloseAsync(stoppingToken);

            message = new Message()
            {
                AgentID   = -1,
                MessageID = MessageID.CSDisconnected,
                Payload   = new EmptyPayload()
            };
            await queue.SendAsync(message, stoppingToken);
        }
Example #3
0
        public override async Task <bool> InvokeAsync(string paramList)
        {
            await _socketClient.CloseAsync();

            return(true);
        }
Example #4
0
 protected override async Task CloseSocketAsync(ISocketClient <R, S> socket,
                                                CancellationToken cancellationToken)
 {
     await socket.CloseAsync(cancellationToken);
 }