98 lines
4.1 KiB
C#
98 lines
4.1 KiB
C#
using Sensus.iPerl.RfidCom.Helper;
|
|
using Sensus.iPerl.RfidCom.Services;
|
|
using Sensus.iPerl.RfidCom.Structures;
|
|
using System;
|
|
using System.Threading;
|
|
using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead;
|
|
|
|
namespace TBF.Rig.TestMethods.iPerlCommunication
|
|
{
|
|
internal class OpticalHeadTest
|
|
{
|
|
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, 16, 5, out pcb);
|
|
if (readRetVal == 0)
|
|
{
|
|
return RfidHelper.HexLiteral2Unsigned(RfidHelper.SwapHexcode(BitConverter.ToString(pcb).Replace("-", string.Empty))).ToString();
|
|
}
|
|
return "Error";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}
|
|
}
|
|
|
|
internal static string SetActiveMode(IperlHead iHead)
|
|
{
|
|
return RfidCommands.SetActiveMode($"COM{iHead.RfidComPortNr}") ? "OK" : "Error Set Active Mode";
|
|
}
|
|
|
|
internal static string SetTestMode(IperlHead iHead)
|
|
{
|
|
return RfidCommands.SetTestMode($"COM{iHead.RfidComPortNr}") ? "OK" : "Error Set Test Mode";
|
|
}
|
|
|
|
internal static string TurnOffRadio(IperlHead iHead)
|
|
{
|
|
try
|
|
{
|
|
string payload = "03";
|
|
RfidCommunicationService rfidCommunicationService = new RfidCommunicationService { ComPort = $"COM{iHead.RfidComPortNr}", WaitTimeAfterFailure = 2200, PassThroughWaitTime = 1500, MaxRetries = 3, TimeOut = 5000 };
|
|
rfidCommunicationService.RfidWrite(Params.u8_WakeUpInterval, payload);
|
|
return rfidCommunicationService.RfidRead(Params.u8_WakeUpInterval).ToString() == payload? "OK" : "Error";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return (ex.Message.ToString());
|
|
}
|
|
}
|
|
|
|
internal static string SetProductionMode(IperlHead iHead)
|
|
{
|
|
try
|
|
{
|
|
string payload = "01"; // 1 set the µC to the production mode, radio should not start
|
|
RfidCommunicationService rfidCommunicationService = new RfidCommunicationService { ComPort = $"COM{iHead.RfidComPortNr}", WaitTimeAfterFailure = 2200, PassThroughWaitTime = 1500, MaxRetries = 3, TimeOut = 5000 };
|
|
rfidCommunicationService.RfidWrite(SystemInfo.u8_system_state, payload);
|
|
Thread.Sleep(1000); // must be for pass thru params
|
|
return rfidCommunicationService.RfidRead(SystemInfo.u8_system_state).ToString() == payload ? "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, 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}";
|
|
}
|
|
}
|
|
}
|