Working on iPerlCommunication activities required for the production cycle.
This commit is contained in:
+144
-57
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user