GenesisMeter: - deactivation of pulse output at login

This commit is contained in:
Thomas Wiedebusch
2023-03-06 15:12:09 +01:00
parent b2da1fabbf
commit 86833fcd6d
@@ -960,7 +960,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// <remarks date="2023-Jan-19" author="T.Wiedebusch">
/// - Password had been reset to empty string if read from file, corrected!
/// </remarks>
/// <remarks date="2023-Feb-28" author="T.Wiedebusch">
/// <remarks date="2023-Feb-28" author="T.Wiedebusch">
/// - Used <see cref="MeterPwdHandlerDb.GetPasswordFromDb"/>
/// </remarks>
private String GetPassword()
@@ -991,12 +991,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
_logger.Info($"Slot:{Slot} - Cannot get password from GenesisPasswordService, " +
$"URL({ServiceUrls.GenesisGetPasswordServiceUrl() + PcbId}))");
// try to read the password from an offline password file
if (!File.Exists(ProgramConfig.OfflineInfoFile)) return password;
if (!File.Exists(ProgramConfig.OfflineInfoFile))
return password;
var listOfOfflinePasswords = JsonConvert.DeserializeObject<List<OfflinePasswordItem>>(
File.ReadAllText(ProgramConfig.OfflineInfoFile));
password = listOfOfflinePasswords.First(x => x.PcbId == PcbId).Password;
if (!string.IsNullOrEmpty(password))
{
_logger.Info($"Slot:{Slot} - Got password for PcbId:{PcbId} from password file!");
@@ -1079,6 +1080,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// <remarks date="2023-Feb-20" author="Thomas Wiedebusch">
/// - Quick login removed.
/// </remarks>
/// <remarks date="2023-Mar-06" author="Thomas Wiedebusch">
/// - Pulse module deactivated at login.
/// </remarks>
public Boolean Login(String password, Boolean runImmediately = true)
{
@@ -1109,12 +1113,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
IsDevelopmentUsage = true;
}
if (!DeactivatePulseModule())
{
_logger.Warn($"Slot:{Slot} - Pulse module deactivation failed!");
}
ReadMeterFirmwareAndAssignRegisters();
}
else
{
_logger.Warn($"Slot:{Slot} - Login to meter failed");
_logger.Warn($"Slot:{Slot} - Login to meter failed!");
}
CommunicationConfig.RequestRetries = backupRetries;
@@ -1464,6 +1472,36 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
}
/// <summary>
/// The pulse module interrupts and disturbs the IrDA communication. As quick fix the pulse module can be switched off,
/// as soon as a communication could be established. As the pulse output will only be switched on again, if a pulse
/// module is attached to the device, this pulse mode can be switched active instantaneously after deactivation.
/// </summary>
/// <remarks date="2023-Feb-13" author="Roland Drabesch/Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private Boolean DeactivatePulseModule()
{
Boolean retVal;
try
{
var pulseMode = RegisterConverter.ConvertTo<Byte>(ReadRegister(Register.Mertrologyasst.PulseMode));
// if pulse mode is already set to 0 (OFF) return true
if (pulseMode == 0)
return true;
// write pulse mode temporary to 0 (OFF) and wait for result
retVal = WriteRegister(Register.Mertrologyasst.PulseMode, 0);
// instantaneously restore pulse mode to original value
retVal &= WriteRegister(Register.Mertrologyasst.PulseMode, pulseMode);
}
catch (Exception)
{
retVal = false;
}
return retVal;
}
/// <summary>
/// Automatic login to meter enabled if logged out by lost authentication
/// </summary>