private async Task CompleteXemoCycle(SampleChanger sc, int?diskPosition) { if (!diskPosition.HasValue || sc == null) { return; } if (sc.IsSampleCaptured) { using (var ct = new CancellationTokenSource(TimeSpan.FromMinutes(2))) { await sc.PutSampleToTheDiskAsync((short)diskPosition.Value, ct.Token); } } using (var ct = new CancellationTokenSource(TimeSpan.FromMinutes(2))) { await sc.HomeAsync(ct.Token); } }
static async Task Main(string[] args) { using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new GRPCXemo.GRPCXemoClient(channel); int devId = 0; try { Report.Notify(new Message(Codes.INFO_XM_GRPC_CLNT_INIT)); // The port number(5001) must match the port of the gRPC server. devId = int.Parse(args[0]); if (devId == 0) { throw new ArgumentException("Wrong device serial number!"); } using (var sc = new SampleChanger(devId)) { var ctinit = new CancellationTokenSource(TimeSpan.FromSeconds(90)); await sc.HomeAsync(ctinit.Token); var ct = new CancellationTokenSource(); Report.Notify(new Message(Codes.INFO_XM_GRPC_CLNT_IN_HOME)); var stopMeas = false; while (!stopMeas) { Report.Notify(new Message(Codes.INFO_XM_GRPC_CLNT_IN_RUN_CYCL)); var ts = await client.DeviceIsReadyAsync(new DeviceIsReadyRequest { DevId = devId, IsReady = true }); await client.SampleInCellAsync(new SampleInCellRequest { DevId = devId, IsInCell = false }); await sc.TakeSampleFromTheCellAsync((short)ts.CellNum, ct.Token); var gotodeth = await client.SampleHasTakenAsync(new SampleHasTakenRequest { DevId = devId, IsTaken = true }); await sc.PutSampleAboveDetectorWithHeightAsync(HH[gotodeth.H], ct.Token); var takeSample1 = await client.SampleAboveDetectorAsync(new SampleAboveDetectorRequest { DevId = devId, IsAbove = true }); var isMeasDone = false; Report.Notify(new Message(Codes.INFO_XM_GRPC_CLNT_WAIT_MEAS)); do { var measStatus = await client.IsMeasurementsDoneAsync(new IsMeasurementsDoneRequest { DevId = devId }); isMeasDone = measStatus.IsDone; await Task.Delay(TimeSpan.FromSeconds(2)); }while (!isMeasDone); Report.Notify(new Message(Codes.INFO_XM_GRPC_CLNT_MEAS_DONE)); var takeSample2 = await client.SampleAboveDetectorAsync(new SampleAboveDetectorRequest { DevId = devId, IsAbove = false }); await sc.PutSampleToTheDiskAsync((short)ts.CellNum, ct.Token); var tsNext = await client.SampleInCellAsync(new SampleInCellRequest { DevId = devId, IsInCell = true }); var isLastMeasReply = await client.IsLastMeasurementAsync(new IsLastMeasurementRequest { DevId = devId }); stopMeas = isLastMeasReply.IsLast; } await sc.HomeAsync(ct.Token); // NOTE: In order to not close main thread after await! Console.WriteLine("Push any key to exit..."); Console.ReadKey(); } // using (var sc = new SampleChanger(devId)) } catch (TaskCanceledException) { Report.Notify(new Message(Codes.ERR_XM_GRPC_CLNT_DEV_NOT_ANS) { DetailedText = $"Device '{devId}' do not answer. XemoClient will be rerun." }); Shell.StartProcess("XemoClient.exe", devId.ToString()); } catch (Exception ex) { await client.DeviceErrorAsync(new ErrorOccurredRequest { DevId = devId }); Report.Notify(new Message(Codes.ERR_XM_GRPC_CLNT_UNREG) { DetailedText = ex.Message }); } }