diff --git a/TBF/BenchControl/Elde/ControlBoardDev.cs b/TBF/BenchControl/Elde/ControlBoardDev.cs index 0ce2c1295..637123fd2 100644 --- a/TBF/BenchControl/Elde/ControlBoardDev.cs +++ b/TBF/BenchControl/Elde/ControlBoardDev.cs @@ -18,6 +18,8 @@ namespace TBF.BenchControl.Elde private static readonly ILog log = LogManager.GetLogger(typeof(ControlBoardDev)); public override string ToString() { return string.Format("ControlBoard({0})", Cfg.ToString(1)); } + const int FiltersCount = 8; + readonly ControlBoardCfg controlBoardCfg; /// @@ -79,48 +81,22 @@ namespace TBF.BenchControl.Elde bool previousEmergencyStop; - - private int flowmeterNr4DiverterTest; - private bool scheduleDiverterToTank; - private bool scheduleDiverterToSink; - private bool scheduleReadDiverterTransition; - private bool pumpPowerChanged; - /// - public void DiverterToTank(int flowmeterNr) + public void DiverterToTank(int flowMtrNr) { - if (!scheduleDiverterToSink && !scheduleReadDiverterTransition && !emergencyStop) - { - flowmeterNr4DiverterTest = flowmeterNr; - scheduleDiverterToTank = true; - } + cbCommandQueue.Enqueue(new SendCommandArgs(Command.Start, flowMtrNr, int.MaxValue, int.MaxValue, TestMethods.Diverter | TestMethods.Synchro, StopDevs.None)); } /// - public void DiverterToSink(int flowmeterNr) + public void DiverterToSink(int flowMtrNr) { - if (!scheduleDiverterToTank && !scheduleReadDiverterTransition && !emergencyStop) - { - flowmeterNr4DiverterTest = flowmeterNr; - scheduleDiverterToSink = true; - } + cbCommandQueue.Enqueue(new SendCommandArgs(Command.Stop, 0, 0, 0, TestMethods.Diverter, + StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation)); } /// - public void ReadDiverterTransition(int flowmeterNr) + public void ReadDiverterTransition(int flowMtrNr) { - if (!scheduleDiverterToTank && !scheduleDiverterToSink && !emergencyStop) - { - flowmeterNr4DiverterTest = flowmeterNr; - scheduleReadDiverterTransition = true; - } + cbCommandQueue.Enqueue(new SendCommandArgs(Command.ReadDivTransition, flowMtrNr, 0, 0, TestMethods.Diverter, 0)); } - - - /// State of valves sent out - buffered by the last SendCommand() - public UInt128 Route { get { return benchModelRoute; } } - - UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves - readonly UInt128 routeMask; /// This mask masks out virtual valves, routeMask is set in the constructor - /// /// Initialization data updated by constructors of children components /// and sent to 'controlCom2panel' by SendCalibData() method. @@ -177,21 +153,22 @@ namespace TBF.BenchControl.Elde public uint[] BalanceRange = new uint[2]; - /// - /// Private values sent by the last SendCommand() - /// - bool sendCommandFlag; - Command cmd; - int refNr; + + Queue cbCommandQueue; + + /// + /// Route: 128-bit word representing the current state of all valves and pumps + /// + public UInt128 Route { get { return benchModelRoute; } } UInt128 benchModelRoute; - int totalRefPulses; - int massRefPulses; - TestMethods testMethods; + UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves + readonly UInt128 routeMask; /// This mask masks out virtual valves, routeMask is set in the constructor + int[] filters; float[] FMFreq; int regConst; int shortImp; - StopDevs stopDevs; + /// @@ -214,6 +191,8 @@ namespace TBF.BenchControl.Elde /// Power (0.0f .. 100.0f) public void SetFMFreq(int index, float power) { + bool pumpPowerChanged = false; + #if DN100 || MUNICH || FUZHOU_150 if ((FMFreq == null) || (FMFreq.Length != 2)) { @@ -292,6 +271,9 @@ namespace TBF.BenchControl.Elde { controlBoardCfg = cfg as ControlBoardCfg; + cbCommandQueue = new Queue(); + lastSentFilters = new uint[FiltersCount]; + #if DN100 || MUNICH || FUZHOU_150 FMFreq = new float[2] { 0, 0 }; /// Nr. of pumps: Fuzhou150=2, Fuzhou300=6, newer=6 #elif SLM_END || WARSAW_END @@ -379,7 +361,9 @@ namespace TBF.BenchControl.Elde log.FatalFormat("Successfully initialized device {0}", ToString()); } - /// Run this device + /// + /// Run this device + /// public void RunDeviceBefore() { if (DebugLevel == DebugMode.Simulate) return; @@ -400,95 +384,89 @@ namespace TBF.BenchControl.Elde { UiBridge.Bridge.OnEmergencyStopChanged(this,UiBridge.EmergencyStopEventArgs.State.CloseForm); } - - if (emergencyStop) - { - /// SendCommand() arguments to clear the emergency stop state - sendCommandFlag = true; - this.refNr = 0; - this.totalRefPulses = 0; - this.massRefPulses = 0; - this.cmd = Command.Stop; - this.testMethods = 0; - this.stopDevs = StopDevs.All; - } - else if (scheduleDiverterToTank) - { - /// Reset all SendCommand() arguments - sendCommandFlag = true; - this.cmd = Command.Start; - this.refNr = flowmeterNr4DiverterTest; - this.totalRefPulses = int.MaxValue; - this.massRefPulses = int.MaxValue; - this.testMethods = TestMethods.Diverter; - this.stopDevs = 0; - scheduleDiverterToTank = false; - } - else if (scheduleDiverterToSink) - { - /// Reset all SendCommand() arguments - sendCommandFlag = true; - this.cmd = Command.Stop; - this.refNr = flowmeterNr4DiverterTest; - this.totalRefPulses = 0; - this.massRefPulses = 0; - this.testMethods = TestMethods.Diverter; - this.stopDevs = StopDevs.Diverter; - scheduleDiverterToSink = false; - } - else if (scheduleReadDiverterTransition) - { - /// Reset all SendCommand() arguments - sendCommandFlag = true; - this.cmd = Command.ReadDivTransition; - this.refNr = flowmeterNr4DiverterTest; - this.totalRefPulses = 0; - this.massRefPulses = 0; - this.testMethods = TestMethods.Diverter; - this.stopDevs = 0; - scheduleReadDiverterTransition = false; - } - else if (pumpPowerChanged) - { - /// Reset all SendCommand() arguments - sendCommandFlag = true; - this.cmd = Command.None; - pumpPowerChanged = false; - } - else - { - /// Reset all SendCommand() arguments - sendCommandFlag = false; - this.cmd = Command.None; - this.refNr = 0; - this.totalRefPulses = 0; - this.massRefPulses = 0; - this.testMethods = 0; - this.stopDevs = 0; - } - - if (this.filters == null) this.filters = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, }; } - /// Run this device + /// + /// Used in RunDeviceAfter() when sending commands + /// + UInt128 lastSentRoute; + uint[] lastSentFilters; + float[] lastSentFMFreq; + int lastsentRegConst; + int lastSentShortImp; + + /// + /// Run this device + /// public void RunDeviceAfter() { if (DebugLevel == DebugMode.Simulate) return; UpdateWeights(); - uint[] uintFilters = new uint[8]; - for (int i = 0; i < 8; i++) + /// Modify queue in case of emergency stop + if (emergencyStop && !previousEmergencyStop) { - uintFilters[i] = (filters.Length > i) ? (uint)filters[i] : uintFilters[i - 1]; + /// SendCommand() arguments to clear the emergency stop state + cbCommandQueue.Clear(); + cbCommandQueue.Enqueue(new SendCommandArgs(Command.Stop, 0, 0, 0, 0, StopDevs.All)); } - /// - if (sendCommandFlag) + /// Prepare uintFilters array and evaluate changes + uint[] uintFilters = new uint[FiltersCount]; + uintFilters[0] = (filters != null && filters.Length > 0) ? (uint)filters[0] : 0; + bool filtersAreDifferent = (uintFilters[0] != lastSentFilters[0]); + for (int i = 1; i < FiltersCount; i++) { - controlCom.SendCommand(cmd, refNr, (benchModelRoute & routeMask), - totalRefPulses, massRefPulses, testMethods, - uintFilters, FMFreq, regConst, shortImp, stopDevs); + uintFilters[i] = (filters != null && filters.Length > i) ? (uint)filters[i] : uintFilters[i - 1]; + filtersAreDifferent |= (uintFilters[i] != lastSentFilters[i]); + } + + /// Evaluate FMFreq changes + bool fmFreqsAreDifferent = false; + if ((FMFreq == null) || (lastSentFMFreq == null) || (FMFreq.Length != lastSentFMFreq.Length)) + { + fmFreqsAreDifferent = true; + } + else + { + for (int i = 0; i < FMFreq.Length; i++) + { + if (FMFreq[i] != lastSentFMFreq[i]) + { + fmFreqsAreDifferent = true; + break; + } + } + } + + if (cbCommandQueue.Count > 0) + { + /// There is a command in the queue + /// + controlCom.SendCommand(cbCommandQueue.Dequeue(), (benchModelRoute & routeMask), uintFilters, FMFreq, regConst, shortImp); + + lastSentRoute = (benchModelRoute & routeMask); + lastSentFilters = uintFilters; + lastSentFMFreq = FMFreq; + lastsentRegConst = regConst; + lastSentShortImp = shortImp; + } + else if (((benchModelRoute & routeMask) != lastSentRoute) || + filtersAreDifferent || + fmFreqsAreDifferent || + (lastsentRegConst != regConst) || + (lastSentShortImp != shortImp)) + { + /// Command queue is mepty, but 'route', pump frequency, PID coef., filters or shortImp have changed + /// + controlCom.SendCommand(new SendCommandArgs(Command.None, 0, 0, 0, 0, 0), (benchModelRoute & routeMask), uintFilters, FMFreq, regConst, shortImp); + + lastSentRoute = (benchModelRoute & routeMask); + lastSentFilters = uintFilters; + lastSentFMFreq = FMFreq; + lastsentRegConst = regConst; + lastSentShortImp = shortImp; } controlCom.RunDeviceAfter(); @@ -512,25 +490,17 @@ namespace TBF.BenchControl.Elde /// /// See ControlBoard.Command enum /// Number of the etalon/reference (1..5) - /// Route: 64-bit installation specific number + /// State of valves, 128-bit word /// kolko impulzov ma trvat skuska /// See ControlBoard.TestMethods enum /// 0 = No filtering (0..255) /// Coefficient used to control reg. valves (1..100) /// 0 = default value, 1 = spec. processing of very short pulses /// What to stop - public void SendCommand(Command cmd, int refFlowmtrNr, UInt128 route, - int totalRefPulses, int massRefPulses, TestMethods testMethods, StopDevs stopDevs) + public void SendCommand(Command cmd, int refFlowmtrNr, int totalRefPulses, int massRefPulses, + TestMethods testMethods, StopDevs stopDevs) { - this.cmd = cmd; - this.refNr = refFlowmtrNr; - this.benchModelRoute = route; - this.totalRefPulses = totalRefPulses; - this.massRefPulses = massRefPulses; - this.testMethods = testMethods; - this.stopDevs = stopDevs; - - sendCommandFlag = true; + cbCommandQueue.Enqueue(new SendCommandArgs(cmd, refFlowmtrNr, totalRefPulses, massRefPulses, testMethods, stopDevs)); } /// @@ -545,7 +515,6 @@ namespace TBF.BenchControl.Elde benchModelRoute = (((benchModelRoute ^ valvesToInvert) | valvesToOpen) & (~valvesToClose)) ^ valvesToInvert; foreach (var extV in extendedValves) extV.UpdateRoute(ref benchModelRoute); log.DebugFormat("SetValves(x,x), new route = {0}", Utils.RouteToStr(benchModelRoute)); - sendCommandFlag = true; return oldRoute ^ benchModelRoute; } diff --git a/TBF/BenchControl/Elde/ControlComSim.cs b/TBF/BenchControl/Elde/ControlComSim.cs index 323454498..faa54b993 100644 --- a/TBF/BenchControl/Elde/ControlComSim.cs +++ b/TBF/BenchControl/Elde/ControlComSim.cs @@ -169,7 +169,7 @@ namespace TBF.BenchControl.Elde /// /// See ControlBoard.Command enum /// Number of the etalon/reference (1..5) - /// Route: 64-bit installation specific number + /// State of valves, 128-bit word /// kolko impulzov ma trvat skuska /// See ControlBoard.TestMethods enum /// 0 = No filtering (0..255) @@ -177,17 +177,15 @@ namespace TBF.BenchControl.Elde /// Coefficient used to control reg. valves (1..100) /// 0 = default value, 1 = spec. processing of very short pulses /// What to stop - public void SendCommand(Command cmd, int refFlowmtrNr, UInt128 route, - int totalRefPulses, int massRefPulses, TestMethods testMethods, - uint[] filterConstants, float[] fmFreq, int regConst, int shortImp, StopDevs stopDevs) + public void SendCommand(SendCommandArgs sendCommandArgs, UInt128 route, uint[] filterConstants, float[] fmFreq, int regConst, int shortImp) { log.InfoFormat("SendCommand(Cmd={0},Ref#={1},Route={2} {3} {4} {5},TotalPls={6},MassPls={7},TstM={8},filt={9},FM=[{10}{11}{12}{13}{14}{15}],Reg={16},ShrtImp={17},Stop={18})", - cmd, refFlowmtrNr, /// 0, 1 - ((route >> 48) & 0xFFFF).ToString("X4"), /// 2 - ((route >> 32) & 0xFFFF).ToString("X4"), /// 3 - ((route >> 16) & 0xFFFF).ToString("X4"), /// 4 - (route & 0xFFFF).ToString("X4"), /// 5 - totalRefPulses, massRefPulses, testMethods, filterConstants, /// 6, 7, 8, 9 + sendCommandArgs.Cmd, sendCommandArgs.RefFlowmtrNr, /// 0, 1 + ((route >> 48) & 0xFFFF).ToString("X4"), /// 2 + ((route >> 32) & 0xFFFF).ToString("X4"), /// 3 + ((route >> 16) & 0xFFFF).ToString("X4"), /// 4 + (route & 0xFFFF).ToString("X4"), /// 5 + totalRefPulses, massRefPulses, testMethods, filterConstants, /// 6, 7, 8, 9 fmFreq[0].ToString(), /// 10 (fmFreq.Length > 1) ? ("," + fmFreq[1].ToString()) : "", /// 11 (fmFreq.Length > 2) ? ("," + fmFreq[2].ToString()) : "", /// 12 @@ -199,8 +197,8 @@ namespace TBF.BenchControl.Elde /// Simulation /// Command lastCmd = this.cmd; - this.cmd = cmd; - this.refFlowmtrNr = refFlowmtrNr; + this.cmd = sendCommandArgs.Cmd; + this.refFlowmtrNr = sendCommandArgs.RefFlowmtrNr; #if FUZHOU_300 /// @@ -214,14 +212,14 @@ namespace TBF.BenchControl.Elde log.DebugFormat("SendCommand route = {0}", Utils.RouteToStr(route)); #endif TestBenchSim.SimRoute = this.simRoute = route; - this.totalRefPulses = totalRefPulses; - this.massRefPulses = massRefPulses; - this.testMethods = testMethods; - this.filterConstants = filterConstants; + this.totalRefPulses = sendCommandArgs.TotalRefPulses; + this.massRefPulses = sendCommandArgs.MassRefPulses; + this.testMethods = sendCommandArgs.TestMethods; + this.stopDevs = sendCommandArgs.StopDevs; + this.filterConstants = filterConstants; this.FMFreq = fmFreq; this.regConst = regConst; this.shortImp = shortImp; - this.stopDevs = stopDevs; #pragma warning disable statusP = (StatusP)(((ulong)statusP & (ulong)0xFFFFFFFFFFFFFFF8L) | (ulong)refFlowmtrNr); diff --git a/TBF/BenchControl/Elde/ControlComWrap.cs b/TBF/BenchControl/Elde/ControlComWrap.cs index 31af7187b..aeca80bbf 100644 --- a/TBF/BenchControl/Elde/ControlComWrap.cs +++ b/TBF/BenchControl/Elde/ControlComWrap.cs @@ -308,63 +308,35 @@ namespace TBF.BenchControl.Elde /// /// Sends a command to the control board. /// - /// See ControlBoard.Command enum - /// Reference flow meter number (1..5) - /// Route: 64-bit installation specific number - /// Test duration as a number of reference flow meter pulses - /// See ControlBoard.TestMethods enum - /// 0 = No filtering (0..255) - /// Freq.inverter control (not applicable in DT100, Munich) - /// Coefficient used to control the regulation valve (1..100) + /// Arguments + /// State of valves, 128-bit word + /// Array with length=8 of filter costants (0..255, 0 = no filtering) + /// Freq.inverter control (not applicable in DT100, Munich) + /// PID coefficient for flow control /// 0 = default value, 1 = spec. processing of very short pulses - /// What to stop - public void SendCommand(Command cmd, int refFlowMeterNr, UInt128 route, - int totalRefPulses, int massRefPulses, TestMethods testMethods, - uint[] filterConstants, float[] fmFreq, int regConst, int shortImp, StopDevs stopDevs) + public void SendCommand(SendCommandArgs sendCommandArgs, UInt128 route, uint[] filterConstants, float[] fmFreq, int regConst, int shortImp) { if (Program.MainWnd.InvokeRequired) { - /// When SendCommand(...) called from the worker thread - object[] args = new object[] { cmd, refFlowMeterNr, route, totalRefPulses, massRefPulses, - testMethods, filterConstants, fmFreq, regConst, shortImp, stopDevs }; - Program.MainWnd.Invoke((SendCommandDlgt)DoSendCommand, args); /// Component was created in UI thread - use Invoke() + /// From another thread ... use Invoke() + Program.MainWnd.Invoke((SendCommandDlgt)DoSendCommand, new object[] { sendCommandArgs, route, filterConstants, fmFreq, regConst, shortImp }); } else { - /// When SendCommand(...) called from the UI thread - DoSendCommand(cmd, refFlowMeterNr, route, totalRefPulses, massRefPulses, testMethods, - filterConstants, fmFreq, regConst, shortImp, stopDevs); + /// Call DoSendCommand() directly + DoSendCommand(sendCommandArgs, route, filterConstants, fmFreq, regConst, shortImp); } } /// - delegate void SendCommandDlgt(Command cmd, int refFlowmtrNr, UInt128 route, - int totalRefPulses, int massRefPulses, TestMethods testMethods, - uint[] filterConstants, float[] fmFreq, int regConst, int shortImp, StopDevs stopDevs); + delegate void SendCommandDlgt(SendCommandArgs sendCommandArgs, UInt128 route, uint[] filterConstants, float[] fmFreq, int regConst, int shortImp); /// - private void DoSendCommand(Command cmd, int refFlowMeterNr, UInt128 route, - int totalRefPulses, int massRefPulses, TestMethods testMethods, - uint[] filterConstants, float[] fmFreq, int regConst, int shortImp, StopDevs stopDevs) + private void DoSendCommand(SendCommandArgs sendCommandArgs, UInt128 route, uint[] filterConstants, float[] fmFreq, int regConst, int shortImp) { - //TBF.UiBridge.Bridge.OnLog(this, string.Format("{0} SendCommand({1}, {2}, {3}, {4}, {5}, {6}, [{7},{8}], {9}, {10}, {11})\r\n", - // DateTime.Now.ToLongTimeString(), - // cmd, - // refFlowMeterNr, - // route.ToString("X"), - // totalRefPulses, - // testMethods, - // filterConstant, - // fmFreq[0], - // fmFreq[1], - // regConst, - // shortImp, - // stopDevs)); - - #if FUZHOU_300 /// /// The following code deals with the situation that all FM controlled pumps share bit #39. /// In settings the bits of pumps should be sent as follows: P1=50, P2=51, P3=52, P4=53, P5=54 and P7=55 - /// (in FUZHOU_300 the FM pump bit should be set set to value FMIndex+50). + /// (in FUZHOU_300 the FM pump bit should be set to value FMIndex+50). /// bool bit39 = (route & 0x00FC000000000000) != 0; /// true if any of bits 50 through 55 is set route = route & 0xFF03FFFFFFFFFFFF; @@ -381,49 +353,100 @@ namespace TBF.BenchControl.Elde route = route & (~(((UInt128)1) << 80)); #endif - log.InfoFormat("DoSendCommand(Cmd={0},Ref#={1},Route={2},TotalPls={3},MassPls={4},TM={5},filt={6},FM=[{7}{8}{9}{10}{11}{12}],Reg={13},ShrtImp={14},Stop={15})", - cmd, /// 0 - refFlowMeterNr, /// 1 - Utils.RouteToStr(route), /// 2 - totalRefPulses, massRefPulses, testMethods, filterConstants, /// 3, 4, 5, 6 + log.InfoFormat("DoSendCommand(Cmd={0},Ref#={1},Route={2},TotalPls={3},MassPls={4},TM={5},filt={6},FM=[{7}{8}{9}{10}{11}{12}],Reg={13},ShrtImp={14},Stop={15})", + sendCommandArgs.Cmd, /// 0 + sendCommandArgs.RefFlowmtrNr, /// 1 + Utils.RouteToStr(route), /// 2 + sendCommandArgs.TotalRefPulses, + sendCommandArgs.MassRefPulses, + sendCommandArgs.TestMethods, + filterConstants, /// 3, 4, 5, 6 fmFreq[0].ToString(), /// 7 (fmFreq.Length > 1) ? ("," + fmFreq[1].ToString()) : "", /// 8 (fmFreq.Length > 2) ? ("," + fmFreq[2].ToString()) : "", /// 9 (fmFreq.Length > 3) ? ("," + fmFreq[3].ToString()) : "", /// 10 (fmFreq.Length > 4) ? ("," + fmFreq[4].ToString()) : "", /// 11 (fmFreq.Length > 5) ? ("," + fmFreq[5].ToString()) : "", /// 12 - regConst, shortImp, stopDevs); /// 13, 14, 15 + regConst, /// 13 + shortImp, /// 14 + sendCommandArgs.StopDevs); /// 15 #if DN100 || MUNICH - ctrlBrdComponent.SendCommand((uint)cmd, (byte)refFlowMeterNr, (ulong)route, (uint)totalRefPulses, (uint)testMethods, - Convert.ToSingle(filterConstants[0]), fmFreq[0], (uint)regConst, (uint)shortImp, (uint)stopDevs); + ctrlBrdComponent.SendCommand((uint)sendCommandArgs.Cmd, + (byte)sendCommandArgs.RefFlowmtrNr, + (ulong)route, + (uint)sendCommandArgs.TotalRefPulses, + (uint)sendCommandArgs.TestMethods, + Convert.ToSingle(filterConstants[0]), + fmFreq[0], + (uint)regConst, + (uint)shortImp, + (uint)sendCommandArgs.StopDevs); #elif BADGER_MALA_TRAT || BADGER_VELKA_TRAT || FUZHOU_50 || FUZHOU_150 || FUZHOU_300 || IZRAEL_200 || TORINO_50 || TORUN_50 || CEVAK_40 || MURES_40 - ctrlBrdComponent.SendCommand((uint)cmd, (byte)refFlowMeterNr, (ulong)route, (uint)totalRefPulses, (uint)testMethods, - Convert.ToSingle(filterConstants[0]), fmFreq, (uint)regConst, (uint)shortImp, (uint)stopDevs); + ctrlBrdComponent.SendCommand((uint)sendCommandArgs.Cmd, + (byte)sendCommandArgs.RefFlowmtrNr, + (ulong)route, + (uint)sendCommandArgs.TotalRefPulses, + (uint)sendCommandArgs.TestMethods, + Convert.ToSingle(filterConstants[0]), + fmFreq, + (uint)regConst, + (uint)shortImp, + (uint)sendCommandArgs.StopDevs); #elif BERLIN || SLM_150 || PETERSBURG_200 - uint[] pulsesArr = new uint[] { (uint)totalRefPulses, (uint)massRefPulses }; - ctrlBrdComponent.SendCommand((uint)cmd, (byte)refFlowMeterNr, (ulong)(route & (UInt128)0xFFFFFFFFFFFFFFFF), (ulong)(route >> 64), pulsesArr, (uint)testMethods, - Convert.ToSingle(filterConstants[0]), fmFreq, (uint)regConst, (uint)shortImp, (uint)stopDevs); + ctrlBrdComponent.SendCommand((uint)sendCommandArgs.Cmd, + (byte)sendCommandArgs.RefFlowmtrNr, + (ulong)(route & (UInt128)0xFFFFFFFFFFFFFFFF), + (ulong)(route >> 64), + new uint[] { (uint)sendCommandArgs.TotalRefPulses, (uint)sendCommandArgs.MassRefPulses }, + (uint)sendCommandArgs.TestMethods, + Convert.ToSingle(filterConstants[0]), + fmFreq, + (uint)regConst, + (uint)shortImp, + (uint)sendCommandArgs.StopDevs); #elif GENESIS || DEWA_300 - uint[] pulsesArr = new uint[] { (uint)totalRefPulses, (uint)massRefPulses }; - ctrlBrdComponent.SendCommand((uint)cmd, (byte)refFlowMeterNr, (ulong)(route & (UInt128)0xFFFFFFFFFFFFFFFF), (ulong)(route >> 64), pulsesArr, (uint)testMethods, - filterConstants, fmFreq, (uint)regConst, (uint)shortImp, (uint)stopDevs); + ctrlBrdComponent.SendCommand((uint)sendCommandArgs.Cmd, + (byte)sendCommandArgs.RefFlowmtrNr, + (ulong)(route & (UInt128)0xFFFFFFFFFFFFFFFF), + (ulong)(route >> 64), + new uint[] { (uint)sendCommandArgs.TotalRefPulses, (uint)sendCommandArgs.MassRefPulses }, + (uint)sendCommandArgs.TestMethods, + filterConstants, + fmFreq, + (uint)regConst, + (uint)shortImp, + (uint)sendCommandArgs.StopDevs); #elif JUZNA_AFRIKA_50 || IZRAEL_25 || ZAMBIA || ZODINO || FEWA_50 || FILIPINY_50 || SENTEC || FUZHOU_100 || CEVAK_200 || IZRAEL_50 - uint[] pulsesArr = new uint[] { (uint)totalRefPulses, (uint)massRefPulses }; - ctrlBrdComponent.SendCommand((uint)cmd, (byte)refFlowMeterNr, (ulong)route, pulsesArr, (uint)testMethods, - filterConstants, fmFreq, (uint)regConst, (uint)shortImp, (uint)stopDevs); + ctrlBrdComponent.SendCommand((uint)sendCommandArgs.Cmd, + (byte)sendCommandArgs.RefFlowmtrNr, + (ulong)route, + new uint[] { (uint)sendCommandArgs.TotalRefPulses, (uint)sendCommandArgs.MassRefPulses }, + (uint)sendCommandArgs.TestMethods, + filterConstants, + fmFreq, + (uint)regConst, + (uint)shortImp, + (uint)sendCommandArgs.StopDevs); #else /// if TURA_IPERL || TURA_IPERL_NEW || TURA_SPECIAL || MALTA_WSD25 || SLM_50 || SLM_END || WARSAW_END || PETERSBURG_50 || KEMPNO_50 || BAHRAIN_50 || RUM_MOB || KRAKOW_50 || BADGER_STREDNA_TRAT || PUCHONG_200 - uint[] pulsesArr = new uint[] { (uint)totalRefPulses, (uint)massRefPulses }; - ctrlBrdComponent.SendCommand((uint)cmd, (byte)refFlowMeterNr, (ulong)route, pulsesArr, (uint)testMethods, - Convert.ToSingle(filterConstants[0]), fmFreq, (uint)regConst, (uint)shortImp, (uint)stopDevs); + ctrlBrdComponent.SendCommand((uint)sendCommandArgs.Cmd, + (byte)sendCommandArgs.RefFlowmtrNr, + (ulong)route, + new uint[] { (uint)sendCommandArgs.TotalRefPulses, (uint)sendCommandArgs.MassRefPulses }, + (uint)sendCommandArgs.TestMethods, + Convert.ToSingle(filterConstants[0]), + fmFreq, + (uint)regConst, + (uint)shortImp, + (uint)sendCommandArgs.StopDevs); #endif log.DebugFormat("DoSendCommand() Route = {0}", Utils.RouteToStr(route)); - if (lastRoute != route) /// This is to update the MainWnd status bar on changes only + if (lastRoute != route) /// This is to update the MainWnd status bar on changes only { UInt128 rRoute = RRoute; Program.MainWnd.UpdateRoute(string.Format("{0} ({1})", Utils.RouteToStr(route), Utils.RouteToStr(rRoute))); - lastRoute = route; + lastRoute = route; } } diff --git a/TBF/BenchControl/Elde/ExecuteCommandOp.cs b/TBF/BenchControl/Elde/ExecuteCommandOp.cs index 20e9c9f74..9c90a2e66 100644 --- a/TBF/BenchControl/Elde/ExecuteCommandOp.cs +++ b/TBF/BenchControl/Elde/ExecuteCommandOp.cs @@ -56,7 +56,7 @@ namespace TBF.BenchControl.Elde public void Start() { controlBoard.SyncRoute(); - controlBoard.SendCommand(commandOnStartOp, 0, controlBoard.Route, 0, 0, testMethod, StopDevs.None); + controlBoard.SendCommand(commandOnStartOp, 0, 0, 0, testMethod, StopDevs.None); opState = OpState.StartingCommand; } @@ -99,7 +99,7 @@ namespace TBF.BenchControl.Elde if (commandOnStopOp != Command.None) { controlBoard.SyncRoute(); - controlBoard.SendCommand(commandOnStopOp, 0, controlBoard.Route, 0, 0, testMethod, StopDevs.None); + controlBoard.SendCommand(commandOnStopOp, 0, 0, 0, testMethod, StopDevs.None); } } } diff --git a/TBF/BenchControl/Elde/IControlCom.cs b/TBF/BenchControl/Elde/IControlCom.cs index 3709ad6eb..e105b589a 100644 --- a/TBF/BenchControl/Elde/IControlCom.cs +++ b/TBF/BenchControl/Elde/IControlCom.cs @@ -61,19 +61,13 @@ namespace TBF.BenchControl.Elde /// /// Updates a command that is regularly sent to the control board by SendCommand. /// - /// See ControlBoard.Command enum - /// Number of the etalon/reference (1..5) - /// Route: 64-bit installation specific number - /// Kolko impulzov ma trvat skuska - /// Pri 'MassAndContinue' metode kolko impulzov ma trvat mass measurement - /// See ControlBoard.TestMethods enum - /// 0 = No filtering (0..255) - /// Freq.inverter control (not applicable in DT100, Munich) - /// Coefficient used to control reg. valves (1..100) - /// 0 = default value, 1 = spec. processing of very short pulses - /// What to stop - void SendCommand(Command cmd, int refNr, UInt128 route, int totalRefPulses, int massRefPulses, TestMethods testMethods, - uint[] filterConstants, float[] fmFreq, int regConst, int shortImp, StopDevs stopDevs); + /// Arguments, see SendCommandArgs class + /// State of valves, 128-bit word + /// Array with length=8 of filter costants (0..255, 0 = no filtering) + /// Freq.inverter control (not applicable in DT100, Munich) + /// PID coefficient for flow control + /// 0 = default value, 1 = spec. processing of very short pulses + void SendCommand(SendCommandArgs sendCommandArgs, UInt128 route, uint[] filterConstants, float[] fmFreq, int regConst, int shortImp); /// /// Control of regulating valves. diff --git a/TBF/BenchControl/Elde/ReadDiverterTransitionOp.cs b/TBF/BenchControl/Elde/ReadDiverterTransitionOp.cs index 553f555da..992f79bfa 100644 --- a/TBF/BenchControl/Elde/ReadDiverterTransitionOp.cs +++ b/TBF/BenchControl/Elde/ReadDiverterTransitionOp.cs @@ -132,7 +132,7 @@ namespace TBF.BenchControl.Elde void SendCommand() { controlBoard.SyncRoute(); - controlBoard.SendCommand(Command.ReadDivTransition, 0, controlBoard.Route, 0, 0, 0, StopDevs.None); + controlBoard.SendCommand(Command.ReadDivTransition, 0, 0, 0, 0, StopDevs.None); cmdSent = true; } diff --git a/TBF/BenchControl/Elde/RegulValve/SetFlowOp.cs b/TBF/BenchControl/Elde/RegulValve/SetFlowOp.cs index 5ec8bc1f6..3ebfbbf66 100644 --- a/TBF/BenchControl/Elde/RegulValve/SetFlowOp.cs +++ b/TBF/BenchControl/Elde/RegulValve/SetFlowOp.cs @@ -198,11 +198,8 @@ namespace TBF.BenchControl.Elde.RegulValve opState = OpState.ValveMoveToFlow1; } - TestMethods tm = 0; - StopDevs sd = 0; - // '_regulValve.RegulValveCfg.PidCoef' replaced by a casted operation parameter 'pidCoef' - controlBoard.SendCommand(Command.Start, flowMeter.Idx1, controlBoard.Route, - int.MaxValue, int.MaxValue, tm, sd); + /// Start flow measurement + controlBoard.SendCommand(Command.Start, flowMeter.Idx1, int.MaxValue, int.MaxValue, 0, 0); /// TestMethods=0, StopDevs=0 } /// Run this operation @@ -250,11 +247,8 @@ namespace TBF.BenchControl.Elde.RegulValve opState = OpState.ValveMoveToFlow1; } - TestMethods tm = 0; - StopDevs sd = 0; - // '_regulValve.RegulValveCfg.PidCoef' replaced by a casted operation parameter 'pidCoef' - controlBoard.SendCommand(Command.Start, flowMeter.Idx1, controlBoard.Route, - int.MaxValue, int.MaxValue, tm, sd); + /// Start flow measurement + controlBoard.SendCommand(Command.Start, flowMeter.Idx1, int.MaxValue, int.MaxValue, 0, 0); /// TestMethods=0, StopDevs=0 return Event.Starting; } else if (opState == OpState.ValveMoveToPosition1) @@ -451,14 +445,13 @@ namespace TBF.BenchControl.Elde.RegulValve /// Start this operation public void Stop() { - opState = OpState.Idle; + if (!leaveMeasurementRunning) + { + /// Stop measurement + controlBoard.SendCommand(Command.Stop, flowMeter.Idx1, 50000, 50000, 0, StopDevs.RegValveRegulation); /// TestMethods=0 + } - if (leaveMeasurementRunning) return; - - /// Stop measurement - TestMethods tm = 0; - StopDevs sd = StopDevs.RegValveRegulation; - controlBoard.SendCommand(Command.Stop, flowMeter.Idx1, controlBoard.Route, 50000, 50000, tm, sd); + opState = OpState.Idle; } } } diff --git a/TBF/BenchControl/Elde/RegulValveCoax/SetFlowOp.cs b/TBF/BenchControl/Elde/RegulValveCoax/SetFlowOp.cs index 623fd9901..aa4697be5 100644 --- a/TBF/BenchControl/Elde/RegulValveCoax/SetFlowOp.cs +++ b/TBF/BenchControl/Elde/RegulValveCoax/SetFlowOp.cs @@ -212,8 +212,7 @@ namespace TBF.BenchControl.Elde.RegulValveCoax TestMethods tm = 0; StopDevs sd = 0; // '_regulValve.RegulValveCfg.PidCoef' replaced by a casted operation parameter 'pidCoef' - controlBoard.SendCommand(Command.Start, flowMeterNr, controlBoard.Route, - int.MaxValue, int.MaxValue, tm, sd); + controlBoard.SendCommand(Command.Start, flowMeterNr, int.MaxValue, int.MaxValue, tm, sd); } /// Run this operation @@ -262,8 +261,7 @@ namespace TBF.BenchControl.Elde.RegulValveCoax TestMethods tm = 0; StopDevs sd = 0; // '_regulValve.RegulValveCfg.PidCoef' replaced by a casted operation parameter 'pidCoef' - controlBoard.SendCommand(Command.Start, flowMeterNr, controlBoard.Route, - int.MaxValue, int.MaxValue, tm, sd); + controlBoard.SendCommand(Command.Start, flowMeterNr, int.MaxValue, int.MaxValue, tm, sd); log.DebugFormat(" return Event.None"); return Event.None; } @@ -479,7 +477,7 @@ namespace TBF.BenchControl.Elde.RegulValveCoax /// Stop measurement TestMethods tm = 0; StopDevs sd = StopDevs.RegValveRegulation; - controlBoard.SendCommand(Command.Stop, flowMeterNr, controlBoard.Route, 50000, 50000, tm, sd); + controlBoard.SendCommand(Command.Stop, flowMeterNr, 50000, 50000, tm, sd); log.WarnFormat("Stop() SendCommand(Stop, {0}, ...)", flowMeterNr); } diff --git a/TBF/BenchControl/Elde/RegulValveTandem/SetFlowOp.cs b/TBF/BenchControl/Elde/RegulValveTandem/SetFlowOp.cs index ab8e69faa..74e06de08 100644 --- a/TBF/BenchControl/Elde/RegulValveTandem/SetFlowOp.cs +++ b/TBF/BenchControl/Elde/RegulValveTandem/SetFlowOp.cs @@ -217,8 +217,7 @@ namespace TBF.BenchControl.Elde.RegulValveTandem TestMethods tm = 0; StopDevs sd = 0; // '_regulValve.RegulValveTandemCfg.PidCoef' replaced by a casted operation parameter 'pidCoef' - controlBoard.SendCommand(Command.Start, flowMeterNr, controlBoard.Route, - int.MaxValue, int.MaxValue, tm, sd); + controlBoard.SendCommand(Command.Start, flowMeterNr, int.MaxValue, int.MaxValue, tm, sd); } /// Run this operation @@ -371,7 +370,7 @@ namespace TBF.BenchControl.Elde.RegulValveTandem /// Stop measurement TestMethods tm = 0; StopDevs sd = StopDevs.RegValveRegulation; - controlBoard.SendCommand(Command.Stop, flowMeterNr, controlBoard.Route, 50000, 50000, tm, sd); + controlBoard.SendCommand(Command.Stop, flowMeterNr, 50000, 50000, tm, sd); } } } diff --git a/TBF/BenchControl/Elde/SendCommandArgs.cs b/TBF/BenchControl/Elde/SendCommandArgs.cs new file mode 100644 index 000000000..8357d1f0c --- /dev/null +++ b/TBF/BenchControl/Elde/SendCommandArgs.cs @@ -0,0 +1,33 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using Dirichlet.Numerics; + +namespace TBF.BenchControl.Elde +{ + public class SendCommandArgs + { + public Command Cmd; + public int RefFlowmtrNr; + public int TotalRefPulses; + public int MassRefPulses; + public TestMethods TestMethods; + public StopDevs StopDevs; + + public SendCommandArgs() + { + } + + public SendCommandArgs(Command cmd, int refFlowmtrNr, int totalRefPulses, int massRefPulses, + TestMethods testMethods, StopDevs stopDevs) + { + Cmd = cmd; + RefFlowmtrNr = refFlowmtrNr; + TotalRefPulses = totalRefPulses; + MassRefPulses = massRefPulses; + TestMethods = testMethods; + StopDevs = stopDevs; + } + } +} diff --git a/TBF/BenchControl/Elde/StartMeasurementOp.cs b/TBF/BenchControl/Elde/StartMeasurementOp.cs index 9fd05a039..42212a5a3 100644 --- a/TBF/BenchControl/Elde/StartMeasurementOp.cs +++ b/TBF/BenchControl/Elde/StartMeasurementOp.cs @@ -125,8 +125,7 @@ namespace TBF.BenchControl.Elde log.InfoFormat("Start() : SendCommand(Cmd.Start, {0}, route, {1}, {1}, {2}, Stop.None)", flowMeterIdxAndDiv, totalRefPulses, testMethod); - controlBoard.SendCommand(Command.Start, flowMeterIdxAndDiv, controlBoard.Route, - totalRefPulses, massRefPulses, testMethod, StopDevs.None); + controlBoard.SendCommand(Command.Start, flowMeterIdxAndDiv, totalRefPulses, massRefPulses, testMethod, StopDevs.None); } /// Start this operation diff --git a/TBF/BenchControl/Elde/StopFlowRegulationOp.cs b/TBF/BenchControl/Elde/StopFlowRegulationOp.cs index 0e923f148..9546d3f86 100644 --- a/TBF/BenchControl/Elde/StopFlowRegulationOp.cs +++ b/TBF/BenchControl/Elde/StopFlowRegulationOp.cs @@ -35,12 +35,7 @@ namespace TBF.BenchControl.Elde void SendStopFlowRegulationCommand() { controlBoard.SyncRoute(); - controlBoard.SendCommand(Command.Stop, - flowMeterNr, /// ref. flowmeter number - controlBoard.Route, /// route - 0, 0, /// ref. pulses - 0, - StopDevs.RegValveRegulation); + controlBoard.SendCommand(Command.Stop, flowMeterNr, 0, 0, 0, StopDevs.RegValveRegulation); } diff --git a/TBF/BenchControl/Elde/StopPreviousOp.cs b/TBF/BenchControl/Elde/StopPreviousOp.cs index 9fdeb765a..a1d3b859b 100644 --- a/TBF/BenchControl/Elde/StopPreviousOp.cs +++ b/TBF/BenchControl/Elde/StopPreviousOp.cs @@ -43,11 +43,7 @@ namespace TBF.BenchControl.Elde void SendStopCommand() { controlBoard.SyncRoute(); - controlBoard.SendCommand(Command.Stop, - 0, /// ref. flowmeter number - controlBoard.Route, /// route - 0, 0, /// ref. pulses - TestMethods.Diverter, + controlBoard.SendCommand(Command.Stop, 0, 0, 0, TestMethods.Diverter, StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation); } diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 025812146..b852173ff 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -572,6 +572,7 @@ +