Changes for Xylem Nanjing, ver. 3.1.1676
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -11,6 +12,7 @@ using log4net;
|
||||
using Common;
|
||||
using Config.Entities;
|
||||
using Dirichlet.Numerics;
|
||||
using SchematicDrawing;
|
||||
using TBF.Rig.GenericDevices;
|
||||
using TBF.Rig.Sequences;
|
||||
using TBF.UiBridge;
|
||||
@@ -57,18 +59,19 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
///
|
||||
/// Serial communication
|
||||
///
|
||||
SerialPort serialPort; /// Seral port or null: Check serialPort.IsOpen before using the serial port
|
||||
const int BUFFER_SIZE = 4000; /// Size of input buffers
|
||||
byte[] buffer; /// Buffer for data received in one attempt in RunDeviceBefore()
|
||||
byte[] rcvdData; /// Buffer for all recevied but nut processed data. May contain data from several read attempts
|
||||
int[] cumulativeSums; /// Cumulative sums to verify checksums easily
|
||||
int rcvdBytesCount; /// Count of valid bytes in rcvdData buffer
|
||||
int age0BytesCount; /// Just received bytes count
|
||||
int age1BytesCount; /// Count of bytes received 1 second ago
|
||||
DateTime lastSentTime; /// Time stamp of the last sent command/request frame
|
||||
DateTime lastReceivedTime; /// Time stamp of the last received valid frame
|
||||
int lastRcvdStMTime; /// StateMachine.Time time stamp of the last received valid frame
|
||||
bool outputsInitialized; /// Flag indicating that outputs were sent at least once
|
||||
SerialPort serialPort; /// Seral port or null, used in DebugMode.Normal, check serialPort.IsOpen before using it
|
||||
TextReader textReader; /// Used instead of serialPort in DebugMode.Simulate
|
||||
const int BUFFER_SIZE = 4000; /// Size of input buffers
|
||||
byte[] buffer; /// Buffer for data received in one attempt in RunDeviceBefore()
|
||||
byte[] rcvdData; /// Buffer for all recevied but nut processed data. May contain data from several read attempts
|
||||
int[] cumulativeSums; /// Cumulative sums to verify checksums easily
|
||||
int rcvdBytesCount; /// Count of valid bytes in rcvdData buffer
|
||||
int age0BytesCount; /// Just received bytes count
|
||||
int age1BytesCount; /// Count of bytes received 1 second ago
|
||||
DateTime lastSentTime; /// Time stamp of the last sent command/request frame
|
||||
DateTime lastReceivedTime; /// Time stamp of the last received valid frame
|
||||
int lastRcvdStMTime; /// StateMachine.Time time stamp of the last received valid frame
|
||||
bool outputsInitialized; /// Flag indicating that outputs were sent at least once
|
||||
|
||||
///
|
||||
/// Received data
|
||||
@@ -197,9 +200,9 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
scopeAnalyzerData = null;
|
||||
switchCounterData = null;
|
||||
|
||||
routeMask = 0xFF1EFFFF00;
|
||||
for (int i = 4; i < cbCfg.RegValvesCount; i++) routeMask &= ~((UInt128)3 << 2 * i);
|
||||
for (int i = 1; i < cbCfg.DivertersCount; i++) routeMask &= ~((UInt128)1 << 24 + i);
|
||||
routeMask = 0x0FF1EFFFF00;
|
||||
for (int i = 4; i < cbCfg.RegValvesCount; i++) routeMask &= ~(((UInt128)3) << (2 * i));
|
||||
for (int i = 1; i < cbCfg.DivertersCount; i++) routeMask &= ~(((UInt128)1) << (24 + i));
|
||||
if (cbCfg.RelaysFInstalled) routeMask |= 0xFF0000000000;
|
||||
if (cbCfg.RelaysGInstalled) routeMask |= 0xFF000000000000;
|
||||
if (cbCfg.RelaysHInstalled) routeMask |= 0xFF00000000000000;
|
||||
@@ -233,12 +236,33 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
serialPort.WriteTimeout = 4000;
|
||||
serialPort.ParityReplace = 0xFF;
|
||||
serialPort.Open();
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
log.FatalFormat("{0} initialized, routeMask = {1}", Name, Utils.ToBin88(routeMask));
|
||||
}
|
||||
else if (cbCfg.DebugLevel == DebugMode.Replay)
|
||||
{
|
||||
buffer = new byte[BUFFER_SIZE];
|
||||
rcvdData = new byte[BUFFER_SIZE];
|
||||
cumulativeSums = new int[BUFFER_SIZE];
|
||||
rcvdBytesCount = 0;
|
||||
age0BytesCount = 0;
|
||||
age1BytesCount = 0;
|
||||
|
||||
serialPort = null;
|
||||
try
|
||||
{
|
||||
textReader = new StreamReader("C:\\TBF\\Simulate\\unicbsim.txt");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("Missing file C:\\TBF\\Simulate\\unicbsim.txt");
|
||||
}
|
||||
|
||||
log.FatalFormat("{0} in replay mode, routeMask = {1}", Name, Utils.ToBin88(routeMask));
|
||||
}
|
||||
else
|
||||
{
|
||||
serialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
log.FatalFormat("{0} simulated: {1}", Name, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,16 +275,39 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
/// Read data from the control board
|
||||
///
|
||||
bool generalDataReceived = false;
|
||||
if (cbCfg.DebugLevel == DebugMode.Normal && serialPort != null && serialPort.IsOpen)
|
||||
if ((cbCfg.DebugLevel == DebugMode.Normal && serialPort != null && serialPort.IsOpen) ||
|
||||
cbCfg.DebugLevel == DebugMode.Replay)
|
||||
{
|
||||
int age2BytesCount = age1BytesCount;
|
||||
age1BytesCount = age0BytesCount;
|
||||
age0BytesCount = serialPort.BytesToRead;
|
||||
|
||||
/// Read new received bytes and append them to an intermediate buffer 'buffer'
|
||||
if (age0BytesCount > 0)
|
||||
if (cbCfg.DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
age0BytesCount = serialPort.Read(buffer, 0, Math.Min(age0BytesCount, BUFFER_SIZE));
|
||||
age0BytesCount = serialPort.BytesToRead;
|
||||
|
||||
/// Read new received bytes and append them to an intermediate buffer 'buffer'
|
||||
if (age0BytesCount > 0)
|
||||
{
|
||||
age0BytesCount = serialPort.Read(buffer, 0, Math.Min(age0BytesCount, BUFFER_SIZE));
|
||||
}
|
||||
}
|
||||
else if (cbCfg.DebugLevel == DebugMode.Replay)
|
||||
{
|
||||
/// Simulation
|
||||
age0BytesCount = 0;
|
||||
string hexValues = textReader.ReadLine();
|
||||
if (hexValues != null)
|
||||
{
|
||||
string[] hexValuesSplit = hexValues.Split(' ');
|
||||
foreach (var hex in hexValuesSplit)
|
||||
{
|
||||
buffer[age0BytesCount++] = Convert.ToByte(hex, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
age0BytesCount = 0; /// No data
|
||||
}
|
||||
|
||||
StringBuilder dataLog = new StringBuilder();
|
||||
@@ -392,21 +439,22 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
///
|
||||
/// Handle emergency stop signal
|
||||
///
|
||||
bool newEmergencyStop = ((State & (ulong)StatusP.EmgcyStopActive) != 0);
|
||||
if (newEmergencyStop)
|
||||
bool emergencyStop = ((State & (UInt64)StatusP.EmgcyStopActive) != 0);
|
||||
///
|
||||
if (emergencyStop)
|
||||
route |= (((UInt128)1) << (cbCfg.BitNr + 1));
|
||||
else
|
||||
route &= ~(((UInt128)1) << (cbCfg.BitNr + 1));
|
||||
///
|
||||
if (emergencyStop && !isEmergencyStop)
|
||||
{
|
||||
/// Emergency stop ... set indicator bit
|
||||
route |= ((UInt128)1) << (cbCfg.BitNr + 1);
|
||||
|
||||
if (!isEmergencyStop)
|
||||
{
|
||||
/// Stop the cycle ... the same as pressing 'STOP' button in the BenchControlPanel
|
||||
TBF.UiBridge.Bridge.Ui2Bench(TBF.UiBridge.UI2BenchCmd.Stop);
|
||||
}
|
||||
TBF.UiBridge.Bridge.Ui2Bench(TBF.UiBridge.UI2BenchCmd.Stop); /// The same as pressing 'STOP' button in BenchControlPanel
|
||||
}
|
||||
isEmergencyStop = newEmergencyStop;
|
||||
///
|
||||
isEmergencyStop = emergencyStop;
|
||||
|
||||
log.DebugFormat("Route synced with RRoute and UI changes, new route = {0}", Utils.ToBin40((ulong)route >> 8));
|
||||
|
||||
log.DebugFormat("Route synced with RRoute and UI changes, new route = {0}", Utils.ToBin88(route));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using Common;
|
||||
using Config.Entities;
|
||||
using SchematicDrawing;
|
||||
using TBF.Resources;
|
||||
@@ -14,7 +15,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
/// <summary>
|
||||
/// Holds backup and security options - serializable configuration.
|
||||
/// </summary>
|
||||
public class UniCBCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider, IDrawingItemWithMeasuredVal, IRouteBasedDrawingItem
|
||||
public class UniCBCfg : ComponentCfgBase, IComponentCfg, IParamsProvider, IDrawingItemWithMeasuredVal, IRouteBasedDrawingItem
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(UniCBCfg) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
@@ -46,14 +47,15 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
public int MsrdX { get; set; }
|
||||
public int MsrdY { get; set; }
|
||||
public Orient MsrdOrient { get; set; }
|
||||
public Config.Unit MsrdUnit { get; set; }
|
||||
public Common.Unit MsrdUnit { get; set; }
|
||||
public string MsrdFormat { get; set; }
|
||||
public double MsrdValLimLo { get; set; }
|
||||
public double MsrdValLimHi { get; set; }
|
||||
|
||||
public int BitNr { get { return 80; } } /// Bit-position
|
||||
[XmlIgnore]
|
||||
public int BitNr { get { return 80; } } /// Bit-position
|
||||
[XmlIgnore]
|
||||
public bool Inverted { get { return false; } } /// When true the valve function is inverted: 0 = open, 1 = closed
|
||||
|
||||
[XmlIgnore]
|
||||
public IList<GNode> GNodes { get; set; }
|
||||
[XmlIgnore]
|
||||
@@ -207,7 +209,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
prms.ShowState = ShowState;
|
||||
}
|
||||
|
||||
public Config.Entities.IParamsProvider Clone()
|
||||
public IParamsProvider Clone()
|
||||
{
|
||||
var pars = new UniCBCfg();
|
||||
CopyContentTo(pars);
|
||||
|
||||
Reference in New Issue
Block a user