Mexico - read additional parameters and store to DB, ver. 3.9.3135.0
Add support for reading and handling additional common parameters in OptoHeadTest. Extend RadioService and related classes with enhanced parsing and validation logic. Update UI and constants for functionality integration.
This commit is contained in:
parent
126322584f
commit
55d2381e8a
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("3.9.3134.112")]
|
[assembly: AssemblyVersion("3.9.3135.0")]
|
||||||
[assembly: AssemblyFileVersion("3.9.3134.112")]
|
[assembly: AssemblyFileVersion("3.9.3135.0")]
|
||||||
|
|||||||
@ -10,6 +10,7 @@ using Config.Entities;
|
|||||||
using TBF.Resources;
|
using TBF.Resources;
|
||||||
using TBF.Rig.Generic;
|
using TBF.Rig.Generic;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication;
|
using TBF.Rig.TestMethods.iPerlCommunication;
|
||||||
|
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication;
|
||||||
|
|
||||||
namespace TBF.Rig.TestMethods.GenesisCommunication
|
namespace TBF.Rig.TestMethods.GenesisCommunication
|
||||||
{
|
{
|
||||||
@ -51,6 +52,7 @@ namespace TBF.Rig.TestMethods.GenesisCommunication
|
|||||||
{
|
{
|
||||||
var retVal = new List<string>();
|
var retVal = new List<string>();
|
||||||
retVal.Add(iPerlCommunicationForm.ReadConfigurationStr);
|
retVal.Add(iPerlCommunicationForm.ReadConfigurationStr);
|
||||||
|
retVal.Add(iPerlCommunicationConstants.ReadAdditionalCommonParametersStr);
|
||||||
retVal.Add(iPerlCommunicationForm.ReadSerialNrStr);
|
retVal.Add(iPerlCommunicationForm.ReadSerialNrStr);
|
||||||
retVal.Add(string.Format("{0} A0", iPerlCommunicationForm.SetTestModeStr));
|
retVal.Add(string.Format("{0} A0", iPerlCommunicationForm.SetTestModeStr));
|
||||||
retVal.Add(string.Format("{0} A4", iPerlCommunicationForm.SetTestModeStr));
|
retVal.Add(string.Format("{0} A4", iPerlCommunicationForm.SetTestModeStr));
|
||||||
|
|||||||
@ -47,6 +47,7 @@ namespace TBF.Rig.TestMethods.SmartMeterFlyingStartMassCollection
|
|||||||
{
|
{
|
||||||
var retVal = new List<string>();
|
var retVal = new List<string>();
|
||||||
retVal.Add(iPerlCommunicationConstants.ReadConfigurationStr);
|
retVal.Add(iPerlCommunicationConstants.ReadConfigurationStr);
|
||||||
|
retVal.Add(iPerlCommunicationConstants.ReadAdditionalCommonParametersStr);
|
||||||
retVal.Add(string.Format("{0} A0", iPerlCommunicationConstants.SetTestModeStr));
|
retVal.Add(string.Format("{0} A0", iPerlCommunicationConstants.SetTestModeStr));
|
||||||
retVal.Add(string.Format("{0} A4", iPerlCommunicationConstants.SetTestModeStr));
|
retVal.Add(string.Format("{0} A4", iPerlCommunicationConstants.SetTestModeStr));
|
||||||
retVal.Add(iPerlCommunicationConstants.ReadCalibrationStr);
|
retVal.Add(iPerlCommunicationConstants.ReadCalibrationStr);
|
||||||
|
|||||||
@ -4,9 +4,20 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommon
|
|||||||
{
|
{
|
||||||
CubicMeters = 0x00,
|
CubicMeters = 0x00,
|
||||||
CubicFeet = 0x01,
|
CubicFeet = 0x01,
|
||||||
UsGallons = 0x02,
|
Unknown_0x02 = 0x02,
|
||||||
UsGallons1 = 0x04,
|
Unknown_0x03 = 0x03,
|
||||||
UsGallons2 = 0x08,
|
UsGallons = 0x04,
|
||||||
UsGallons3 = 0x10,
|
Unknown_0x05 = 0x05,
|
||||||
|
Unknown_0x06 = 0x06,
|
||||||
|
Unknown_0x07 = 0x07,
|
||||||
|
Unknown_0x08 = 0x08,
|
||||||
|
Unknown_0x09 = 0x09,
|
||||||
|
Unknown_0x0A = 0x0A,
|
||||||
|
Unknown_0x0B = 0x0B,
|
||||||
|
Unknown_0x0C = 0x0C,
|
||||||
|
Unknown_0x0D = 0x0D,
|
||||||
|
Unknown_0x0E = 0x0E,
|
||||||
|
Unknown_0x0F = 0x0F,
|
||||||
|
Unknown_0x10 = 0x10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,7 +332,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
|
|
||||||
if (iperlHead != null)
|
if (iperlHead != null)
|
||||||
{
|
{
|
||||||
iperlHead.ConfigStruct = new ConfigStruct();
|
if (iperlHead.ConfigStruct == null)
|
||||||
|
{
|
||||||
|
iperlHead.ConfigStruct = new ConfigStruct();
|
||||||
|
}
|
||||||
|
|
||||||
if (serialDriver == null)
|
if (serialDriver == null)
|
||||||
serialDriver = BuildConnection(iperlHead);
|
serialDriver = BuildConnection(iperlHead);
|
||||||
@ -691,39 +694,43 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads additional common parameters:
|
/// Reads additional common parameters and stores them
|
||||||
/// version and type, reading units, flip mode
|
/// in the current iPerl ConfigStruct.
|
||||||
/// and calibration factor.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resultStr">
|
public bool ReadAdditionalCommonParameters( out string resultStr, bool prettyText)
|
||||||
/// Result intended for GUI and test-process output.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// True when all parameters were read successfully.
|
|
||||||
/// </returns>
|
|
||||||
public bool ReadAdditionalCommonParameters(
|
|
||||||
out string resultStr)
|
|
||||||
{
|
{
|
||||||
resultStr = string.Empty;
|
resultStr = string.Empty;
|
||||||
|
|
||||||
if (iperlHead == null)
|
if (iperlHead == null)
|
||||||
{
|
{
|
||||||
resultStr =
|
resultStr = "Read additional common parameters: iPerl head is null.";
|
||||||
"Read additional common parameters: iPerl head is null.";
|
|
||||||
|
|
||||||
log.Warn(resultStr);
|
log.Warn(resultStr);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iperlHead.ConfigStruct == null)
|
||||||
|
{
|
||||||
|
iperlHead.ConfigStruct = new ConfigStruct();
|
||||||
|
}
|
||||||
|
|
||||||
if (iperlHead.DebugLevel == DebugMode.Simulate)
|
if (iperlHead.DebugLevel == DebugMode.Simulate)
|
||||||
{
|
{
|
||||||
resultStr =
|
iperlHead.ConfigStruct.VersionType = new VersionTypeResult
|
||||||
"Version/type: SIMULATED; " +
|
{
|
||||||
"Reading units: CubicMeters; " +
|
TouchReadVersion = "SIMULATED",
|
||||||
"Flip mode: 0x00; " +
|
MeterDeviceType = "SIMULATED",
|
||||||
"Calibration: 4096 (100.0000 %, correction 0.0000 %)";
|
MeterFirmwareVersion = "SIMULATED"
|
||||||
|
};
|
||||||
|
|
||||||
|
iperlHead.ConfigStruct.ReadingUnits = ReadingUnits.CubicMeters;
|
||||||
|
iperlHead.ConfigStruct.FlipMode = (FlipMode)0x00;
|
||||||
|
iperlHead.ConfigStruct.Calibration = new CalibrationFactorResult {
|
||||||
|
RawValue = 4096,
|
||||||
|
Percentage = 100.0,
|
||||||
|
CorrectionPercentage = 0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
resultStr = BuildAdditionalCommonParametersString( iperlHead.ConfigStruct, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,97 +742,96 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
BuildConnection(iperlHead);
|
BuildConnection(iperlHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
var headService =
|
var headService = new RadioService(serialDriver);
|
||||||
new RadioService(serialDriver);
|
VersionTypeResult versionType = headService.SetViewVersionAndType( iperlHead);
|
||||||
|
ReadingUnits? readingUnits = headService.ViewReadingUnits( iperlHead);
|
||||||
|
FlipMode? flipMode = headService.ViewFlipMode( iperlHead);
|
||||||
|
CalibrationFactorResult calibration = headService.ViewCalibration( iperlHead);
|
||||||
|
|
||||||
VersionTypeResult versionType =
|
/*
|
||||||
headService.SetViewVersionAndType(iperlHead);
|
* Save received values into ConfigStruct.
|
||||||
|
* Null values replace old values after an unsuccessful read.
|
||||||
|
*/
|
||||||
|
iperlHead.ConfigStruct.VersionType = versionType;
|
||||||
|
iperlHead.ConfigStruct.ReadingUnits = readingUnits;
|
||||||
|
iperlHead.ConfigStruct.FlipMode = flipMode;
|
||||||
|
iperlHead.ConfigStruct.Calibration = calibration;
|
||||||
|
|
||||||
ReadingUnits? readingUnits =
|
bool successful = versionType != null && readingUnits.HasValue && flipMode.HasValue && calibration != null;
|
||||||
headService.ViewReadingUnits(iperlHead);
|
resultStr = BuildAdditionalCommonParametersString( iperlHead.ConfigStruct, prettyText);
|
||||||
|
|
||||||
FlipMode? flipMode =
|
|
||||||
headService.ViewFlipMode(iperlHead);
|
|
||||||
|
|
||||||
CalibrationFactorResult calibration =
|
|
||||||
headService.ViewCalibration(iperlHead);
|
|
||||||
|
|
||||||
bool successful =
|
|
||||||
versionType != null &&
|
|
||||||
readingUnits.HasValue &&
|
|
||||||
flipMode.HasValue &&
|
|
||||||
calibration != null;
|
|
||||||
|
|
||||||
string versionTypeText =
|
|
||||||
versionType == null
|
|
||||||
? "FAILED"
|
|
||||||
: versionType.ToString();
|
|
||||||
|
|
||||||
string readingUnitsText =
|
|
||||||
readingUnits.HasValue
|
|
||||||
? string.Format(
|
|
||||||
"{0} (0x{1:X2})",
|
|
||||||
readingUnits.Value,
|
|
||||||
Convert.ToByte(readingUnits.Value))
|
|
||||||
: "FAILED";
|
|
||||||
|
|
||||||
string flipModeText =
|
|
||||||
flipMode.HasValue
|
|
||||||
? string.Format(
|
|
||||||
"{0} (0x{1:X2})",
|
|
||||||
flipMode.Value,
|
|
||||||
Convert.ToByte(flipMode.Value))
|
|
||||||
: "FAILED";
|
|
||||||
|
|
||||||
string calibrationText;
|
|
||||||
|
|
||||||
if (calibration == null)
|
|
||||||
{
|
|
||||||
calibrationText = "FAILED";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
calibrationText = string.Format(
|
|
||||||
"{0} ({1:F4} %, correction {2:+0.0000;-0.0000;0.0000} %)",
|
|
||||||
calibration.RawValue,
|
|
||||||
calibration.Percentage,
|
|
||||||
calibration.CorrectionPercentage);
|
|
||||||
}
|
|
||||||
|
|
||||||
resultStr =
|
|
||||||
"Version/type: " + versionTypeText +
|
|
||||||
"; Reading units: " + readingUnitsText +
|
|
||||||
"; Flip mode: " + flipModeText +
|
|
||||||
"; Calibration: " + calibrationText;
|
|
||||||
|
|
||||||
if (successful)
|
if (successful)
|
||||||
{
|
{
|
||||||
log.Info(
|
log.Info( "ReadAdditionalCommonParameters: " + resultStr);
|
||||||
"ReadAdditionalCommonParameters: " +
|
|
||||||
resultStr);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Warn(
|
log.Warn( "ReadAdditionalCommonParameters failed: " + resultStr);
|
||||||
"ReadAdditionalCommonParameters failed: " +
|
|
||||||
resultStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return successful;
|
return successful;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
resultStr =
|
resultStr = "Read additional common parameters failed: " + ex.Message;
|
||||||
"Read additional common parameters failed: " +
|
log.Error( "ReadAdditionalCommonParameters failed.", ex);
|
||||||
ex.Message;
|
|
||||||
|
|
||||||
log.Error(
|
|
||||||
"ReadAdditionalCommonParameters failed.",
|
|
||||||
ex);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string BuildAdditionalCommonParametersString(
|
||||||
|
ConfigStruct config, bool prettyText)
|
||||||
|
{
|
||||||
|
if (config == null)
|
||||||
|
{
|
||||||
|
return "Additional common parameters are not available.";
|
||||||
|
}
|
||||||
|
|
||||||
|
string versionTypeText = config.VersionType == null ? "Not available" : config.VersionType.ToString();
|
||||||
|
string readingUnitsText = config.ReadingUnits.HasValue ?
|
||||||
|
string.Format( "{0} (0x{1:X2})", config.ReadingUnits.Value, Convert.ToByte( config.ReadingUnits.Value))
|
||||||
|
: "Not available";
|
||||||
|
|
||||||
|
string flipModeText = config.FlipMode.HasValue ?
|
||||||
|
string.Format( "{0} (0x{1:X2})", config.FlipMode.Value, Convert.ToByte( config.FlipMode.Value))
|
||||||
|
: "Not available";
|
||||||
|
|
||||||
|
string calibrationText;
|
||||||
|
|
||||||
|
if (config.Calibration == null)
|
||||||
|
{
|
||||||
|
calibrationText = "Not available";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
calibrationText =
|
||||||
|
string.Format( "{0} ({1:F4} %, correction " + "{2:+0.0000;-0.0000;0.0000} %)",
|
||||||
|
config.Calibration.RawValue,
|
||||||
|
config.Calibration.Percentage,
|
||||||
|
config.Calibration.CorrectionPercentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prettyText)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
"Version/type: {0}{4}" +
|
||||||
|
"Reading units: {1}{4}" +
|
||||||
|
"Flip mode: {2}{4}" +
|
||||||
|
"Calibration: {3}",
|
||||||
|
versionTypeText,
|
||||||
|
readingUnitsText,
|
||||||
|
flipModeText,
|
||||||
|
calibrationText,
|
||||||
|
Environment.NewLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
|
"Version/type: " + versionTypeText +
|
||||||
|
"; Reading units: " + readingUnitsText +
|
||||||
|
"; Flip mode: " + flipModeText +
|
||||||
|
"; Calibration: " + calibrationText;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,7 +294,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlipMode? ViewFlipMode(IperlHead iHead)
|
public FlipMode? ViewFlipMode(IperlHead iHead)
|
||||||
{
|
{
|
||||||
if (!serialDriver.IsOpen())
|
if (!serialDriver.IsOpen())
|
||||||
@ -302,7 +302,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
serialDriver.Open();
|
serialDriver.Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] request = new TouchReadFrameBuilder()
|
byte[] request = new IperlHatFrameBuilder()
|
||||||
.RequestResponse(true)
|
.RequestResponse(true)
|
||||||
.AddDeviceCommand(ProtocolDeviceSubCommand.ViewFlipMode)
|
.AddDeviceCommand(ProtocolDeviceSubCommand.ViewFlipMode)
|
||||||
.BuildBytes();
|
.BuildBytes();
|
||||||
@ -311,71 +311,73 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
|
|
||||||
if (rawData == null || rawData.Length == 0)
|
if (rawData == null || rawData.Length == 0)
|
||||||
{
|
{
|
||||||
log.Warn("ViewFlipMode: No response received.");
|
log.Warn( "ViewFlipMode: No response received.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var parser = new IperlHatFrameParser();
|
var parser = new IperlHatFrameParser();
|
||||||
|
|
||||||
IperlHatResponse decoded = parser.Parse(rawData);
|
IperlHatResponse decoded = parser.Parse(rawData);
|
||||||
|
|
||||||
log.Debug("ViewFlipMode isOK: " + decoded.IsOk);
|
log.Debug( "ViewFlipMode isOK: " + decoded.IsOk);
|
||||||
|
|
||||||
if (!decoded.IsOk)
|
if (!decoded.IsOk)
|
||||||
{
|
{
|
||||||
log.Warn("ViewFlipMode: Device returned NOK response.");
|
log.Warn( "ViewFlipMode: Device returned NOK response.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlipMode flipMode =
|
if (decoded.Payload == null || decoded.Payload.Length != 1)
|
||||||
decoded.GetResponse<FlipMode>(out bool responseOk);
|
|
||||||
|
|
||||||
if (!responseOk)
|
|
||||||
{
|
{
|
||||||
log.Warn(
|
log.Warn( "ViewFlipMode: Invalid payload. Expected exactly one byte. Payload="
|
||||||
"ViewFlipMode: Invalid payload. Expected one byte " +
|
+ BitConverter.ToString( decoded.Payload ?? new byte[0]));
|
||||||
"with value 0x00 or 0x01. Payload=" +
|
|
||||||
BitConverter.ToString(decoded.Payload));
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug(
|
byte rawValue = decoded.Payload[0];
|
||||||
$"ViewFlipMode: {flipMode} " +
|
|
||||||
$"(0x{(byte)flipMode:X2})");
|
|
||||||
|
|
||||||
|
if (!Enum.IsDefined( typeof(FlipMode), rawValue))
|
||||||
|
{
|
||||||
|
log.Warn( $"ViewFlipMode: Unknown value. Value=0x{rawValue:X2}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
FlipMode flipMode = (FlipMode)rawValue;
|
||||||
|
|
||||||
|
log.Debug( $"ViewFlipMode: {flipMode} " + $"(0x{rawValue:X2})");
|
||||||
return flipMode;
|
return flipMode;
|
||||||
}
|
}
|
||||||
catch (FormatException ex)
|
catch (FormatException ex)
|
||||||
{
|
{
|
||||||
log.Error("ViewFlipMode: Invalid response frame.", ex);
|
log.Error( "ViewFlipMode: Invalid response frame.", ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Error("ViewFlipMode failed.", ex);
|
log.Error( "ViewFlipMode failed.", ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalibrationFactorResult ViewCalibration(IperlHead iHead)
|
public CalibrationFactorResult ViewCalibration( IperlHead iHead)
|
||||||
{
|
{
|
||||||
if (!serialDriver.IsOpen())
|
if (!serialDriver.IsOpen())
|
||||||
{
|
{
|
||||||
serialDriver.Open();
|
serialDriver.Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] request = new TouchReadFrameBuilder()
|
byte[] request = new IperlHatFrameBuilder()
|
||||||
.RequestResponse(true)
|
.RequestResponse(true)
|
||||||
.AddDeviceCommand(ProtocolDeviceSubCommand.ViewCalibration)
|
.AddDeviceCommand( ProtocolDeviceSubCommand.ViewCalibration)
|
||||||
.BuildBytes();
|
.BuildBytes();
|
||||||
|
|
||||||
byte[] rawData = serialDriver.SendAndWait(request, 5000);
|
byte[] rawData = serialDriver.SendAndWait(request, 5000);
|
||||||
|
|
||||||
if (rawData == null || rawData.Length == 0)
|
if (rawData == null || rawData.Length == 0)
|
||||||
{
|
{
|
||||||
log.Warn("ViewCalibration: No response received.");
|
log.Warn( "ViewCalibration: No response received.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,38 +386,38 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
var parser = new IperlHatFrameParser();
|
var parser = new IperlHatFrameParser();
|
||||||
IperlHatResponse decoded = parser.Parse(rawData);
|
IperlHatResponse decoded = parser.Parse(rawData);
|
||||||
|
|
||||||
log.Debug("ViewCalibration isOK: " + decoded.IsOk);
|
log.Debug( "ViewCalibration isOK: " + decoded.IsOk);
|
||||||
|
|
||||||
if (!decoded.IsOk)
|
if (!decoded.IsOk)
|
||||||
{
|
{
|
||||||
log.Warn("ViewCalibration: Device returned NOK response.");
|
log.Warn( "ViewCalibration: Device returned NOK response.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ushort calibrationFactor = decoded.GetUInt16LittleEndian(out bool responseOk);
|
if (decoded.Payload == null || decoded.Payload.Length != 2)
|
||||||
|
|
||||||
if (!responseOk)
|
|
||||||
{
|
{
|
||||||
log.Warn( "ViewCalibration: Invalid payload. Expected uint16 little-endian value. Payload=" + BitConverter.ToString(decoded.Payload));
|
log.Warn( "ViewCalibration: Invalid payload. Expected two-byte little-endian value. Payload=" +
|
||||||
|
BitConverter.ToString( decoded.Payload ?? new byte[0]));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ushort calibrationFactor = (ushort)( decoded.Payload[0] | (decoded.Payload[1] << 8));
|
||||||
|
|
||||||
double percentage = calibrationFactor * 100.0 / 4096.0;
|
double percentage = calibrationFactor * 100.0 / 4096.0;
|
||||||
|
|
||||||
var result = new CalibrationFactorResult
|
var result = new CalibrationFactorResult
|
||||||
{
|
{
|
||||||
RawValue = calibrationFactor,
|
RawValue = calibrationFactor,
|
||||||
Percentage = percentage,
|
Percentage = percentage,
|
||||||
CorrectionPercentage = percentage - 100.0
|
CorrectionPercentage = percentage - 100.0
|
||||||
};
|
};
|
||||||
|
|
||||||
log.Debug("ViewCalibration result: " + result);
|
|
||||||
|
|
||||||
|
log.Debug( "ViewCalibration result: " + result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch (FormatException ex)
|
catch (FormatException ex)
|
||||||
{
|
{
|
||||||
log.Error("ViewCalibration: Invalid response frame.", ex);
|
log.Error( "ViewCalibration: Invalid response frame.", ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -424,7 +426,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -717,7 +717,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
|||||||
else if (currentActivity.ToLower().Equals(SetActiveModeStr.ToLower())) error = SetActiveMode(threadID, ihead, ref resultStr);
|
else if (currentActivity.ToLower().Equals(SetActiveModeStr.ToLower())) error = SetActiveMode(threadID, ihead, ref resultStr);
|
||||||
else if (currentActivity.ToLower().Equals(SetIdleModeStr.ToLower())) error = SetIdleMode(threadID, ihead, ref resultStr);
|
else if (currentActivity.ToLower().Equals(SetIdleModeStr.ToLower())) error = SetIdleMode(threadID, ihead, ref resultStr);
|
||||||
else if (currentActivity.ToLower().Contains(ReadConfigurationStr.ToLower())) error = ReadConfiguration(ihead, wm, ref resultStr);
|
else if (currentActivity.ToLower().Contains(ReadConfigurationStr.ToLower())) error = ReadConfiguration(ihead, wm, ref resultStr);
|
||||||
else if (currentActivity.ToLower().Contains( iPerlCommunicationConstants.ReadAdditionalCommonParametersStr.ToLower())) error = ReadAdditionalCommonParameters( ihead, ref resultStr);
|
else if (currentActivity.ToLower().Contains( iPerlCommunicationConstants.ReadAdditionalCommonParametersStr.ToLower())) error = ReadAdditionalCommonParameters( ihead,wm, ref resultStr);
|
||||||
///
|
///
|
||||||
/// RFID communication functions below require a reference to water meter entity (wm != null)
|
/// RFID communication functions below require a reference to water meter entity (wm != null)
|
||||||
///
|
///
|
||||||
@ -890,7 +890,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
|||||||
if (ihead.CommFailed) return CommErr.CommFailed;
|
if (ihead.CommFailed) return CommErr.CommFailed;
|
||||||
|
|
||||||
//zeroing
|
//zeroing
|
||||||
ihead.ConfigStruct = null; /// Clear previous ConfigStruct, avoid reuse of (not anymore valid) PCB Number
|
//ihead.ConfigStruct = null; /// Clear previous ConfigStruct, avoid reuse of (not anymore valid) PCB Number
|
||||||
|
|
||||||
CommErr error = CommErr.Read;
|
CommErr error = CommErr.Read;
|
||||||
int readRetVal = 0;
|
int readRetVal = 0;
|
||||||
@ -1018,20 +1018,24 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads additional common parameters through the optical head.
|
/// Reads additional common parameters through the optical head.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static CommErr ReadAdditionalCommonParameters( IperlHead ihead, ref string resultStr)
|
private static CommErr ReadAdditionalCommonParameters( IperlHead ihead, WaterMeter wm, ref string resultStr)
|
||||||
{
|
{
|
||||||
if (ihead == null)
|
if (ihead == null)
|
||||||
{
|
{
|
||||||
resultStr = "Read additional common parameters: iPerl head is null.";
|
resultStr = "Read additional common parameters: iPerl head is null.";
|
||||||
return CommErr.CommFailed;
|
return CommErr.CommFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ihead.CommFailed)
|
if (wm == null)
|
||||||
{
|
{
|
||||||
resultStr = "Read additional common parameters: previous communication failed.";
|
resultStr =
|
||||||
|
"Read additional common parameters: WaterMeter is null.";
|
||||||
|
|
||||||
return CommErr.CommFailed;
|
return CommErr.CommFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ihead.CommFailed = false;
|
||||||
|
|
||||||
if (ihead.OptoHeadTest == null)
|
if (ihead.OptoHeadTest == null)
|
||||||
{
|
{
|
||||||
resultStr = "Read additional common parameters: OptoHeadTest is not available.";
|
resultStr = "Read additional common parameters: OptoHeadTest is not available.";
|
||||||
@ -1040,8 +1044,72 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool successful = ihead.OptoHeadTest.ReadAdditionalCommonParameters( out resultStr);
|
log.DebugFormat( "ReadAdditionalCommonParameters started: Head={0}", ihead);
|
||||||
return successful ? CommErr.None : CommErr.Read;
|
|
||||||
|
bool successful = ihead.OptoHeadTest.ReadAdditionalCommonParameters( out resultStr, false);
|
||||||
|
|
||||||
|
log.DebugFormat( "ReadAdditionalCommonParameters finished: Head={0}, successful={1}, result={2}",
|
||||||
|
ihead, successful, resultStr);
|
||||||
|
|
||||||
|
if (successful)
|
||||||
|
{
|
||||||
|
ConfigStruct config = ihead.ConfigStruct;
|
||||||
|
|
||||||
|
if (config != null)
|
||||||
|
{
|
||||||
|
if (config.VersionType != null)
|
||||||
|
{
|
||||||
|
wm.FWVersion = string.Format(
|
||||||
|
"{0} {1} {2}",
|
||||||
|
config.VersionType.TouchReadVersion,
|
||||||
|
config.VersionType.MeterDeviceType,
|
||||||
|
config.VersionType.MeterFirmwareVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.ReadingUnits.HasValue)
|
||||||
|
{
|
||||||
|
wm.SerialNrAux =
|
||||||
|
config.ReadingUnits.Value.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.FlipMode.HasValue)
|
||||||
|
{
|
||||||
|
wm.RadioAddress =
|
||||||
|
config.FlipMode.Value.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.Calibration != null)
|
||||||
|
{
|
||||||
|
wm.CalibFactor =
|
||||||
|
config.Calibration.RawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.DebugFormat(
|
||||||
|
"Additional common parameters copied to WaterMeter: " +
|
||||||
|
"FWVersion={0}, ReadingUnits={1}, FlipMode={2}, CalibFactor={3}",
|
||||||
|
wm.FWVersion,
|
||||||
|
wm.SerialNrAux,
|
||||||
|
wm.RadioAddress,
|
||||||
|
wm.CalibFactor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.WarnFormat(
|
||||||
|
"Additional common parameters were read, but ConfigStruct is null: Head={0}",
|
||||||
|
ihead);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommErr.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(resultStr))
|
||||||
|
{
|
||||||
|
resultStr = "Failed to read additional common parameters.";
|
||||||
|
}
|
||||||
|
|
||||||
|
log.ErrorFormat( "ReadAdditionalCommonParameters failed: Head={0}, result={1}", ihead, resultStr);
|
||||||
|
|
||||||
|
return CommErr.Read;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -2765,7 +2833,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
success = iHead.OptoHeadTest .ReadAdditionalCommonParameters( out txt);
|
success = iHead.OptoHeadTest .ReadAdditionalCommonParameters( out txt, false);
|
||||||
|
|
||||||
if (!success && string.IsNullOrWhiteSpace(txt))
|
if (!success && string.IsNullOrWhiteSpace(txt))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -10,6 +10,7 @@ using Config.Entities;
|
|||||||
using TBF.Rig.Generic;
|
using TBF.Rig.Generic;
|
||||||
using TBF.Resources;
|
using TBF.Resources;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication;
|
||||||
|
|
||||||
namespace TBF.Rig.TestMethods.iPerlCommunication
|
namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||||
{
|
{
|
||||||
@ -51,6 +52,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
|||||||
{
|
{
|
||||||
var retVal = new List<string>();
|
var retVal = new List<string>();
|
||||||
retVal.Add(iPerlCommunicationForm.ReadConfigurationStr);
|
retVal.Add(iPerlCommunicationForm.ReadConfigurationStr);
|
||||||
|
retVal.Add(iPerlCommunicationConstants.ReadAdditionalCommonParametersStr);
|
||||||
retVal.Add(iPerlCommunicationForm.ReadSerialNrStr);
|
retVal.Add(iPerlCommunicationForm.ReadSerialNrStr);
|
||||||
retVal.Add(string.Format("{0} A0", iPerlCommunicationForm.SetTestModeStr));
|
retVal.Add(string.Format("{0} A0", iPerlCommunicationForm.SetTestModeStr));
|
||||||
retVal.Add(string.Format("{0} A4", iPerlCommunicationForm.SetTestModeStr));
|
retVal.Add(string.Format("{0} A4", iPerlCommunicationForm.SetTestModeStr));
|
||||||
|
|||||||
@ -20,6 +20,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
public string Unit; //dynamic
|
public string Unit; //dynamic
|
||||||
public string Version; // dynamic
|
public string Version; // dynamic
|
||||||
|
|
||||||
|
public VersionTypeResult VersionType { get; set; }
|
||||||
|
public ReadingUnits? ReadingUnits { get; set; }
|
||||||
|
public FlipMode? FlipMode { get; set; }
|
||||||
|
public CalibrationFactorResult Calibration { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ConfigStruct()
|
public ConfigStruct()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Web.UI.WebControls;
|
using System.Web.UI.WebControls;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@ -34,6 +35,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
var items = new[]
|
var items = new[]
|
||||||
{
|
{
|
||||||
new {Name = "Read PCB", Value = "ReadPCB" },
|
new {Name = "Read PCB", Value = "ReadPCB" },
|
||||||
|
new {Name = "Read Additional Common Parameters", Value = "ReadAdditionalCommonParameters" },
|
||||||
new {Name = "Set Test Mode", Value = "SetTestMode" },
|
new {Name = "Set Test Mode", Value = "SetTestMode" },
|
||||||
new {Name = "Set Active Mode", Value = "SetActiveMode" },
|
new {Name = "Set Active Mode", Value = "SetActiveMode" },
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -80,12 +82,50 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
ListItem rfidListItem = new ListItem();
|
ListItem rfidListItem = new ListItem();
|
||||||
rfidListItem.Attributes.Add("style", "font-volume:bold");
|
rfidListItem.Attributes.Add("style", "font-volume:bold");
|
||||||
//rfidListItem.Attributes.Add("style", "font-weight:bold");
|
//rfidListItem.Attributes.Add("style", "font-weight:bold");
|
||||||
|
|
||||||
|
List<ListItem> additionalItems = new List<ListItem>();
|
||||||
|
|
||||||
bool isTestModeSuccessful = false;
|
bool isTestModeSuccessful = false;
|
||||||
switch (rfidCommandComboBox.SelectedValue)
|
switch (rfidCommandComboBox.SelectedValue)
|
||||||
{
|
{
|
||||||
case "ReadPCB":
|
case "ReadPCB":
|
||||||
rfidListItem.Text = $"PCB: {iPerlHead.OptoHeadTest.ReadRequest_PCB()}";
|
rfidListItem.Text = $"PCB: {iPerlHead.OptoHeadTest.ReadRequest_PCB()}";
|
||||||
break;
|
break;
|
||||||
|
case "ReadAdditionalCommonParameters":
|
||||||
|
{
|
||||||
|
if (iPerlHead == null)
|
||||||
|
{
|
||||||
|
rfidListItem.Text = "FAILED: iPerl head is not available.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iPerlHead.OptoHeadTest == null)
|
||||||
|
{
|
||||||
|
rfidListItem.Text = "FAILED: OptoHeadTest is not available.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool successful = iPerlHead.OptoHeadTest.ReadAdditionalCommonParameters( out string result, true);
|
||||||
|
|
||||||
|
if (!successful)
|
||||||
|
{
|
||||||
|
rfidListItem.Text = "FAILED: " + result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rfidListItem.Text = "Additional common parameters:";
|
||||||
|
|
||||||
|
string[] resultLines = result.Split(
|
||||||
|
new[] { "\r\n", "\n", "\r" },
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
foreach (string line in resultLines)
|
||||||
|
{
|
||||||
|
additionalItems.Add( new ListItem(" " + line.Trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "SetTestMode":
|
case "SetTestMode":
|
||||||
rfidListItem.Text = iPerlHead.OptoHeadTest.SetTestMode(ref isTestModeSuccessful);
|
rfidListItem.Text = iPerlHead.OptoHeadTest.SetTestMode(ref isTestModeSuccessful);
|
||||||
optoListBox.Items.Clear();
|
optoListBox.Items.Clear();
|
||||||
@ -133,6 +173,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rfidOutputListBox.Items.Add(rfidListItem);
|
rfidOutputListBox.Items.Add(rfidListItem);
|
||||||
|
foreach (ListItem item in additionalItems)
|
||||||
|
{
|
||||||
|
rfidOutputListBox.Items.Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
rfidOutputListBox.Items.AddRange(logChecker.Messages.ToArray());
|
rfidOutputListBox.Items.AddRange(logChecker.Messages.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@ using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.diagnosticLed.pars
|
|||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.hexLogger;
|
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.hexLogger;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons;
|
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons.TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
|
||||||
|
|
||||||
|
|
||||||
namespace TBFTests.Rig.RegisterReaders.iPerlASICReader.communication.C4.IperlHatProtocol
|
namespace TBFTests.Rig.RegisterReaders.iPerlASICReader.communication.C4.IperlHatProtocol
|
||||||
|
|||||||
@ -2,10 +2,8 @@ using System;
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication;
|
using TBF.Rig.TestMethods.iPerlCommunication.communication;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4;
|
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons;
|
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons.TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.wiredProtocol;
|
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.wiredProtocol;
|
||||||
using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead;
|
using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user