コード例 #1
0
        private async Task InitServiceHub()
        {
            _serviceHub = new SerialServiceHub(WebServerUrl, this);
            var connection = await _serviceHub.Start();

            connection.On("queueEmpty", (int id) =>
            {
                if (PortId == id)
                {
                    CommandQueueEmpty?.Invoke(this, new SerialEventArgs());
                }
            });
            connection.On("queueChanged", (int id, int queuelength) =>
            {
                if (PortId == id)
                {
                    CommandQueueChanged?.Invoke(this, new SerialEventArgs(queuelength, null));
                }
            });
            connection.On("sendingCommand", (int id, int seqId) =>
            {
                if (PortId == id)
                {
                    CommandSending?.Invoke(this, new SerialEventArgs(new SerialCommand()
                    {
                        SeqId = seqId
                    }));
                }
            });
        }
コード例 #2
0
ファイル: SerialService.cs プロジェクト: lulzzz/CNCLib
        public async Task DisconnectAsync()
        {
            if (PortId >= 0)
            {
                using (var scope = CreateScope())
                {
                    var response = await scope.Instance.PostAsJsonAsync($@"{_api}/{PortId}/disconnect", "x");
                    if (response.IsSuccessStatusCode)
                    {
                        _serviceHub?.Stop();
                        _serviceHub = null;
                        IsConnected = false;
                        PortId      = -1;
                        return;
                    }
                }
            }

            throw new Exception("DisConnect to SerialPort failed");
        }
コード例 #3
0
ファイル: SerialService.cs プロジェクト: rockxcn/CNCLib
        public async Task DisconnectAsync()
        {
            if (PortId != 0)
            {
                using (HttpClient client = CreateHttpClient())
                {
                    HttpResponseMessage response = await client.PostAsJsonAsync($@"{_api}/{PortId}/disconnect", "x");

                    if (response.IsSuccessStatusCode)
                    {
                        _serviceHub?.Stop();
                        _serviceHub = null;
                        IsConnected = false;
                        PortId      = 0;
                        return;
                    }
                }
            }
            throw new Exception("DisConnect to SerialPort failed");
        }