using Config.Resources; 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(Params.u8_Customer_Text).ToString(); } } catch (Exception ex) { return (ex.Message.ToString()); }*/ return $"Error COM{iHead.RfidComPortNr}"; } internal static string SetRfidMode(IperlHead iHead) { iHead.SetRfidInterface(); iHead.SetCommunicationInterface(CommunicationInterface.RFID); return ($"OK - {Strings.Program_restart_is_required_to_apply_some_settings}"); } internal static string SetNfcMode(IperlHead iHead) { iHead.SetNfcInterface(); iHead.SetCommunicationInterface(CommunicationInterface.NFC); return ($"OK - {Strings.Program_restart_is_required_to_apply_some_settings}"); } #endif /// IPERL } }