- Introduced simulation timers in `FlyingStartStopTestOp`. - Added `Simulate` methods in `WaterMetrologyData`, `WaterMetrologyDataC7`, and `WaterMetrologyDataC2`. - Enhanced `SmartCommunicationForm` with textbox resizing logic and initialization code. - Implemented flow rate and volume calculation from optohead telemetry in `SmartReader`. - Added unit tests for Poseidon correction parsing.
257 lines
9.4 KiB
C#
257 lines
9.4 KiB
C#
using System;
|
|
using Common;
|
|
using Config.Resources;
|
|
using log4net;
|
|
using Sensus.iPerl.RfidCom.Helper;
|
|
using TBF.Rig.RegisterReaders.CommonRR;
|
|
using TBF.Rig.RegisterReaders.PoseidonReader.communication.C7;
|
|
using TBF.Rig.RegisterReaders.PoseidonReader.communication.C7.Protocols;
|
|
using TBF.Rig.RegisterReaders.PoseidonReader.communication.C7.Utils;
|
|
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication;
|
|
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication.common;
|
|
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication.implementations;
|
|
using static Sensus.iPerl.NfcHandler.MCI_Protocol;
|
|
|
|
namespace TBF.Rig.RegisterReaders.PoseidonReader.communication
|
|
{
|
|
internal class OpticalHeadTest
|
|
{
|
|
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
|
|
|
|
DebugMode _debugMode;
|
|
public DebugMode DebugMode { get => _debugMode; set => _debugMode = value; }
|
|
|
|
internal static string OpenSealing(ISmartReader iHead)
|
|
{
|
|
if (RfidCommands.OpenSealing($"COM{iHead.RfidComPortNr}")) return "OK";
|
|
return "Error Open Sealing";
|
|
}
|
|
|
|
internal static string ReadRequest_SerialNo(PoseidonCfg iHeadCfg)
|
|
{
|
|
if (iHeadCfg != null && iHeadCfg.DebugLevel == DebugMode.Simulate)
|
|
{
|
|
return "1111";
|
|
}
|
|
|
|
string serialNo = null;
|
|
try
|
|
{
|
|
if (iHeadCfg != null)
|
|
{
|
|
// TODO BUMI set correct val !!!!!!!!
|
|
SerialPortData serialPortData = new SerialPortData(
|
|
$"COM{iHeadCfg.HeadCommunicationComPortNr}",
|
|
iHeadCfg.CliProgramName,
|
|
iHeadCfg.CliMeterType);
|
|
NfcHeadServiceOld headService = new NfcHeadServiceOld(serialPortData);
|
|
serialNo = headService.GetSerialNr();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}
|
|
|
|
|
|
return serialNo;
|
|
}
|
|
|
|
internal static string ReadRequest_SerialNoAsynch(PoseidonCfg iHeadCfg)
|
|
{
|
|
string serialNo = null;
|
|
try
|
|
{
|
|
if (iHeadCfg != null)
|
|
{
|
|
// TODO BUMI set correct val !!!!!!!!
|
|
SerialPortData serialPortData = new SerialPortData(
|
|
$"COM{iHeadCfg.HeadCommunicationComPortNr}",
|
|
iHeadCfg.CliProgramName,
|
|
iHeadCfg.CliMeterType);
|
|
NfcHeadService headService = new NfcHeadService(serialPortData);
|
|
// Wait synchronously
|
|
serialNo = headService.GetSerialNrAsync().GetAwaiter().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}
|
|
|
|
|
|
return serialNo;
|
|
}
|
|
|
|
internal static string SetActiveMode(PoseidonCfg iHeadCfg)
|
|
{
|
|
if (iHeadCfg != null && iHeadCfg.DebugLevel == DebugMode.Simulate)
|
|
{
|
|
return "OK";
|
|
}
|
|
|
|
SerialPortData serialPortData = new SerialPortData(
|
|
$"COM{iHeadCfg.RfidComPortNr}",
|
|
iHeadCfg.CliProgramName,
|
|
iHeadCfg.CliMeterType);
|
|
NfcHeadServiceOld headService = new NfcHeadServiceOld(serialPortData);
|
|
// Wait synchronously
|
|
OptoHeadStatus optoHeadStatus = headService.SetTestingMode(OptoHeadStatus.OptoHeadDisabled);
|
|
if (optoHeadStatus == OptoHeadStatus.OptoHeadDisabled)
|
|
{
|
|
_lastOptoHeadStatus = optoHeadStatus;
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
return "Error Set Test Mode";
|
|
}
|
|
}
|
|
|
|
private static OptoHeadStatus _lastOptoHeadStatus = OptoHeadStatus.Unknown;
|
|
private static PoseidonCfg _lastIHeadCfg;
|
|
|
|
internal static string SetTestMode(PoseidonCfg iHeadCfg)
|
|
{
|
|
if (iHeadCfg != null && iHeadCfg.DebugLevel == DebugMode.Simulate)
|
|
{
|
|
return "OK";
|
|
}
|
|
|
|
SerialPortData serialPortData = new SerialPortData(
|
|
$"COM{iHeadCfg.RfidComPortNr}",
|
|
iHeadCfg.CliProgramName,
|
|
iHeadCfg.CliMeterType);
|
|
NfcHeadServiceOld headService = new NfcHeadServiceOld(serialPortData);
|
|
// Wait synchronously
|
|
OptoHeadStatus optoHeadStatus = headService.SetTestingMode(OptoHeadStatus.OptoHeadC7);
|
|
if (optoHeadStatus == OptoHeadStatus.OptoHeadC7)
|
|
{
|
|
_lastOptoHeadStatus = optoHeadStatus;
|
|
_lastIHeadCfg = iHeadCfg;
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
return "Error Set Test Mode";
|
|
}
|
|
}
|
|
|
|
private static OptoHeadService optoHeadService;
|
|
|
|
public static void Deactivate()
|
|
{
|
|
if (_lastIHeadCfg != null && _lastIHeadCfg.DebugLevel == DebugMode.Simulate)
|
|
{
|
|
return;
|
|
}
|
|
StopOptoTestInputLoop();
|
|
if (_lastOptoHeadStatus != OptoHeadStatus.Unknown &&
|
|
_lastOptoHeadStatus != OptoHeadStatus.OptoHeadDisabled &&
|
|
_lastIHeadCfg != null
|
|
)
|
|
{
|
|
SetActiveMode(_lastIHeadCfg);
|
|
}
|
|
}
|
|
|
|
public static bool StartOptotestInputLoop(PoseidonCfg iHeadCfg,
|
|
EventHandler<CommonRR.IPerl.communication.OptoReceivedEventArgs> onOptoReceivedHandler)
|
|
{
|
|
try
|
|
{
|
|
if (iHeadCfg != null)
|
|
{
|
|
if (optoHeadService != null) return false;
|
|
|
|
OptoHeadService.Con connection = new OptoHeadService.Con($"COM{iHeadCfg.OptoComPortNr}", iHeadCfg.DebugLevel);
|
|
optoHeadService = new OptoHeadService(connection);
|
|
optoHeadService.CreateSerialConnection();
|
|
optoHeadService.RunLoop(onOptoReceivedHandler);
|
|
//run loop runstate = true;
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static void StopOptoTestInputLoop()
|
|
{
|
|
try
|
|
{
|
|
optoHeadService?.CloseSerialConnection();
|
|
}
|
|
finally
|
|
{
|
|
optoHeadService = null;
|
|
}
|
|
}
|
|
|
|
#if IPERL
|
|
internal static string TurnOffRadio(ISmartReader iHead)
|
|
{
|
|
try
|
|
{
|
|
int retValue = IPerlCorrections.WriteRequestPort(SmartCommunicationForm.TestMethodCfg, iHead, MessageID.RadioPassthrough, StructName.RadioParams, 0x1898, 1, new byte[] { (byte)3 }); // WakeUpInterval
|
|
return 0 == retValue ? "OK" : "Error";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}
|
|
}
|
|
|
|
internal static string SetProductionMode(ISmartReader iHead)
|
|
{
|
|
try
|
|
{
|
|
int retValue = IPerlCorrections.WriteRequestPort(SmartCommunicationForm.TestMethodCfg, iHead, MessageID.RadioPassthrough, StructName.RadioInfo, 0x1804, 1, new byte[] { (byte)1 }); // System Status
|
|
return 0 == retValue ? "OK" : "Error";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}
|
|
}
|
|
|
|
internal static string WriteRequestPort_u8_Customer_Text(ISmartReader iHead)
|
|
{
|
|
string custText = "FF0123456789ABCDEF"; // Sample text to test write function
|
|
/*try
|
|
{
|
|
byte[] cmd = RfidHelper.HexStringToByteArray(custText);
|
|
if (0 == iPerlCommunicationForm.WriteRequestPort(iHead, MessageID.RadioPassthrough, Sensus.iPerl.NfcHandler.MCI_Protocol.StructName.RadioParams, 0x1899, 9, cmd))
|
|
{
|
|
RfidCommunicationService rfidCommunicationService = new RfidCommunicationService { ComPort = $"COM{iHead.RfidComPortNr}", WaitTimeAfterFailure = 2200, PassThroughWaitTime = 1500, MaxRetries = 3, TimeOut = 5000 };
|
|
//rfidCommunicationService.RfidWrite(Params.u8_Customer_Text, custText);
|
|
return rfidCommunicationService.RfidRead<string>(Params.u8_Customer_Text).ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}*/
|
|
return $"Error COM{iHead.RfidComPortNr}";
|
|
}
|
|
|
|
internal static string SetTouchedMode(ISmartReader iHead)
|
|
{
|
|
iHead.SetRfidInterface();
|
|
iHead.SetCommunicationInterface(ECommunicationInterface.Touched.ToDescription());
|
|
return ($"OK - {Strings.Program_restart_is_required_to_apply_some_settings}");
|
|
}
|
|
|
|
internal static string SetNfcMode(ISmartReader iHead)
|
|
{
|
|
iHead.SetNfcInterface();
|
|
iHead.SetCommunicationInterface(ECommunicationInterface.Nfc.ToDescription());
|
|
return ($"OK - {Strings.Program_restart_is_required_to_apply_some_settings}");
|
|
}
|
|
#endif /// IPERL
|
|
}
|
|
}
|