UniCB DrShp, AltStrings, double Press, new Cfg style, Lbl,Setp,Msrd pos != 0, arrow keys, refactorization, ver. 3.1.1597

This commit is contained in:
Milan Hanajik
2021-03-01 15:22:37 +01:00
parent b5f8d06e5b
commit 35815fe78a
147 changed files with 2901 additions and 5315 deletions
@@ -666,9 +666,9 @@ namespace TBF.BenchControl.ControlBoard.Legacy
public IOperation SetFlowOp(double reqrdFlowLo, double reqrdFlowHi, TBF.Boxes.DoubleBox measuredFlow, int timeout)
{
if (Devices.RegulValve == null || Devices.FlowMeter == null) return null;
if (Devices.RegValve == null || Devices.FlowMeter == null) return null;
return Devices.RegulValve.SetFlowOp(Devices.FlowMeter, reqrdFlowLo, reqrdFlowHi, measuredFlow, timeout);
return Devices.RegValve.SetFlowOp(Devices.FlowMeter, reqrdFlowLo, reqrdFlowHi, measuredFlow, timeout);
}
@@ -78,16 +78,16 @@ namespace TBF.BenchControl.ControlBoard.Legacy
if (outputPath.FlowMeter == null) throw new ArgumentNullException("Flow meter is missing");
flowMeterNr = outputPath.FlowMeter.Idx1;
this.regulValve = outputPath.RegulValve;
this.regulValve = outputPath.RegValve;
if (regulValve is Elde.RegulValve.RegulValve)
{
Elde.RegulValve.RegulValve rv = outputPath.RegulValve as Elde.RegulValve.RegulValve;
Elde.RegulValve.RegulValve rv = outputPath.RegValve as Elde.RegulValve.RegulValve;
regulValveNr = rv.Idx1;
regulValveStableTime = rv.StableTime;
}
else if (regulValve is Elde.RegulValveCoax.RegulValve)
{
Elde.RegulValveCoax.RegulValve rv = outputPath.RegulValve as Elde.RegulValveCoax.RegulValve;
Elde.RegulValveCoax.RegulValve rv = outputPath.RegValve as Elde.RegulValveCoax.RegulValve;
regulValveNr = rv.Idx1;
regulValveStableTime = rv.StableTime;
}
@@ -142,31 +142,8 @@ namespace TBF.BenchControl.ControlBoard.Papouch
RequestInputs();
}
///
/// Collect measured values
///
if (ProcessData.MeasuredValues == null || ProcessData.Setpoints.Length != ProcessData.ComponentsWithMeasuredVal.Count)
{
ProcessData.MeasuredValues = new double[ProcessData.ComponentsWithMeasuredVal.Count];
}
for (int i = 0; i < ProcessData.ComponentsWithMeasuredVal.Count; i++)
{
ProcessData.MeasuredValues[i] = ProcessData.ComponentsWithMeasuredVal[i].MeasuredVal;
}
///
/// Collect setpoints
///
if (ProcessData.Setpoints == null || ProcessData.Setpoints.Length != ProcessData.ComponentsWithSetpoint.Count)
{
ProcessData.Setpoints = new double[ProcessData.ComponentsWithSetpoint.Count];
}
for (int i = 0; i < ProcessData.ComponentsWithSetpoint.Count; i++)
{
ProcessData.Setpoints[i] = ProcessData.ComponentsWithSetpoint[i].SetpointVal;
}
TBF.UiBridge.Bridge.OnStateMachineTick(this, new TBF.UiBridge.StateMachineTickEventArgs(benchModelRoute, ProcessData.MeasuredValues, ProcessData.Setpoints));
ProcessData.UpdateMeasuredValuesAndSetpoints();
TBF.UiBridge.Bridge.OnStateMachineTick(this, new TBF.UiBridge.StateMachineTickEventArgs(benchModelRoute, ProcessData.MeasuredValues, ProcessData.AltStrings, ProcessData.Setpoints));
}
public void StopDevice()
@@ -377,7 +354,7 @@ namespace TBF.BenchControl.ControlBoard.Papouch
string loLimStr = reqrdFlowLo.ToString(Config.Utils.SignificantDigitsToFmt(reqrdFlowLo, 2));
string hiLimStr = reqrdFlowHi.ToString(Config.Utils.SignificantDigitsToFmt(reqrdFlowHi, 2));
this.promptMsg = string.Format("Set flow measured by {0} withing {1} and {2} m3/h by regulation valve {3}",
devices.FlowMeter.Name, loLimStr, hiLimStr, devices.RegulValve.Name);
devices.FlowMeter.Name, loLimStr, hiLimStr, devices.RegValve.Name);
this.backColor = System.Drawing.Color.LightSalmon;
scheduledOp = SelectedOp.SetFlow;
+34 -20
View File
@@ -10,20 +10,30 @@ using Common;
using Config.Entities;
using Dirichlet.Numerics;
using TBF.BenchControl.GenericDevices;
using TBF.BenchControl.Sequences;
namespace TBF.BenchControl.ControlBoard.Uni
{
public class CBoard : ComponentBase, IControlBoard
public class CBoard : ComponentBase, IControlBoard, SchematicDrawing.IDrawingItCmpntWithMeasuredVal
{
private static readonly ILog log = LogManager.GetLogger(typeof(CBoard));
public override string ToString() { return string.Format("CBoard({0})", cBoardCfg != null ? cBoardCfg.ToString(1) : string.Empty); }
/// TBF component configuration
readonly CBoardCfg cBoardCfg;
/// IDrawingItCmpnt interface implementation
public SchematicDrawing.IDrawingItem DrawingItem { get { return cBoardCfg as SchematicDrawing.IDrawingItem; } }
public double MeasuredVal { get { return 0.1; } }
public string AltString { get { return "hovno"; } }
/// Wrappers
int comPortNr { get { return cBoardCfg.ComPortNr; } }
int virtValvesRngLo { get { return cBoardCfg.VirtValvesRangeLo; } }
int virtValvesRngHi { get { return cBoardCfg.VirtValvesRangeHi; } }
/// Propagated from configurations of other components
UInt128 valvesToInvert;
@@ -75,7 +85,16 @@ namespace TBF.BenchControl.ControlBoard.Uni
/// Select devices used for control and measurement
/// </summary>
/// <param name="outPath"></param>
public OutputPath Devices { set; get; }
public OutputPath Devices
{
set { devices = value; }
get { return devices; }
}
OutputPath devices;
IFlowMeter flowMeter { get { return devices.FlowMeter; } }
IRegulValve regValve { get { return devices.RegValve; } }
IDiverter diverter { get { return devices.Diverter; } }
/// <summary>
@@ -84,6 +103,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
/// </summary>
public CBoard()
{
devices = new OutputPath(string.Empty, 0);
}
/// <summary>
@@ -103,13 +123,14 @@ namespace TBF.BenchControl.ControlBoard.Uni
#endif
cBoardCfg = cfg as CBoardCfg;
devices = new OutputPath(string.Empty, 0);
msgQueue = new Queue<IOutputMessage>();
Data = new GeneralData();
divTransitionData = null;
scopeAnalyzerData = null;
switchCounterData = null;
msgQueue = new Queue<IOutputMessage>();
serialPort = null;
buffer = new byte[BUFFER_SIZE];
rcvdData = new byte[BUFFER_SIZE];
@@ -267,13 +288,12 @@ namespace TBF.BenchControl.ControlBoard.Uni
}
}
if (msgQueue.Count > 0)
{
/// There is a message in the message queue => write it to the serial port
var message = msgQueue.Dequeue();
byte[] outData = message.GetMessage();
serialPort.Write(outData, 0, outData.Length);
IOutputMessage message = (msgQueue.Count > 0) ? msgQueue.Dequeue() : OutputMessage.CreateDataRequestMsg();
byte[] outData = message.GetMessage();
if (outData != null && outData.Length > 0)
{
serialPort.Write(outData, 0, outData.Length);
string s1 = message.ToString();
string s2 = Telegram.LogTelegram("Message ", outData);
Debug.WriteLine(s1);
@@ -281,6 +301,9 @@ namespace TBF.BenchControl.ControlBoard.Uni
log.Debug(s1);
log.Debug(s2);
}
ProcessData.UpdateMeasuredValuesAndSetpoints();
TBF.UiBridge.Bridge.OnStateMachineTick(this, new TBF.UiBridge.StateMachineTickEventArgs(Route, ProcessData.MeasuredValues, ProcessData.AltStrings, ProcessData.Setpoints));
}
public void StopDevice()
@@ -295,16 +318,6 @@ namespace TBF.BenchControl.ControlBoard.Uni
#endregion
public void SendCommand(Command cmd, int etalonNr, int regValveNr, int divNr, ulong totalPulsesCount, ulong massPuleseCount, UInt128 route)
{
msgQueue.Enqueue(new CommandMsg(cmd, etalonNr, regValveNr, divNr, totalPulsesCount, massPuleseCount, route));
}
public void ValveMove(Command cmd, int etalonNr, int regValveNr, int divNr, ulong totalPulsesCount, ulong massPuleseCount, UInt128 route)
{
msgQueue.Enqueue(new CommandMsg(cmd, etalonNr, regValveNr, divNr, totalPulsesCount, massPuleseCount, route));
}
#region IControlBoard interface
///
@@ -322,6 +335,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
///
public IOperation SetFlowOp(double flowLimLo, double flowLimHi, TBF.Boxes.DoubleBox measuredFlow, int timeout)
{
//var msg = new OutputMessage(Command.Start, );
return null;
}
+32 -2
View File
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Config.Entities;
using SchematicDrawing;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.ControlBoard.Uni
@@ -12,7 +13,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
/// <summary>
/// Holds backup and security options - serializable configuration.
/// </summary>
public class CBoardCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider
public class CBoardCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider, IDrawingItemWithMeasuredVal
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(CBoardCfg) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
@@ -26,13 +27,42 @@ namespace TBF.BenchControl.ControlBoard.Uni
public int VirtValvesRangeLo;
public int VirtValvesRangeHi;
/// Schematic drawing info
public Shape Shape { get; set; }
public int X { get; set; }
public int Y { get; set; }
public Sz Sz { get; set; }
public Orient Orient { get; set; }
public bool Flip { get; set; }
public int LblX { get; set; }
public int LblY { get; set; }
public Orient LblOrient { get; set; }
public int MsrdX { get; set; }
public int MsrdY { get; set; }
public Orient MsrdOrient { get; set; }
public Config.Unit MsrdUnit { get; set; }
public string MsrdFormat { get; set; }
public double MsrdValLimLo { get; set; }
public double MsrdValLimHi { get; set; }
[XmlIgnore]
public IList<GNode> GNodes { get; set; }
[XmlIgnore]
public IList<GEdge> EdgesToSet { get; set; }
/// Private parameterless constructor invoked by all other (public) constructors
CBoardCfg() { }
CBoardCfg()
{
GNodes = new List<GNode>();
EdgesToSet = new List<GEdge>();
}
public CBoardCfg(string name, IComponentFactory factory)
: this()
{
Shape = Shape.UniCB;
Sz = Sz.L;
Name = name;
Factory = factory;
ParentName = string.Empty;
@@ -90,7 +90,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
/// A/D converters: Feedback from RV-s and diverters
for (int i = 0; i < Const.ADCsCount; i++) /// Byte 25 .. 56
{
AnalogInput[i] = GetInt16(data, offs + (int)Poz.Analogy + 2 * i);
AnalogInput[15 - i] = GetInt16(data, offs + (int)Poz.Analogy + 2 * i);
}
/// Groch temperature meters
@@ -7,28 +7,56 @@ using Dirichlet.Numerics;
namespace TBF.BenchControl.ControlBoard.Uni
{
public class CommandMsg : IOutputMessage
public class OutputMessage : IOutputMessage
{
public int PayloadLen { get { return 38; } }
public byte MessageCode { get { return (byte)' '; } }
readonly Command cmd;
readonly int etalonNr;
readonly int regValveNr;
readonly int divNr;
readonly ulong totalPulsesCount;
readonly ulong massPuleseCount;
readonly UInt128 route;
Command command;
byte startOrStopParams;
UInt32 totalPulsesCount;
UInt32 massPuleseCount;
UInt128 route;
public CommandMsg(Command cmd, int etalonNr, int regValveNr, int divNr, ulong totalPulsesCount, ulong massPuleseCount, UInt128 route)
OutputMessage()
{
this.cmd = cmd;
this.etalonNr = etalonNr;
this.regValveNr = regValveNr;
this.divNr = divNr;
this.totalPulsesCount = totalPulsesCount;
this.massPuleseCount = massPuleseCount;
this.route = route;
command = Command.RequestData;
startOrStopParams = 0;
totalPulsesCount = 0;
massPuleseCount = 0;
}
public static OutputMessage CreateDataRequestMsg()
{
var msg = new OutputMessage();
msg.command = Command.RequestData;
return msg;
}
public static OutputMessage CreateSetFlowMsg(OutputPath devices, float flowLo, float flowHi, int timeOut)
{
var msg = new OutputMessage();
msg.command = Command.RequestData;
return msg;
}
public static OutputMessage CreateTestStartCmd(int etalonNr, int regValveNr, int divNr, long totalPulsesCount, long massPulsesCount = -1)
{
var msg = new OutputMessage();
//msg.command = Command.Start;
//msg.etalonNr = etalonNr;
//msg.regValveNr = regValveNr;
//msg.divNr = divNr;
//msg.totalPulsesCount = totalPulsesCount;
//msg.massPuleseCount = (massPulsesCount >= 0) ? massPulsesCount : totalPulsesCount;
return msg;
}
public static OutputMessage CreateTestStopCmd()
{
var msg = new OutputMessage();
msg.command = Command.Stop;
return msg;
}
public byte[] GetMessage()
@@ -37,22 +65,22 @@ namespace TBF.BenchControl.ControlBoard.Uni
/// Header (3 bytes)
message[0] = Const.STX;
message[1] = 1; /// Control board addres
message[2] = (byte)PayloadLen; /// Payload length
message[1] = 1; /// Control board addres
message[2] = (byte)PayloadLen; /// Payload length
/// Command
message[3] = MessageCode;
message[4] = (byte)cmd;
//message[5] = GetCmdParameter(message[4]);
//message[6] = (byte)(pulsesCount & 0xFF);
//message[7] = (byte)((pulsesCount >> 8) & 0xFF);
//message[8] = (byte)((pulsesCount >> 16) & 0xFF);
//message[9] = 0;
message[4] = (byte)command;
message[5] = startOrStopParams;
message[6] = 0; /// nn | (paralelEt << 3);
message[7] = (byte)(totalPulsesCount & 0xFF);
message[8] = (byte)((totalPulsesCount >> 8) & 0xFF);
message[9] = (byte)((totalPulsesCount >> 16) & 0xFF);
message[10] = (byte)(massPuleseCount & 0xFF);
message[11] = (byte)((massPuleseCount >> 8) & 0xFF);
message[12] = (byte)((massPuleseCount >> 16) & 0xFF);
///// Valves
//message[10] = (byte)GetValveChgFlag();
//message[11] = (byte)(route & 0xFF);
//message[12] = (byte)((route >> 8) & 0xFF);
//message[13] = (byte)((route >> 16) & 0xFF);
//message[14] = (byte)((route >> 24) & 0xFF);
//message[15] = (byte)((route >> 32) & 0xFF);
@@ -98,7 +126,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
public override string ToString()
{
return string.Format("CommandMessage : {0}", cmd);
return string.Format("CommandMessage : {0}", command);
}
}
}