Working on iPerlCommunication activities required for the production cycle.
This commit is contained in:
parent
289e06ce65
commit
7e28381df5
@ -393,9 +393,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
wmFound = true;
|
||||
if (wm.DebugLevel == Entities.DebugMode.Normal)
|
||||
{
|
||||
if (activity.Equals("Read configuration")) ReadConfig(wm, threadId, wmNr);
|
||||
else if (activity.Equals("Set to test mode")) SetToTestMode(wm, threadId, wmNr);
|
||||
else if (activity.Equals("Set to active mode")) SetToActiveMode(wm, threadId, wmNr);
|
||||
if (activity.ToLower().Equals("read configuration")) ReadConfig(wm, threadId, wmNr);
|
||||
else if (activity.ToLower().Equals("read calibration")) ReadCalibration(wm, threadId, wmNr);
|
||||
else if (activity.ToLower().Contains("set test mode")) SetToTestMode(wm, threadId, wmNr);
|
||||
else if (activity.ToLower().Equals("set active mode")) SetToActiveMode(wm, threadId, wmNr);
|
||||
else OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Invalid activity"));
|
||||
}
|
||||
else
|
||||
@ -412,28 +413,43 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Read a complete configuration structure of the watermeter
|
||||
/// </summary>
|
||||
/// <param name="wm">Water meter object</param>
|
||||
/// <param name="threadId">Thread ID</param>
|
||||
/// <param name="wmNr">Water meter number 1 .. 40</param>
|
||||
static void ReadConfig(WaterMeters.iPerl.WaterMeter wm, int threadId, int wmNr)
|
||||
{
|
||||
bool success = (0 == openPort(wm.RfidComPortNr)); /// Open RFID port
|
||||
bool success = false;
|
||||
byte[] config = null;
|
||||
|
||||
byte[] cfg = null;
|
||||
if (success)
|
||||
if (!wm.Disabled)
|
||||
{
|
||||
success = false;
|
||||
success = (0 == openPort(wm.RfidComPortNr)); /// Open RFID port
|
||||
|
||||
/// Read configuration
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
if (success)
|
||||
{
|
||||
if (0 == ReadRequestPort(MessageID.Configuration, 0, ConfigStruct.Length, out cfg, CommTimeout)) { success = true; break; }
|
||||
success = false;
|
||||
|
||||
/// Read configuration
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == ReadRequestPort(MessageID.Configuration, 0, ConfigStruct.Length, out config, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
}
|
||||
|
||||
closePort(); /// Close RFID port
|
||||
}
|
||||
|
||||
closePort(); /// Close RFID port
|
||||
|
||||
if (success)
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, ConfigStruct.FromByteArray(cfg).ToString(1)));
|
||||
wm.ConfigStruct = ConfigStruct.FromByteArray(config);
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, ConfigStruct.FromByteArray(config).ToString(1)));
|
||||
}
|
||||
else if (wm.Disabled)
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -441,81 +457,152 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void SetToTestMode(WaterMeters.iPerl.WaterMeter wm, int threadId, int wmNr)
|
||||
/// <summary>
|
||||
/// Read a complete calibration structure of the watermeter
|
||||
/// </summary>
|
||||
/// <param name="wm">Water meter object</param>
|
||||
/// <param name="threadId">Thread ID</param>
|
||||
/// <param name="wmNr">Water meter number 1 .. 40</param>
|
||||
static void ReadCalibration(WaterMeters.iPerl.WaterMeter wm, int threadId, int wmNr)
|
||||
{
|
||||
bool success = (openPort(wm.RfidComPortNr) == 0); /// Open RFID port
|
||||
bool success = false;
|
||||
byte[] calib = null;
|
||||
|
||||
if (success)
|
||||
if (!wm.Disabled)
|
||||
{
|
||||
success = false;
|
||||
success = (0 == openPort(wm.RfidComPortNr)); /// Open RFID port
|
||||
|
||||
/// Switch to test mode
|
||||
byte[] cmd = new byte[1] { (byte)7 };
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
if (success)
|
||||
{
|
||||
if (0 == WriteRequestPort(MessageID.Command, 0, 1, cmd, CommTimeout)) { success = true; break; }
|
||||
success = false;
|
||||
|
||||
/// Read calibration
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == ReadRequestPort(MessageID.Configuration, 0, CalibrationStruct.Length, out calib, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
}
|
||||
|
||||
closePort(); /// Close RFID port
|
||||
}
|
||||
|
||||
byte[] cfg = null;
|
||||
if (success)
|
||||
{
|
||||
success = false;
|
||||
|
||||
/// Read configuration
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == ReadRequestPort(MessageID.Configuration, 0, ConfigStruct.Length, out cfg, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
wm.CalibrationStruct = CalibrationStruct.FromByteArray(calib);
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Calibration successfully read"));
|
||||
}
|
||||
|
||||
closePort(); /// Close RFID port
|
||||
|
||||
if (success)
|
||||
else if (wm.Disabled)
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, ConfigStruct.FromByteArray(cfg).ToString(1)));
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Cannot switch to test mode"));
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Cannot read calibration"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the watermeter to the test mode.
|
||||
/// If testModeConfig is specified as a hexadeximal number appended to "set test mode ", it is verified
|
||||
/// whether the testModeConfig is correctly set, if necessary it is changed to the specified value.
|
||||
/// Read a part of configuration afterwards to verify the mode was set correctly.
|
||||
/// </summary>
|
||||
/// <param name="wm">Water meter object</param>
|
||||
/// <param name="threadId">Thread ID</param>
|
||||
/// <param name="wmNr">Water meter number 1 .. 40</param>
|
||||
static void SetToTestMode(WaterMeters.iPerl.WaterMeter wm, int threadId, int wmNr)
|
||||
{
|
||||
bool success = false;
|
||||
byte[] cfg_0_3 = null;
|
||||
|
||||
if (!wm.Disabled)
|
||||
{
|
||||
success = (openPort(wm.RfidComPortNr) == 0); /// Open RFID port
|
||||
|
||||
if (success)
|
||||
{
|
||||
success = false;
|
||||
|
||||
/// Switch to test mode
|
||||
byte[] cmd = new byte[1] { (byte)7 };
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == WriteRequestPort(MessageID.Command, 0, 1, cmd, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
success = false;
|
||||
|
||||
/// Read configuration
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == ReadRequestPort(MessageID.Configuration, 0, 4, out cfg_0_3, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
}
|
||||
|
||||
closePort(); /// Close RFID port
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
wm.ConfigStruct.Update(cfg_0_3, 0);
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, wm.ConfigStruct.ToString(1)));
|
||||
}
|
||||
else if (wm.Disabled)
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "'Set test mode' failed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void SetToActiveMode(WaterMeters.iPerl.WaterMeter wm, int threadId, int wmNr)
|
||||
{
|
||||
bool success = (openPort(wm.RfidComPortNr) == 0); /// Open RFID port
|
||||
bool success = false;
|
||||
byte[] cfg_0_3 = null;
|
||||
|
||||
if (success)
|
||||
if (!wm.Disabled)
|
||||
{
|
||||
success = false;
|
||||
success = (openPort(wm.RfidComPortNr) == 0); /// Open RFID port
|
||||
|
||||
/// Switch to active mode
|
||||
byte[] cmd = new byte[1] { (byte)6 };
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
if (success)
|
||||
{
|
||||
if (0 == WriteRequestPort(MessageID.Command, 0, 1, cmd, CommTimeout)) { success = true; break; }
|
||||
success = false;
|
||||
|
||||
/// Switch to active mode
|
||||
byte[] cmd = new byte[1] { (byte)6 };
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == WriteRequestPort(MessageID.Command, 0, 1, cmd, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
success = false;
|
||||
|
||||
/// Read configuration
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == ReadRequestPort(MessageID.Configuration, 0, ConfigStruct.Length, out cfg_0_3, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
}
|
||||
|
||||
closePort(); /// Close RFID port
|
||||
}
|
||||
|
||||
byte[] cfg = null;
|
||||
if (success)
|
||||
{
|
||||
success = false;
|
||||
|
||||
/// Read configuration
|
||||
for (int j = 0; j < MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == ReadRequestPort(MessageID.Configuration, 0, ConfigStruct.Length, out cfg, CommTimeout)) { success = true; break; }
|
||||
}
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, ConfigStruct.FromByteArray(cfg_0_3).ToString(1)));
|
||||
}
|
||||
|
||||
closePort(); /// Close RFID port
|
||||
|
||||
if (success)
|
||||
else if (wm.Disabled)
|
||||
{
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, ConfigStruct.FromByteArray(cfg).ToString(1)));
|
||||
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -77,6 +77,11 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a configuration structure from a complete byte array
|
||||
/// </summary>
|
||||
/// <param name="data">A complete byte array data</param>
|
||||
/// <returns>ConfigStruct or null when byte array was not complete</returns>
|
||||
public static ConfigStruct FromByteArray(byte[] data)
|
||||
{
|
||||
if (data.Length != Length) return null;
|
||||
@ -103,6 +108,53 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the configuration structure from an incomplete byte array
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array data</param>
|
||||
/// <param name="offset">Offset of byte array data in ConfigStruct</param>
|
||||
/// <returns>true when successful, false when data are not appropriate</returns>
|
||||
public bool Update(byte[] data, int offset)
|
||||
{
|
||||
if (offset == 0 && data.Length == 2)
|
||||
{
|
||||
/// Data containing an iPerl mode of function
|
||||
Version = data[0];
|
||||
MeterState = (MeterState)data[1];
|
||||
return true;
|
||||
}
|
||||
else if (offset == 0 && data.Length == 4)
|
||||
{
|
||||
/// Data containing an iPerl mode of function
|
||||
Version = data[0];
|
||||
MeterState = (MeterState)data[1];
|
||||
return true;
|
||||
}
|
||||
else if (offset == 0 && data.Length == Length)
|
||||
{
|
||||
/// Data containing a complete ConfigStruct
|
||||
Version = data[0];
|
||||
MeterState = (MeterState)data[1];
|
||||
TargetTimeVeryLowBatt = (((UInt32)data[5] * 256 + data[4]) * 256 + data[3]) * 256 + data[2];
|
||||
TargetTimeLowBatt = (((UInt32)data[9] * 256 + data[8]) * 256 + data[7]) * 256 + data[6];
|
||||
TestModeTime = (((UInt32)data[13] * 256 + data[12]) * 256 + data[11]) * 256 + data[10];
|
||||
EmptyPipeThreshold = (UInt16)(data[15] * 256 + data[14]);
|
||||
PCBNumber[0] = data[16];
|
||||
PCBNumber[1] = data[17];
|
||||
PCBNumber[2] = data[18];
|
||||
PCBNumber[3] = data[19];
|
||||
PCBNumber[4] = data[20];
|
||||
TestModeConfig = data[21];
|
||||
RadioAddress = (((UInt32)data[25] * 256 + data[24]) * 256 + data[23]) * 256 + data[22];
|
||||
TempCalibration = (UInt16)(data[27] * 256 + data[26]);
|
||||
AlarmMask = (UInt16)(data[29] * 256 + data[28]);
|
||||
ConfigCheckSum = (UInt16)(data[31] * 256 + data[30]);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("Config: V{0} State={1} VLoBattT={2}s LoBattT={3}s TestModeT={4}s EPThld={5} PCBNr={6} TestModeCfg={7} RadioAddr={8} TempCalib={9} AlarmMask={10} CfgCheckSum={11}",
|
||||
|
||||
@ -67,12 +67,21 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
}
|
||||
bool disabled;
|
||||
|
||||
/// <summary>
|
||||
/// ConfigStruct of the water meter obtained or updated by iPerlCommunication
|
||||
/// </summary>
|
||||
public ConfigStruct ConfigStruct;
|
||||
|
||||
/// <summary>
|
||||
/// CalibrationStruct of the water meter obtained or updated by iPerlCommunication
|
||||
/// </summary>
|
||||
public CalibrationStruct CalibrationStruct;
|
||||
|
||||
|
||||
Boxes.IntBox pulses;
|
||||
Boxes.IntBox refPulses;
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// Opto serial port and worker thread related private variables
|
||||
///
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("1.5.75.1")]
|
||||
[assembly: AssemblyFileVersion("1.5.75.1")]
|
||||
[assembly: AssemblyVersion("1.5.76.1")]
|
||||
[assembly: AssemblyFileVersion("1.5.76.1")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user