diff --git a/MaterialTraceability.Rfid/Impl/RFly_I160Adapter.cs b/MaterialTraceability.Rfid/Impl/RFly_I160Adapter.cs index 2234fa0..aa2e490 100644 --- a/MaterialTraceability.Rfid/Impl/RFly_I160Adapter.cs +++ b/MaterialTraceability.Rfid/Impl/RFly_I160Adapter.cs @@ -948,85 +948,83 @@ namespace MaterialTraceability.Rfid.Impl public List Device_DealTagInfoList2(byte[] AutoDealReportData) { List tagInfoList = new List(); - byte[] bResultEPC_Data = new byte[14]; - m_AutoReadEPC = null; - m_readEPCDataLen = 0; + byte[] numArray1 = new byte[14]; + this.m_AutoReadEPC = (byte[])null; + this.m_readEPCDataLen = 0; try { - mutauto.WaitOne(); - int iFirstCountPos = 6; //第一次读取标签次数位置 - int iFirstRSSIPos = 7; //第一次读取标签强度位置 - int iFirstAnt = 8; - int iFirstPC = 9; //第一次读取标签天线位置 - int iFirstLeftBarcketPos = 11;//EPC数据起始位置 - UInt16 tempDataCount = 0; - int tempDataRSSI = 0; - UInt16 tempDataANT = 0; - int iBarcodeGroupCount = Convert.ToInt32(AutoDealReportData[5].ToString()); //标签组数 - int iBarcodeLength = 16; //标签长度 - int iCommonSecondFlag = 0; - for (int j = 0; j < iBarcodeGroupCount; j++) + this.mutauto.WaitOne(); + int sourceIndex1 = 6; + int sourceIndex2 = 7; + int sourceIndex3 = 8; + int sourceIndex4 = 9; + int sourceIndex5 = 11; + int int32_1 = Convert.ToInt32(AutoDealReportData[5].ToString()); + int num1 = 0; + for (int index1 = 0; index1 < int32_1; ++index1) { - TagInfo tag = new TagInfo(); - byte[] tempPCByte = new byte[2]; //取出PC - Array.Clear(tempPCByte, 0, 2); - Array.Copy(AutoDealReportData, iFirstPC, tempPCByte, 0, 2); - - int pc = Convert.ToInt32(tempPCByte[0].ToString("X")); - int epcLength = EPCLengthByPC(pc); - iBarcodeLength = epcLength; - - byte[] tempDataByte = new byte[epcLength]; - Array.Clear(tempDataByte, 0, iBarcodeLength); - Array.Copy(AutoDealReportData, iFirstLeftBarcketPos, tempDataByte, 0, iBarcodeLength); - - byte[] tempCountByte = new byte[1]; //取出标签次数 - Array.Clear(tempCountByte, 0, 1); - Array.Copy(AutoDealReportData, iFirstCountPos, tempCountByte, 0, 1); - tempDataCount = tempCountByte[0]; - - byte[] tempRSSIByte = new byte[1]; //取出标签强度 - Array.Clear(tempRSSIByte, 0, 1); - Array.Copy(AutoDealReportData, iFirstRSSIPos, tempRSSIByte, 0, 1); - - tempDataRSSI = StringChange.HexStringToNegative(StringChange.bytesToHexStr(tempRSSIByte, 1)); - - #region add by wenjy 20220829 取出天线号 - byte[] tempAntByte = new byte[1]; //取出天线号 - Array.Clear(tempAntByte, 0, 1); - Array.Copy(AutoDealReportData, iFirstAnt, tempAntByte, 0, 1); - tempDataANT = tempAntByte[0]; - #endregion - - tag.Count = tempDataCount; - tag.RSSI = tempDataRSSI; - tag.EPC = tempDataByte; - - if (pc == 24) + TagInfo tagInfo = new TagInfo(); + byte[] destinationArray1 = new byte[2]; + Array.Clear((Array)destinationArray1, 0, 2); + Array.Copy((Array)AutoDealReportData, sourceIndex4, (Array)destinationArray1, 0, 2); + int int32_2 = Convert.ToInt32(destinationArray1[0].ToString("X")); + int length1 = this.EPCLengthByPC(int32_2); + int length2 = length1; + byte[] numArray2 = new byte[length1]; + Array.Clear((Array)numArray2, 0, length2); + Array.Copy((Array)AutoDealReportData, sourceIndex5, (Array)numArray2, 0, length2); + byte[] destinationArray2 = new byte[1]; + Array.Clear((Array)destinationArray2, 0, 1); + Array.Copy((Array)AutoDealReportData, sourceIndex1, (Array)destinationArray2, 0, 1); + ushort num2 = (ushort)destinationArray2[0]; + byte[] destinationArray3 = new byte[1]; + Array.Clear((Array)destinationArray3, 0, 1); + Array.Copy((Array)AutoDealReportData, sourceIndex2, (Array)destinationArray3, 0, 1); + int negative = StringChange.HexStringToNegative(StringChange.bytesToHexStr(destinationArray3, 1)); + byte[] destinationArray4 = new byte[1]; + Array.Clear((Array)destinationArray4, 0, 1); + Array.Copy((Array)AutoDealReportData, sourceIndex3, (Array)destinationArray4, 0, 1); + ushort num3 = (ushort)destinationArray4[0]; + tagInfo.Count = (int)num2; + tagInfo.RSSI = negative; + tagInfo.EPC = numArray2; + if (int32_2 == 44) { - tag.EPCstring = StringChange.bytesToHexStr(tempDataByte, tempDataByte.Length).Substring(0, 7); + tagInfo.EPCstring = Encoding.ASCII.GetString(numArray2); } else { - tag.EPCstring = System.Text.Encoding.ASCII.GetString(tempDataByte); + tagInfo.EPCstring = StringChange.bytesToHexStr(numArray2, numArray2.Length); + char[] chArray = new char[5]; + for (int index2 = 0; index2 < 5; ++index2) + { + if (numArray2[index2] >= (byte)0 && numArray2[index2] <= (byte)127) + { + chArray[index2] = Convert.ToChar(numArray2[index2]); + } + else + { + Console.WriteLine(string.Format("警告: 数值 {0} 不在ASCII码范围内。", (object)numArray2[index2])); + chArray[index2] = '?'; + } + } + string str = new string(chArray) + tagInfo.EPCstring.Substring(10, tagInfo.EPCstring.Length - 10); + tagInfo.EPCstring = str.Replace('F', ' ').Trim() + "00"; } - - tag.PC = tempPCByte; - tag.Antana = tempDataANT; - tagInfoList.Add(tag); - int iBarcodeListLen = tagInfoList.Count; //特别注意,必须这样,要不然会多一条数据 - - iFirstCountPos = iFirstCountPos + iBarcodeLength + 5; //次数 - iFirstRSSIPos = iFirstCountPos + 1; //强度 - iFirstAnt = iFirstRSSIPos + 1; //天线 - iFirstPC = iFirstAnt + 1; - iFirstLeftBarcketPos = iFirstLeftBarcketPos + iBarcodeLength + 5; - - LogHelper.RfidLog("----函数调用:Device_DealTagInfoList2 第[" + (iCommonSecondFlag + 1) + "]次数据解析为:" + tag.EPCstring + ",读取标签次数:[" + tempDataCount + "],标签信号强度:[" + tempDataRSSI + "],天线号:[" + tempDataANT + "]"); - iCommonSecondFlag++; - if (iCommonSecondFlag == iBarcodeGroupCount) + tagInfo.PC = destinationArray1; + tagInfo.Antana = (int)num3; + tagInfoList.Add(tagInfo); + int count = tagInfoList.Count; + sourceIndex1 = sourceIndex1 + length2 + 5; + sourceIndex2 = sourceIndex1 + 1; + sourceIndex3 = sourceIndex2 + 1; + sourceIndex4 = sourceIndex3 + 1; + sourceIndex5 = sourceIndex5 + length2 + 5; + LogHelper.RfidLog("----函数调用:Device_DealTagInfoList2 第[" + (num1 + 1).ToString() + "]次数据解析为:" + tagInfo.EPCstring + ",读取标签次数:[" + num2.ToString() + "],标签信号强度:[" + negative.ToString() + "],天线号:[" + num3.ToString() + "]"); + ++num1; + if (num1 == int32_1) { - mutauto.ReleaseMutex(); + this.mutauto.ReleaseMutex(); LogHelper.RfidLog("《《《返回标签数据!"); return tagInfoList; } @@ -1035,47 +1033,31 @@ namespace MaterialTraceability.Rfid.Impl catch (Exception ex) { LogHelper.RfidLog("----函数调用:Device_AutoDealContent 自动处理函数异常:" + ex.ToString()); - mutauto.ReleaseMutex(); + this.mutauto.ReleaseMutex(); } return tagInfoList; } private int EPCLengthByPC(int pcValue) { - int epcLength = 0; + int num = 0; if (pcValue >= 10 && pcValue < 20) - { - epcLength = 4; - } + num = 4; else if (pcValue >= 20 && pcValue < 30) - { - epcLength = 8; - } + num = 8; else if (pcValue >= 30 && pcValue < 40) - { - epcLength = 12; - } + num = 12; else if (pcValue >= 40 && pcValue < 50) - { - epcLength = 16; - } + num = 16; else if (pcValue >= 50 && pcValue < 60) - { - epcLength = 20; - } + num = 20; else if (pcValue >= 60 && pcValue < 70) - { - epcLength = 24; - } + num = 24; else if (pcValue >= 70 && pcValue < 80) - { - epcLength = 28; - } + num = 28; else if (pcValue >= 80 && pcValue < 90) - { - epcLength = 30; - } - return epcLength; + num = 30; + return num; } /// diff --git a/MaterialTraceabilityUI/App.config b/MaterialTraceabilityUI/App.config index 5618eb9..8b233dd 100644 --- a/MaterialTraceabilityUI/App.config +++ b/MaterialTraceabilityUI/App.config @@ -40,7 +40,7 @@ - +