OptoTelegram serial port data parsing, OptoData and RfidData logging, opto-measurement ready to be tested.
This commit is contained in:
parent
a6aa6739ad
commit
e302cb9335
1
TODO.txt
1
TODO.txt
@ -1,4 +1,5 @@
|
||||
iPerl:
|
||||
- OptoTelegram parsing, odkial prat MeterType?
|
||||
- STOP nefunguje pocas communikacie
|
||||
- na Process obrazovke posunut stupacku a rezervoar uplne doprava
|
||||
|
||||
|
||||
@ -9,9 +9,11 @@ using TBF.BenchControl;
|
||||
|
||||
namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
{
|
||||
public class TestMethod : ComponentBase, GenericDevices.ITestMethod
|
||||
public class TestMethod : ComponentBase, GenericDevices.ITestMethod, Generic.IDevice
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
|
||||
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
|
||||
|
||||
public override string ToString() { return string.Format("TestMethods.Adjustment({0})", Cfg.ToString(1)); }
|
||||
|
||||
readonly TestMethodCfg testMethodCfg;
|
||||
@ -31,6 +33,16 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
rfidDataLogger.Fatal("------------------------------------------------------------------------");
|
||||
rfidDataLogger.Fatal("Program restarted");
|
||||
}
|
||||
|
||||
public void RunDeviceBefore() { }
|
||||
public void RunDeviceAfter() { }
|
||||
public void StopDevice() { }
|
||||
|
||||
public IList<Event> Execute(Entities.Test test)
|
||||
{
|
||||
return (new iPerlCommunicationSeq()).Execute(test, testMethodCfg.TestParams);
|
||||
|
||||
@ -18,6 +18,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
public partial class iPerlCommunicationForm : Form, GenericDevices.IHasCompleted
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(iPerlCommunicationForm));
|
||||
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
|
||||
|
||||
#region DLL_Interface
|
||||
|
||||
@ -36,8 +37,20 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
[DllImport("libRfid.dll", EntryPoint = "writeRequestPort")]
|
||||
static extern unsafe int writeRequestPort(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms);
|
||||
|
||||
static int currentPort;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper function with safe interface adn unsafe body
|
||||
/// Wrapper function with safe interface and unsafe body
|
||||
/// </summary>
|
||||
/// <returns>Value returned by openPort(...)</returns>
|
||||
public static unsafe int OpenPort(int comPort)
|
||||
{
|
||||
currentPort = comPort;
|
||||
return openPort(comPort);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper function with safe interface and unsafe body
|
||||
/// </summary>
|
||||
/// <returns>Value returned by readRequestPort(...)</returns>
|
||||
public static unsafe int ReadRequestPort(MessageID messageID, int offset, int lenght, out byte[] buffer, int timeout)
|
||||
@ -48,6 +61,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
fixed (byte* pBuf = buf)
|
||||
{
|
||||
retv = readRequestPort(messageID, offset, lenght, pBuf, timeout);
|
||||
rfidDataLogger.InfoFormat("Group={0}, Port={1}, ReadRequestPort({2}, {3}, {4}, ...) returned {5} {6}", currentGroup, currentPort, messageID, offset, lenght, retv, (retv != 0) ? "!" : "");
|
||||
|
||||
buffer = new byte[lenght];
|
||||
for (int i = 0; i < lenght; i++) buffer[i] = buf[i];
|
||||
@ -66,6 +80,18 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
fixed (byte* pBuf = buffer)
|
||||
{
|
||||
retv = writeRequestPort(messageID, offset, lenght, pBuf, timeout);
|
||||
if (lenght == 1)
|
||||
{
|
||||
rfidDataLogger.InfoFormat("Group={0}, Port={1}, WriteRequestPort({3}, {4}, {5}, {6}) returned {2} {7}", currentGroup, currentPort, retv, messageID, offset, lenght, pBuf[0].ToString("X2"), (retv != 0) ? "!" : "");
|
||||
}
|
||||
else if (lenght == 2)
|
||||
{
|
||||
rfidDataLogger.InfoFormat("Group={0}, Port={1}, WriteRequestPort({3}, {4}, {5}, {6} {7}) returned {2} {8}", currentGroup, currentPort, retv, messageID, offset, lenght, pBuf[0].ToString("X2"), pBuf[1].ToString("X2"), (retv != 0) ? "!" : "");
|
||||
}
|
||||
else
|
||||
{
|
||||
rfidDataLogger.InfoFormat("Group={0}, Port={1}, WriteRequestPort({3}, {4}, {5}, {6} {7} ...) returned {2} {8}", currentGroup, currentPort, retv, messageID, offset, lenght, pBuf[0].ToString("X2"), pBuf[1].ToString("X2"), (retv != 0) ? "!" : "");
|
||||
}
|
||||
}
|
||||
return retv;
|
||||
}
|
||||
@ -387,6 +413,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
{
|
||||
int threadId = (threadData as Boxes.IntBox).Val;
|
||||
|
||||
rfidDataLogger.InfoFormat(""); /// Makes the log more readable when there is a lot of data
|
||||
rfidDataLogger.WarnFormat("Activity = {0}", activity);
|
||||
rfidDataLogger.InfoFormat(""); /// Makes the log more readable when there is a lot of data
|
||||
|
||||
for (int group = 1; group <= lastGroup; group++)
|
||||
{
|
||||
while (currentGroup != group && !stopWorkerThreads[threadId]) Thread.Sleep(50);
|
||||
@ -426,7 +456,8 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
else if (wm.Disabled) OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled"));
|
||||
else
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Cannot " + activity));
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, activity + " failed !!!"));
|
||||
rfidDataLogger.ErrorFormat("Group={0}, Port={1}, {2} failed !!!", currentGroup, currentPort, activity);
|
||||
wm.Disabled = true;
|
||||
}
|
||||
}
|
||||
@ -464,7 +495,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
|
||||
if (wm.Disabled) return false;
|
||||
|
||||
if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
|
||||
bool success = false;
|
||||
|
||||
@ -519,7 +550,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
}
|
||||
|
||||
/// Communication necessary
|
||||
if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
|
||||
bool success = true;
|
||||
|
||||
@ -596,7 +627,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
{
|
||||
if (wm.Disabled) return false;
|
||||
|
||||
if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
|
||||
bool success = false;
|
||||
|
||||
@ -641,7 +672,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
{
|
||||
if (wm.Disabled) return false;
|
||||
|
||||
if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
|
||||
bool success = false;
|
||||
|
||||
@ -675,7 +706,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
{
|
||||
if (wm.Disabled) return false;
|
||||
|
||||
if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
|
||||
bool success = false;
|
||||
|
||||
@ -727,7 +758,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
{
|
||||
if (wm.Disabled) return false;
|
||||
|
||||
if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
|
||||
bool success = false;
|
||||
|
||||
@ -776,7 +807,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
{
|
||||
if (wm.Disabled) return false;
|
||||
|
||||
if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port
|
||||
|
||||
bool success = false;
|
||||
|
||||
|
||||
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
{
|
||||
public class OptoTelegram
|
||||
{
|
||||
public static readonly int Length = 42;
|
||||
|
||||
public double EMF;
|
||||
public Int16 MagneticField;
|
||||
public double Flow;
|
||||
public double Volume;
|
||||
public Int16 Impedance;
|
||||
public UInt32 Timestamp;
|
||||
public byte GG;
|
||||
|
||||
string sourceStr;
|
||||
|
||||
|
||||
public OptoTelegram()
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return sourceStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a configuration structure from a complete byte array
|
||||
///
|
||||
/// Telegram description:
|
||||
///
|
||||
/// AAAAAA[tab]BBBB[tab]CCCC[tab]DDDDDD[tab]EEEE[tab]FFFFFFFF[tab]GG[cr][lf] (42 bytes)
|
||||
///
|
||||
/// Data Comment Type Calculate to decimal
|
||||
/// ----------------------------------------------------------------
|
||||
/// AAAAAA EMF Int24 Value * 0.000000333
|
||||
/// BBBB Magnetic field Int16 Value
|
||||
/// CCCC Flow Int16 Value * 0.225 * Scalig factor
|
||||
/// DDDDDD Volume Int24 Value / 16000 * Scaling factor
|
||||
/// EEEE Impedance Int16 Value
|
||||
/// FFFFFFFF Timestamp Uint32 Value / 8192
|
||||
/// GG
|
||||
/// ----------------------------------------------------------------
|
||||
///
|
||||
/// Example:
|
||||
/// FFFFFE 51EA 0000 65324E 0087 F6319DFF 86
|
||||
/// FFDD3A 51F9 0000 65324E 0088 F631A60B 45
|
||||
/// ...
|
||||
/// </summary>
|
||||
/// <param name="data">A complete byte array data</param>
|
||||
/// <returns>ConfigStruct or null when byte array was not complete</returns>
|
||||
public static OptoTelegram FromString(string telegram, MeterType meterType)
|
||||
{
|
||||
if ((telegram == null) || (telegram.Length < Length) ||
|
||||
(telegram[6] != '\t') || (telegram[11] != '\t') ||
|
||||
(telegram[16] != '\t') || (telegram[23] != '\t') ||
|
||||
(telegram[28] != '\t') || (telegram[37] != '\t') ||
|
||||
(telegram[40] != '\r') || (telegram[41] != '\n'))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
OptoTelegram opto = new OptoTelegram();
|
||||
|
||||
Int32 value;
|
||||
if (Int32.TryParse(telegram.Substring(0, 6), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value))
|
||||
{
|
||||
Int32 svalue = (value >= 0x00800000) ? (value - 0x01000000) : value;
|
||||
opto.EMF = 0.000000333 * (double)svalue;
|
||||
}
|
||||
else return null;
|
||||
|
||||
if (Int32.TryParse(telegram.Substring(7, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value))
|
||||
{
|
||||
Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value;
|
||||
opto.MagneticField = (Int16)svalue;
|
||||
}
|
||||
else return null;
|
||||
|
||||
double factor = ScalingFactor(meterType);
|
||||
|
||||
if (Int32.TryParse(telegram.Substring(12, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value))
|
||||
{
|
||||
Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value;
|
||||
opto.Flow = 0.225 * (double)svalue * factor;
|
||||
}
|
||||
else return null;
|
||||
|
||||
if (Int32.TryParse(telegram.Substring(17, 6), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value))
|
||||
{
|
||||
Int32 svalue = (value >= 0x00800000) ? (value - 0x01000000) : value;
|
||||
opto.Volume = (double)svalue / 16000.0 * factor;
|
||||
}
|
||||
else return null;
|
||||
|
||||
if (Int32.TryParse(telegram.Substring(24, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value))
|
||||
{
|
||||
Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value;
|
||||
opto.Impedance = (Int16)svalue;
|
||||
}
|
||||
else return null;
|
||||
|
||||
UInt32 uvalue;
|
||||
if (UInt32.TryParse(telegram.Substring(29, 8), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out uvalue))
|
||||
{
|
||||
opto.Timestamp = uvalue;
|
||||
}
|
||||
else return null;
|
||||
|
||||
if (UInt32.TryParse(telegram.Substring(38, 2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out uvalue))
|
||||
{
|
||||
opto.GG = (byte)uvalue;
|
||||
}
|
||||
else return null;
|
||||
|
||||
opto.sourceStr = telegram.Substring(0, Length - 2);
|
||||
|
||||
return opto;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Scaling factor:
|
||||
/// 0, 1 (DN15, Coax) . . . . 1
|
||||
/// 2 (DN20) . . . . . . . . 2
|
||||
/// 3 (DN25) . . . . . . . . 4
|
||||
/// 4, 5 (DN26, DN32) . . . . 8
|
||||
/// 6 (DN40) . . . . . . . . 16
|
||||
/// </summary>
|
||||
/// <param name="meterType">MeterType (0..6)</param>
|
||||
/// <returns>Scaling factor</returns>
|
||||
public static double ScalingFactor(MeterType meterType)
|
||||
{
|
||||
switch (meterType)
|
||||
{
|
||||
default:
|
||||
case MeterType.DN15:
|
||||
case MeterType.CoaxManifold: return 1.0;
|
||||
case MeterType.DN20: return 2.0;
|
||||
case MeterType.DN25: return 4.0;
|
||||
case MeterType.DN26:
|
||||
case MeterType.DN32: return 8.0;
|
||||
case MeterType.DN40: return 16.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
public class WaterMeter : ComponentBase, IDevice, GenericDevices.IWaterMeter, GenericDevices.IRegisterReader, IOperation
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(WaterMeter));
|
||||
protected static readonly ILog optoDataLogger = LogManager.GetLogger("OptoData");
|
||||
public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); }
|
||||
|
||||
readonly WaterMeterCfg iPerlCfg;
|
||||
@ -69,10 +70,30 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
bool disabled;
|
||||
|
||||
/// <summary> ConfigStruct of the water meter obtained or updated by iPerlCommunication </summary>
|
||||
public ConfigStruct ConfigStruct;
|
||||
public ConfigStruct ConfigStruct
|
||||
{
|
||||
get { return configStruct; }
|
||||
set { configStruct = value; }
|
||||
}
|
||||
ConfigStruct configStruct;
|
||||
|
||||
/// <summary> CalibrationStruct of the water meter obtained or updated by iPerlCommunication </summary>
|
||||
public CalibrationStruct CalibrationStruct;
|
||||
public CalibrationStruct CalibrationStruct
|
||||
{
|
||||
get { return calibrationStruct; }
|
||||
set
|
||||
{
|
||||
calibrationStruct = value;
|
||||
switch (calibrationStruct.VolumeUnits)
|
||||
{
|
||||
default:
|
||||
case VolumeUnits.m3: volumeUnit = 1000.0; break; /// liter per m3
|
||||
case VolumeUnits.US_gallon: volumeUnit = 3.785; break; /// liter per US gallon
|
||||
case VolumeUnits.UK_gallon: volumeUnit = 4.54609; break; /// liter per UK gallon
|
||||
}
|
||||
}
|
||||
}
|
||||
CalibrationStruct calibrationStruct;
|
||||
|
||||
|
||||
public ushort CalibrationFactor { get { return CalibrationStruct.Calibration; } }
|
||||
@ -86,21 +107,37 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
}
|
||||
|
||||
|
||||
Boxes.IntBox pulses;
|
||||
Boxes.IntBox refPulses;
|
||||
/// <summary>
|
||||
/// Volume of water in liter set by OptoTelegramRreceived(...)
|
||||
/// </summary>
|
||||
private double volumeLtr;
|
||||
|
||||
/// <summary>
|
||||
/// Volume of one water meter unit in liter. Set when reading the configuration.
|
||||
/// </summary>
|
||||
private double volumeUnit;
|
||||
|
||||
private Boxes.IntBox pulses;
|
||||
private Boxes.IntBox refPulses;
|
||||
|
||||
|
||||
///
|
||||
/// Opto serial port and worker thread related private variables
|
||||
///
|
||||
private SerialPort optoSerialPort;
|
||||
private bool optoPortOpen;
|
||||
|
||||
#if USE_SEPARATE_WORKER_THREAD
|
||||
private Thread workerThread;
|
||||
private bool stopWorkerThread;
|
||||
#endif
|
||||
|
||||
|
||||
public WaterMeter()
|
||||
{
|
||||
synchronized = false;
|
||||
synchronized2 = false;
|
||||
partOfTelegram = string.Empty;
|
||||
volumeUnit = 1000.0; /// liter / m3
|
||||
}
|
||||
|
||||
public WaterMeter(WaterMeterCfg cfg)
|
||||
@ -110,25 +147,37 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
static bool initOnceDone;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (DebugLevel == Entities.DebugMode.Normal)
|
||||
{
|
||||
if (!initOnceDone)
|
||||
{
|
||||
initOnceDone = true;
|
||||
optoDataLogger.Fatal("------------------------------------------------------------------------");
|
||||
optoDataLogger.Fatal("Program restarted");
|
||||
}
|
||||
|
||||
optoSerialPort = new SerialPort(string.Format("COM{0}", iPerlCfg.OptoComPortNr),
|
||||
9600, Parity.None, 8, StopBits.One);
|
||||
optoSerialPort.Handshake = Handshake.None;
|
||||
optoSerialPort.Open();
|
||||
optoPortOpen = true;
|
||||
|
||||
#if USE_SEPARATE_WORKER_THREAD
|
||||
stopWorkerThread = false;
|
||||
workerThread = new Thread(Worker);
|
||||
workerThread.Start();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
#if !USE_SEPARATE_WORKER_THREAD
|
||||
ReadOptoSerialPort();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void RunDeviceAfter()
|
||||
@ -139,10 +188,11 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
{
|
||||
if (DebugLevel == Entities.DebugMode.Normal)
|
||||
{
|
||||
#if USE_SEPARATE_WORKER_THREAD
|
||||
stopWorkerThread = true;
|
||||
workerThread.Join(2000);
|
||||
#endif
|
||||
optoSerialPort.Close();
|
||||
optoPortOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,33 +255,108 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
|
||||
void ReadPulses()
|
||||
{
|
||||
/// Do something meaningfull here
|
||||
pulses.Val = 1;
|
||||
refPulses.Val = 2;
|
||||
pulses.Val = (int)(volumeLtr / (double)PulsesPerLtr + 0.5);
|
||||
refPulses.Val = 2; /// Do something meaningfull here
|
||||
}
|
||||
|
||||
|
||||
#if USE_SEPARATE_WORKER_THREAD
|
||||
void Worker()
|
||||
{
|
||||
while (!stopWorkerThread)
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
if (stopWorkerThread) break;
|
||||
ReadOptoSerialPort();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool synchronized;
|
||||
bool synchronized2;
|
||||
string partOfTelegram;
|
||||
|
||||
/// <summary>
|
||||
/// 9600 Bd, 8 data bits, 1 stop bit, no parity
|
||||
///
|
||||
/// Telegram description:
|
||||
///
|
||||
/// AAAAAA[tab]BBBB[tab]CCCC[tab]DDDDDD[tab]EEEE[tab]FFFFFFFF[tab]GG[cr][lf] (42 bytes)
|
||||
///
|
||||
/// Example:
|
||||
/// FFFFFE 51EA 0000 65324E 0087 F6319DFF 86
|
||||
/// FFDD3A 51F9 0000 65324E 0088 F631A60B 45
|
||||
/// ...
|
||||
/// </summary>
|
||||
void ReadOptoSerialPort()
|
||||
{
|
||||
if (DebugLevel == Entities.DebugMode.Normal || DebugLevel == Entities.DebugMode.Record)
|
||||
{
|
||||
int nrBytes = optoSerialPort.BytesToRead;
|
||||
if (nrBytes > 0)
|
||||
{
|
||||
char[] buffer = new char[nrBytes];
|
||||
optoSerialPort.Read(buffer, 0, nrBytes);
|
||||
string s = new string(buffer);
|
||||
OnOptoReceived(this, new OptoReceivedEventArgs(s));
|
||||
string received = new string(buffer);
|
||||
|
||||
string allRcvd = partOfTelegram + received;
|
||||
|
||||
OptoTelegram opto;
|
||||
while (true)
|
||||
{
|
||||
int pos = allRcvd.IndexOf("\r\n");
|
||||
|
||||
if (pos < 0)
|
||||
{
|
||||
/// No CR+LF found, wait for more characters in the next invocation
|
||||
partOfTelegram = allRcvd;
|
||||
return;
|
||||
}
|
||||
// CR+LF found
|
||||
else if (pos < OptoTelegram.Length - 2)
|
||||
{
|
||||
/// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop
|
||||
allRcvd = allRcvd.Substring(pos + 2);
|
||||
if (synchronized)
|
||||
{
|
||||
optoDataLogger.ErrorFormat("{0}: Opto data syncronisation error", Name);
|
||||
}
|
||||
synchronized = true;
|
||||
}
|
||||
// CR+LF found and (pos >= OptoTelegram.Length - 2)
|
||||
else if ((null != (opto = OptoTelegram.FromString(allRcvd.Substring(pos - OptoTelegram.Length + 2), iPerlCfg.MeterType))))
|
||||
{
|
||||
OptoTelegramRreceived(opto, synchronized2);
|
||||
synchronized2 = synchronized;
|
||||
allRcvd = allRcvd.Substring(pos + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
optoDataLogger.ErrorFormat("{0}: Wrong format of opto data", Name);
|
||||
allRcvd = allRcvd.Substring(pos + 2);
|
||||
}
|
||||
}
|
||||
|
||||
//OnOptoReceived(this, new OptoReceivedEventArgs(s));
|
||||
}
|
||||
else
|
||||
{
|
||||
//OnOptoReceived(this, new OptoReceivedEventArgs("."));
|
||||
}
|
||||
}
|
||||
else if (DebugLevel == Entities.DebugMode.Simulate)
|
||||
{
|
||||
}
|
||||
else if (DebugLevel == Entities.DebugMode.Reply)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void OptoTelegramRreceived(OptoTelegram optoTelegram, bool async)
|
||||
{
|
||||
volumeLtr = optoTelegram.Volume * volumeUnit;
|
||||
optoDataLogger.InfoFormat("{0}: {1}", Name, optoTelegram);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the state machine when a test is selected and UI needs to be updated.
|
||||
|
||||
@ -19,6 +19,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public MeterType MeterType;
|
||||
public int OptoComPortNr;
|
||||
public int RfidComPortNr;
|
||||
public int Group; /// Number written to QuidoRS to connct the watermeter to RfidComPort
|
||||
|
||||
@ -35,6 +35,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
private void WaterMeterCfgCtrl_Load(object sender, EventArgs e)
|
||||
{
|
||||
nameLabel.Text = Strings.Name;
|
||||
for (byte i = 0; i < (byte)MeterType.Count; i++) meterTypeComboBox.Items.Add(((MeterType)i).ToString());
|
||||
Redraw();
|
||||
}
|
||||
|
||||
@ -47,6 +48,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
if (config == null) return; /// Control was not loaded, settings were not changed
|
||||
classNameLabel.Text = config.Factory.ClassName;
|
||||
nameTextBox.Text = config.Name;
|
||||
meterTypeComboBox.Text = config.MeterType.ToString();
|
||||
optoPortNrTextBox.Text = config.OptoComPortNr.ToString();
|
||||
rfidPortNrTextBox.Text = config.RfidComPortNr.ToString();
|
||||
groupTextBox.Text = config.Group.ToString();
|
||||
@ -55,6 +57,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
public void Unlock()
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
meterTypeComboBox.Enabled = true;
|
||||
optoPortNrTextBox.Enabled = true;
|
||||
rfidPortNrTextBox.Enabled = true;
|
||||
groupTextBox.Enabled = true;
|
||||
@ -64,6 +67,12 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
if (!meterTypeComboBox.Items.Contains(meterTypeComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Meter type is not valid";
|
||||
}
|
||||
|
||||
int dummy;
|
||||
if (!int.TryParse(optoPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
|
||||
{
|
||||
@ -91,6 +100,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
||||
|
||||
config.Name = nameTextBox.Text;
|
||||
config.MeterType = (MeterType)meterTypeComboBox.SelectedIndex;
|
||||
config.OptoComPortNr = int.Parse(optoPortNrTextBox.Text);
|
||||
config.RfidComPortNr = int.Parse(rfidPortNrTextBox.Text);
|
||||
config.Group = int.Parse(groupTextBox.Text);
|
||||
|
||||
@ -41,6 +41,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
this.rfidPortNrLabel = new System.Windows.Forms.Label();
|
||||
this.groupTextBox = new System.Windows.Forms.TextBox();
|
||||
this.groupLabel = new System.Windows.Forms.Label();
|
||||
this.meterTypeLabel = new System.Windows.Forms.Label();
|
||||
this.meterTypeComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// nameTextBox
|
||||
@ -48,7 +50,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
this.nameTextBox.Enabled = false;
|
||||
this.nameTextBox.Location = new System.Drawing.Point(135, 55);
|
||||
this.nameTextBox.Name = "nameTextBox";
|
||||
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
|
||||
this.nameTextBox.Size = new System.Drawing.Size(121, 20);
|
||||
this.nameTextBox.TabIndex = 5;
|
||||
//
|
||||
// nameLabel
|
||||
@ -72,7 +74,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
// optoPortNrTextBox
|
||||
//
|
||||
this.optoPortNrTextBox.Enabled = false;
|
||||
this.optoPortNrTextBox.Location = new System.Drawing.Point(135, 79);
|
||||
this.optoPortNrTextBox.Location = new System.Drawing.Point(135, 104);
|
||||
this.optoPortNrTextBox.Name = "optoPortNrTextBox";
|
||||
this.optoPortNrTextBox.Size = new System.Drawing.Size(34, 20);
|
||||
this.optoPortNrTextBox.TabIndex = 7;
|
||||
@ -80,7 +82,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
// optoPortNrLabel
|
||||
//
|
||||
this.optoPortNrLabel.AutoSize = true;
|
||||
this.optoPortNrLabel.Location = new System.Drawing.Point(25, 82);
|
||||
this.optoPortNrLabel.Location = new System.Drawing.Point(25, 107);
|
||||
this.optoPortNrLabel.Name = "optoPortNrLabel";
|
||||
this.optoPortNrLabel.Size = new System.Drawing.Size(101, 13);
|
||||
this.optoPortNrLabel.TabIndex = 6;
|
||||
@ -89,7 +91,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
// rfidPortNrTextBox
|
||||
//
|
||||
this.rfidPortNrTextBox.Enabled = false;
|
||||
this.rfidPortNrTextBox.Location = new System.Drawing.Point(135, 103);
|
||||
this.rfidPortNrTextBox.Location = new System.Drawing.Point(135, 128);
|
||||
this.rfidPortNrTextBox.Name = "rfidPortNrTextBox";
|
||||
this.rfidPortNrTextBox.Size = new System.Drawing.Size(34, 20);
|
||||
this.rfidPortNrTextBox.TabIndex = 9;
|
||||
@ -97,7 +99,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
// rfidPortNrLabel
|
||||
//
|
||||
this.rfidPortNrLabel.AutoSize = true;
|
||||
this.rfidPortNrLabel.Location = new System.Drawing.Point(25, 106);
|
||||
this.rfidPortNrLabel.Location = new System.Drawing.Point(25, 131);
|
||||
this.rfidPortNrLabel.Name = "rfidPortNrLabel";
|
||||
this.rfidPortNrLabel.Size = new System.Drawing.Size(103, 13);
|
||||
this.rfidPortNrLabel.TabIndex = 8;
|
||||
@ -106,7 +108,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
// groupTextBox
|
||||
//
|
||||
this.groupTextBox.Enabled = false;
|
||||
this.groupTextBox.Location = new System.Drawing.Point(135, 127);
|
||||
this.groupTextBox.Location = new System.Drawing.Point(135, 152);
|
||||
this.groupTextBox.Name = "groupTextBox";
|
||||
this.groupTextBox.Size = new System.Drawing.Size(34, 20);
|
||||
this.groupTextBox.TabIndex = 11;
|
||||
@ -114,16 +116,36 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
// groupLabel
|
||||
//
|
||||
this.groupLabel.AutoSize = true;
|
||||
this.groupLabel.Location = new System.Drawing.Point(25, 130);
|
||||
this.groupLabel.Location = new System.Drawing.Point(25, 155);
|
||||
this.groupLabel.Name = "groupLabel";
|
||||
this.groupLabel.Size = new System.Drawing.Size(39, 13);
|
||||
this.groupLabel.TabIndex = 10;
|
||||
this.groupLabel.Text = "Group:";
|
||||
//
|
||||
// meterTypeLabel
|
||||
//
|
||||
this.meterTypeLabel.AutoSize = true;
|
||||
this.meterTypeLabel.Location = new System.Drawing.Point(25, 82);
|
||||
this.meterTypeLabel.Name = "meterTypeLabel";
|
||||
this.meterTypeLabel.Size = new System.Drawing.Size(57, 13);
|
||||
this.meterTypeLabel.TabIndex = 12;
|
||||
this.meterTypeLabel.Text = "Meter type";
|
||||
//
|
||||
// meterTypeComboBox
|
||||
//
|
||||
this.meterTypeComboBox.Enabled = false;
|
||||
this.meterTypeComboBox.FormattingEnabled = true;
|
||||
this.meterTypeComboBox.Location = new System.Drawing.Point(135, 79);
|
||||
this.meterTypeComboBox.Name = "meterTypeComboBox";
|
||||
this.meterTypeComboBox.Size = new System.Drawing.Size(121, 21);
|
||||
this.meterTypeComboBox.TabIndex = 13;
|
||||
//
|
||||
// WaterMeterCfgCtrl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.meterTypeComboBox);
|
||||
this.Controls.Add(this.meterTypeLabel);
|
||||
this.Controls.Add(this.groupTextBox);
|
||||
this.Controls.Add(this.groupLabel);
|
||||
this.Controls.Add(this.rfidPortNrTextBox);
|
||||
@ -152,5 +174,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
private System.Windows.Forms.Label rfidPortNrLabel;
|
||||
private System.Windows.Forms.TextBox groupTextBox;
|
||||
private System.Windows.Forms.Label groupLabel;
|
||||
private System.Windows.Forms.Label meterTypeLabel;
|
||||
private System.Windows.Forms.ComboBox meterTypeComboBox;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,24 +6,34 @@
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="LogFile-UI" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\Logs\Log-UI.txt" />
|
||||
|
||||
<!-- Process data appenders -->
|
||||
<appender name="OptoData" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\ProcessData\OptoData.log" />
|
||||
<appendToFile value="true" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
|
||||
<conversionPattern value="%date %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="LogFile-WT" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\Logs\Log-WT.txt" />
|
||||
<appender name="RfidData" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\ProcessData\RfidData.log" />
|
||||
<appendToFile value="true" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
|
||||
<conversionPattern value="%date %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="ProcessData" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\ProcessData\process-data.txt" />
|
||||
<appendToFile value="true" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="AllResults" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\Logs\AllResults.txt" />
|
||||
<file value="C:\TBF\ProcessData\AllResults.txt" />
|
||||
<appendToFile value="true" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
@ -31,7 +41,7 @@
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="SummaryResults" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\Logs\SummaryResults.txt" />
|
||||
<file value="C:\TBF\Results\SummaryResults.txt" />
|
||||
<appendToFile value="true" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
@ -39,20 +49,40 @@
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Program log appenders -->
|
||||
<appender name="LogFile-UI" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\Logs\Log-UI.txt" />
|
||||
<appendToFile value="true" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %-5level %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="LogFile-WT" type="log4net.Appender.FileAppender">
|
||||
<file value="C:\TBF\Logs\Log-WT.txt" />
|
||||
<appendToFile value="true" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %-5level %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Set root logger -->
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="LogFile-UI" />
|
||||
</root>
|
||||
<!-- Set loggers -->
|
||||
<logger name="AllResults">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="AllResults" />
|
||||
</logger>
|
||||
<logger name="SummaryResults">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="SummaryResults" />
|
||||
</logger>
|
||||
|
||||
|
||||
<!-- Set process loggers -->
|
||||
<logger name="AllResults"><level value="INFO" /><appender-ref ref="AllResults" /></logger>
|
||||
<logger name="SummaryResults"> <level value="INFO" /><appender-ref ref="SummaryResults" /></logger>
|
||||
<logger name="ProcessData"><level value="INFO" /><appender-ref ref="ProcessData" /></logger>
|
||||
<logger name="OptoData"><level value="INFO" /><appender-ref ref="OptoData" /></logger>
|
||||
<logger name="RfidData"><level value="INFO" /><appender-ref ref="RfidData" /></logger>
|
||||
|
||||
|
||||
<!-- Set program loggers -->
|
||||
<logger name="NHibernate"> <level value="ERROR" /> </logger>
|
||||
<logger name="TBF.BenchControl">
|
||||
<appender-ref ref="A1" />
|
||||
@ -60,8 +90,16 @@
|
||||
</logger>
|
||||
<logger name="TBF.BenchControl.StateMachine"> <level value="INFO" /> </logger>
|
||||
<logger name="TBF.BenchControl.State"> <level value="WARN" /> </logger>
|
||||
<logger name="TBF.BenchControl.Elde.ControlBoardDev"> <level value="DEBUG" /> </logger>
|
||||
<logger name="TBF.BenchControl.MettlerToledo"> <level value="INFO" /> </logger>
|
||||
<logger name="TBF.BenchControl.IdcCamera"> <level value="INFO" /> </logger>
|
||||
<logger name="TBF.BenchControl.Elde.ControlBoardWrap"> <level value="DEBUG" /> </logger>
|
||||
<logger name="TBF.BenchControl.Elde.Pump"> <level value="DEBUG" /> </logger>
|
||||
<logger name="TBF.BenchControl.Elde.PumpWithFM"> <level value="DEBUG" /> </logger>
|
||||
|
||||
<logger name="TBF.BenchControl.MettlerToledo"> <level value="INFO" /> </logger>
|
||||
<logger name="TBF.BenchControl.MettlerToledo.BalanceDev"> <level value="WARN" /> </logger>
|
||||
<logger name="TBF.BenchControl.MettlerToledo.BalanceNewDev"> <level value="WARN" /> </logger>
|
||||
<logger name="TBF.BenchControl.MettlerToledo.ReadMassOp"> <level value="INFO" /> </logger>
|
||||
<logger name="TBF.BenchControl.MettlerToledo.ReadStableMassOp"> <level value="INFO" /> </logger>
|
||||
|
||||
<logger name="TBF.BenchControl.IdcCamera"> <level value="INFO" /> </logger>
|
||||
<logger name="TBF.BenchControl.Elde.StartMeasurementOp"> <level value="DEBUG" /> </logger>
|
||||
</log4net>
|
||||
|
||||
@ -358,6 +358,7 @@
|
||||
<Compile Include="BenchControl\WaterMeters\iPerl\ConfigStruct.cs" />
|
||||
<Compile Include="BenchControl\WaterMeters\iPerl\Enums.cs" />
|
||||
<Compile Include="BenchControl\WaterMeters\iPerl\OptoReceivedEventArgs.cs" />
|
||||
<Compile Include="BenchControl\WaterMeters\iPerl\OptoTelegram.cs" />
|
||||
<Compile Include="BenchControl\WaterMeters\iPerl\ProcParams.cs" />
|
||||
<Compile Include="BenchControl\WaterMeters\iPerl\StatusStruct.cs" />
|
||||
<Compile Include="BenchControl\WaterMeters\iPerl\WaterMeter.cs" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user