Beispiel #1
0
        protected Commander(PortLevel port, IDevice device)
        {
            this.port       = port;
            port.ErrorPort += (s, e) => {
                // TODO: more accurate
                OnErrorOccured(e.Message);
            };
            this.device = device;

            undoProgramState     = (s, e) => setProgramStateWithoutUndo(pStatePrev);
            notRareModeRequested = false;
            var r = GetRealizer(port, notRare);

            ConsoleWriter.Subscribe(r);

            // eliminate local events!
            ProgramStateChanged += s => {
                if (s == ProgramStates.Measure || s == ProgramStates.BackgroundMeasureReady || s == ProgramStates.WaitBackgroundMeasure)
                {
                    r.Reset();
                }
            };
            MeasureCancelled += s => r.Reset();

            r.SystemReady += (s, e) => {
                if (hBlock)
                {
                    setProgramStateWithoutUndo(ProgramStates.WaitHighVoltage);
                }
                else
                {
                    setProgramStateWithoutUndo(ProgramStates.Ready);
                }
            };
            r.UpdateDevice += (s, e) => {
                // TODO: proper device
                if (device != null)
                {
                    e.Value.UpdateDevice(device);
                }
            };
            r.OperationBlock += (s, e) => {
                hBlock = e.Value;
                if (hBlock)
                {
                    setProgramStateWithoutUndo(ProgramStates.WaitHighVoltage);//???
                }
                else
                {
                    if (pState == ProgramStates.WaitHighVoltage)
                    {
                        setProgramStateWithoutUndo(ProgramStates.Ready);
                    }
                }
            };
            r.MeasurePreconfigured += (s, e) => {
                if (pState == ProgramStates.Measure ||
                    pState == ProgramStates.WaitBackgroundMeasure)
                {
                    if (!CurrentMeasureMode.Start())
                    {
                        OnErrorOccured("Нет точек для измерения.");
                    }
                }
            };
            // TODO: move to measure mode
            r.MeasureSend += (s, e) => {
                var temp = CurrentMeasureMode;
                if (temp != null && temp.isOperating)
                {
                    temp.NextMeasure(e.Value);
                }
            };
            r.MeasureDone += (s, e) => {
                if (CurrentMeasureMode == null)
                {
                    // fake reply caught here (in order to put device into proper state)
                    hBlock = false;
                    setProgramStateWithoutUndo(ProgramStates.Ready);
                }
            };
            this.realizer = r;

            hBlock = true;
        }
 protected override IRealizer GetRealizer(PortLevel port, Func<bool> notRare)
 {
     return realizer = new AlmazovRealizer(port, Config.Try, () => notRare() ? 500 : 10000);
 }
Beispiel #3
0
 protected abstract IRealizer GetRealizer(PortLevel port, Func <bool> notRare);
Beispiel #4
0
 protected abstract IRealizer GetRealizer(PortLevel port, Func<bool> notRare);
Beispiel #5
0
        protected Commander(PortLevel port, IDevice device)
        {
            this.port = port;
            port.ErrorPort += (s, e) => {
                // TODO: more accurate
                OnErrorOccured(e.Message);
            };
            this.device = device;

            undoProgramState = (s, e) => setProgramStateWithoutUndo(pStatePrev);
            notRareModeRequested = false;
            var r = GetRealizer(port, notRare);
            ConsoleWriter.Subscribe(r);

            // eliminate local events!
            ProgramStateChanged += s => {
                if (s == ProgramStates.Measure || s == ProgramStates.BackgroundMeasureReady || s == ProgramStates.WaitBackgroundMeasure) {
                    r.Reset();
                }
            };
            MeasureCancelled += s => r.Reset();

            r.SystemReady += (s, e) => {
                if (hBlock) {
                    setProgramStateWithoutUndo(ProgramStates.WaitHighVoltage);
                } else {
                    setProgramStateWithoutUndo(ProgramStates.Ready);
                }
            };
            r.UpdateDevice += (s, e) => {
                // TODO: proper device
                if (device != null)
                    e.Value.UpdateDevice(device);
            };
            r.OperationBlock += (s, e) => {
                hBlock = e.Value;
                if (hBlock) {
                    setProgramStateWithoutUndo(ProgramStates.WaitHighVoltage);//???
                } else {
                    if (pState == ProgramStates.WaitHighVoltage) {
                        setProgramStateWithoutUndo(ProgramStates.Ready);
                    }
                }
            };
            r.MeasurePreconfigured += (s, e) => {
                if (pState == ProgramStates.Measure ||
                    pState == ProgramStates.WaitBackgroundMeasure) {
                    if (!CurrentMeasureMode.Start()) {
                        OnErrorOccured("Нет точек для измерения.");
                    }
                }
            };
            // TODO: move to measure mode
            r.MeasureSend += (s, e) => {
                var temp = CurrentMeasureMode;
                if (temp != null && temp.isOperating) {
                    temp.NextMeasure(e.Value);
                }
            };
            r.MeasureDone += (s, e) => {
                if (CurrentMeasureMode == null) {
                    // fake reply caught here (in order to put device into proper state)
                    hBlock = false;
                    setProgramStateWithoutUndo(ProgramStates.Ready);
                }
            };
            this.realizer = r;

            hBlock = true;
        }
 protected override IRealizer GetRealizer(PortLevel port, Func <bool> notRare)
 {
     return(realizer = new AlmazovRealizer(port, Config.Try, () => notRare() ? FREQUENT_INTERVAL_MS : RARE_INTERVAL_MS));
 }
 protected override IRealizer GetRealizer(PortLevel port, Func <bool> notRare)
 {
     return(realizer = new SevMorGeoRealizer(port, Config.Try, () => notRare() ? 5 : 3, () => notRare() ? 500 : 10000));
 }