示例#1
0
 private void ButtonSendVCSELBurnInCommandsOnClick()
 {
     foreach (PediatricSensor sensor in PediatricSensorData.Sensors)
     {
         sensor.SendCommand(PediatricSoftConstants.SensorCommandLaserCurrent);
         sensor.SendCommand(String.Concat("#", PediatricSensor.UInt16ToStringBE(ushort.MaxValue)));
     }
 }
        public void ScanPortsAsync()
        {
            Task.Run(() =>
            {
                if (CanScan)
                {
                    DebugLog.Enqueue("Begin port scan");

                    CanScan         = false;
                    CanLock         = false;
                    CanStartStop    = false;
                    CanZeroFields   = false;
                    CanSendCommands = false;

                    // Remove all failed sensors
                    for (int i = Sensors.Count - 1; i >= 0; i--)
                    {
                        if (Sensors[i].State == PediatricSoftConstants.SensorState.Failed)
                        {
                            Sensors[i].Dispose();
                            while (!Sensors[i].IsDisposed)
                            {
                                Thread.Sleep(PediatricSoftConstants.StateHandlerSleepTime);
                            }
                            App.Current.Dispatcher.Invoke(() => Sensors.RemoveAt(i));
                        }
                    }

                    RaisePropertyChanged("SensorCount");

                    string[] potentialSensorSerialNumbers = GetPotentialSensorSerialNumbers();
                    string[] currentSensorSerialNumbers   = Sensors.Select(x => x.SN).ToArray();

                    // Try to add all potential sensors that are not on the list currently
                    foreach (string serial in potentialSensorSerialNumbers)
                    {
                        if (!currentSensorSerialNumbers.Contains(serial))
                        {
                            PediatricSensor sensor = new PediatricSensor(serial);
                            if (sensor.IsValid)
                            {
                                sensor.KickOffTasks();
                                App.Current.Dispatcher.Invoke(() => Sensors.Add(sensor));
                            }
                            else
                            {
                                while (!sensor.IsDisposed)
                                {
                                    Thread.Sleep(PediatricSoftConstants.StateHandlerSleepTime);
                                }
                            }
                            RaisePropertyChanged("SensorCount");
                        }
                        else
                        {
                            DebugLog.Enqueue($"Sensor with serial number {serial} is already on the list - skipping");
                        }
                    }

                    if (Sensors.Count > 0)
                    {
                        CanLock         = true;
                        CanSendCommands = true;
                    }

                    IsMasterCardPresent = false;
                    foreach (PediatricSensor sensor in Sensors)
                    {
                        IsMasterCardPresent = IsMasterCardPresent | sensor.IsMasterCard;
                    }

                    CanScan = true;

                    DebugLog.Enqueue("Port scan done");
                }
            });
        }