tbf/NfcC7_DLL.Tests/NfcHanler/OptoHeadServiceTest.cs
Michal Buzik 320cddb177 compatible version to TBF
Refactor `NfcHanler` namespace to `NfcHandler` and enhance code consistency.
2025-10-29 16:05:21 +01:00

70 lines
2.5 KiB
C#

using JetBrains.Annotations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NfcC7_DLL.NfcHandler;
using NfcC7_DLL.NfcHandler.Protocols;
using NfcC7_DLL.NfcHandler.Utils;
namespace NfcC7_DLL.Tests.NfcHanler;
[TestClass]
[TestSubject(typeof(OptoHeadService))]
public class OptoHeadServiceTest
{
[TestMethod]
public void RunLoop_Test()
{
//Switch meter to Optohead C7 testing mode
SerialPortData serialPortData = new SerialPortData(
"COM5",
"HatCliDemo.exe",
74);
NfcHeadService service = new NfcHeadService(serialPortData);
OptoHeadStatus status = service.SetTestingMode(OptoHeadStatus.OptoHeadC7);
Assert.AreEqual(OptoHeadStatus.OptoHeadC7, status);
//Open serial connection to Optohead
OptoHeadService.Con con = new OptoHeadService.Con();
con.com = "COM6";
OptoHeadService optoHeadService = new OptoHeadService(con);
Assert.IsTrue(optoHeadService.CreateSerialConnection());
//start loop to receive data
optoHeadService.RunLoop();
WaterMetrologyData lastData = null;
int iCycles = 0, iCyclesMax = 10;
for (int i = 0; i < iCyclesMax; i++)
{
bool finished = false;
while (!finished)
{
//optoHeadService.Run();
if (optoHeadService.WaterMetrologyData != null
&& lastData != optoHeadService.WaterMetrologyData
&& optoHeadService.WaterMetrologyData.OptoHeadStatus != OptoHeadStatus.Unknown)
{
lastData = optoHeadService.WaterMetrologyData;
finished = true;
iCycles++;
if (lastData.OptoHeadStatus.HasFlag(OptoHeadStatus.OptoHeadC7))
{
Assert.IsNotNull(lastData.C7Data);
}
else
{
Assert.IsNotNull(lastData.C2Data);
}
System.Console.WriteLine("Cycle: {0} lastData: {1}", iCycles, lastData);
}
}
}
optoHeadService.CloseSerialConnection();
Assert.IsTrue(iCycles > 0);
Assert.IsTrue(iCycles == iCyclesMax);
//Close Optohead
status = service.SetTestingMode(OptoHeadStatus.OptoHeadDisabled);
Assert.AreEqual(OptoHeadStatus.OptoHeadDisabled, status);
}
}