コード例 #1
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");
        }
コード例 #2
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");
        }