117 lines
4.4 KiB
C#
117 lines
4.4 KiB
C#
using log4net;
|
|
using Sensus.iPerl.RfidCom.Helper;
|
|
using Sensus.iPerl.RfidCom.Services;
|
|
using Sensus.iPerl.RfidCom.Structures;
|
|
using System;
|
|
using System.Threading;
|
|
using TBF.Rig.Hart.Common;
|
|
using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead;
|
|
using static Sensus.iPerl.NfcHandler.MCI_Protocol;
|
|
|
|
namespace TBF.Rig.TestMethods.iPerlCommunication
|
|
{
|
|
internal class OpticalHeadTest
|
|
{
|
|
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
|
|
|
|
internal static string OpenSealing(IperlHead iHead)
|
|
{
|
|
if (RfidCommands.OpenSealing($"COM{iHead.RfidComPortNr}")) return "OK";
|
|
return "Error Open Sealing";
|
|
}
|
|
|
|
internal static string ReadRequest_PCB(IperlHead iHead)
|
|
{
|
|
try
|
|
{
|
|
byte[] pcb = null;
|
|
int readRetVal = iPerlCommunicationForm.ReadRequestPort(iHead, MessageID.Configuration, Sensus.iPerl.NfcHandler.MCI_Protocol.StructName.Configuration, 16, 5, out pcb);
|
|
if (readRetVal == 0)
|
|
{
|
|
return RfidHelper.HexLiteral2Unsigned(RfidHelper.SwapHexcode(BitConverter.ToString(pcb).Replace("-", string.Empty))).ToString();
|
|
}
|
|
rfidDataLogger.Error($"COM{iHead.RfidComPortNr}: ReadRequest_PCB ({MessageID.Configuration},16,5...) <- Error: {readRetVal}");
|
|
return "Error";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}
|
|
}
|
|
|
|
internal static string SetActiveMode(IperlHead iHead)
|
|
{
|
|
byte[] cmd = new byte[1] { (byte)Command.SetActiveMode };
|
|
if (0 == iPerlCommunicationForm.WriteRequestPort(iHead, MessageID.Command, StructName.Command, 0, 1, cmd))
|
|
{
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
return "Error Set Active Mode";
|
|
}
|
|
}
|
|
|
|
internal static string SetTestMode(IperlHead iHead)
|
|
{
|
|
byte[] cmd = new byte[1] { (byte)Command.SetTestMode };
|
|
if (0 == iPerlCommunicationForm.WriteRequestPort(iHead, MessageID.Command, StructName.Command, 0, 1, cmd))
|
|
{
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
return "Error Set Test Mode";
|
|
}
|
|
}
|
|
|
|
#if IPERL
|
|
internal static string TurnOffRadio(IperlHead iHead)
|
|
{
|
|
try
|
|
{
|
|
int retValue = iPerlCommunicationForm.WriteRequestPort(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(IperlHead iHead)
|
|
{
|
|
try
|
|
{
|
|
int retValue = iPerlCommunicationForm.WriteRequestPort(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(IperlHead 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}";
|
|
}
|
|
#endif /// IPERL
|
|
}
|
|
}
|