コード例 #1
0
        public async override Task DisconnectAsync()
        {
            await _semaphoreSlimConnect.WaitAsync();

            if (Connected)
            {
                // make sure we're in a halfway known state...
                var dxCommand = new StopDataAcquisitionCommand();
                await SimpleCommandTxRxAsync(dxCommand);

                // close the serial port
                serialPort.Close();
            }

            _semaphoreSlimConnect.Release();
        }
コード例 #2
0
        public async override Task ConnectAsync()
        {
            await _semaphoreSlimConnect.WaitAsync();

            // already connected
            if (Connected)
                return;

            serialPort.Open();

            // make sure we're in a halfway known state...
            var dxCommand = new StopDataAcquisitionCommand();
            await serialPort.WriteAsync(dxCommand.Command.Select(x => (byte)x).ToArray(), 0, dxCommand.Command.Length);

            await Task.Delay(100);
            serialPort.DiscardInBuffer();

            await WaitForStabilizedMotorSpeedAsync(TimeSpan.FromSeconds(10), throwOnFail: true);
            await UpdateDeviceInfoAsync();

            _semaphoreSlimConnect.Release();
        }     
コード例 #3
0
        public async override Task StopScanAsync()
        {
            if (!Connected)
                throw new LidaRxStateException("This instance is not yet connected to the Sweep scanner.");

            await _semaphoreSlimScanStart.WaitAsync();

            // send a stop command to sweep
            var cmd = new StopDataAcquisitionCommand();
            var cmdBytes = cmd.Command.Select(x => (byte)x).ToArray();
            await serialPort.WriteAsync(cmdBytes, 0, cmdBytes.Length);

            // stop the threads
            scanProcessingCts.Cancel();

            // wait for termination
            while (this.scanProcessingThreads.Any(x => x.IsAlive))
            {
                await Task.Delay(1);
            }

            this.scanProcessingThreads.Clear();
            this.rxScanBuffer.Clear();

            await Task.Delay(1);
            serialPort.DiscardInBuffer();

            // send a second DX command
            await serialPort.WriteAsync(cmdBytes, 0, cmdBytes.Length);

            // throwaway stuff in the RX buffer!
            Thread.Sleep(1);
            serialPort.DiscardInBuffer();

            this._isScanning = false;

            _semaphoreSlimScanStart.Release();
        }