Refactor `NfcHanler` namespace to `NfcHandler` and enhance code consistency.
70 lines
2.5 KiB
C#
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);
|
|
}
|
|
} |