private static void CalculateCheckSumCommand(object sender, EventArgs e) { if (htxtSendData.Length == 0) { return; } string[] reslut = CCommondMethod.StringToStringArray(htxtSendData.ToUpper(), 2); byte[] btArySendData = CCommondMethod.StringArrayToByteArray(reslut, reslut.Length); byte btCheckData = reader.CheckValue(btArySendData); htxtCheckData = string.Format(" {0:X2}", btCheckData); }
private static void ProcessSetWorkAntenna(MessageTran msgTran) { int intCurrentAnt = 0; intCurrentAnt = m_curSetting.btWorkAntenna + 1; string strCmd = "Set working antenna successfully, Current Ant: Ant" + intCurrentAnt.ToString(); string strErrorCode = string.Empty; if (msgTran.AryData.Length == 1) { if (msgTran.AryData[0] == 0x10) { m_curSetting.btReadId = msgTran.ReadId; Logger(strCmd); //Verify inventory operations if (m_bInventory) { RunLoopInventroy(); } return; } else { strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]); } } else { strErrorCode = "Unknown Error"; } string strLog = strCmd + "Failure, failure cause: " + strErrorCode; Logger(strLog); if (m_bInventory) { m_curInventoryBuffer.nCommond = 1; m_curInventoryBuffer.dtEndInventory = DateTime.Now; RunLoopInventroy(); } }
private static void ProcessInventoryReal(MessageTran msgTran) { string strCmd = ""; if (msgTran.Cmd == 0x89) { strCmd = "Real time inventory"; Logger(strCmd); } if (msgTran.Cmd == 0x8B) { strCmd = "User define Session and Inventoried Flag inventory"; Logger(strCmd); } string strErrorCode = string.Empty; Logger("Check This AryData.Length 1 OR 7 : " + msgTran.AryData.Length); if (msgTran.AryData.Length == 1) { strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]); string strLog = strCmd + "Failure, failure cause: " + strErrorCode; Logger(strLog); RefreshInventoryReal(0x00); RunLoopInventroy(); } else if (msgTran.AryData.Length == 7) { m_curInventoryBuffer.nReadRate = Convert.ToInt32(msgTran.AryData[1]) * 256 + Convert.ToInt32(msgTran.AryData[2]); m_curInventoryBuffer.nDataCount = Convert.ToInt32(msgTran.AryData[3]) * 256 * 256 * 256 + Convert.ToInt32(msgTran.AryData[4]) * 256 * 256 + Convert.ToInt32(msgTran.AryData[5]) * 256 + Convert.ToInt32(msgTran.AryData[6]); Logger(strCmd); RefreshInventoryReal(0x01); RunLoopInventroy(); } else { int nLength = msgTran.AryData.Length; int nEpcLength = nLength - 4; //Add inventory list //if (msgTran.AryData[3] == 0x00) //{ // MessageBox.Show(""); //} string strEPC = CCommondMethod.ByteArrayToString(msgTran.AryData, 3, nEpcLength); string strPC = CCommondMethod.ByteArrayToString(msgTran.AryData, 1, 2); string strRSSI = (msgTran.AryData[nLength - 1] & 0x7F).ToString(); SetMaxMinRSSI(Convert.ToInt32(msgTran.AryData[nLength - 1] & 0x7F)); byte btTemp = msgTran.AryData[0]; byte btAntId = (byte)((btTemp & 0x03) + 1); if ((msgTran.AryData[nLength - 1] & 0x80) != 0) { btAntId += 4; } m_curInventoryBuffer.nCurrentAnt = btAntId; string strAntId = btAntId.ToString(); byte btFreq = (byte)(btTemp >> 2); string strFreq = GetFreqString(btFreq); //DataRow row = m_curInventoryBuffer.dtTagDetailTable.NewRow(); //row[0] = strEPC; //row[1] = strRSSI; //row[2] = strAntId; //row[3] = strFreq; //m_curInventoryBuffer.dtTagDetailTable.Rows.Add(row); //m_curInventoryBuffer.dtTagDetailTable.AcceptChanges(); ////Add tag list //DataRow[] drsDetail = m_curInventoryBuffer.dtTagDetailTable.Select(string.Format("COLEPC = '{0}'", strEPC)); //int nDetailCount = drsDetail.Length; DataRow[] drs = m_curInventoryBuffer.dtTagTable.Select(string.Format("COLEPC = '{0}'", strEPC)); if (drs.Length == 0) { DataRow row1 = m_curInventoryBuffer.dtTagTable.NewRow(); row1[0] = strPC; row1[2] = strEPC; row1[4] = strRSSI; row1[5] = "1"; row1[6] = strFreq; m_curInventoryBuffer.dtTagTable.Rows.Add(row1); m_curInventoryBuffer.dtTagTable.AcceptChanges(); } else { foreach (DataRow dr in drs) { dr.BeginEdit(); dr[4] = strRSSI; dr[5] = (Convert.ToInt32(dr[5]) + 1).ToString(); dr[6] = strFreq; dr.EndEdit(); } m_curInventoryBuffer.dtTagTable.AcceptChanges(); } m_curInventoryBuffer.dtEndInventory = DateTime.Now; RefreshInventoryReal(0x89); } }
private static void Connect() { string strException = string.Empty; string strComPort = _Com_Port; int nBaudrate = Convert.ToInt32(_Boud_Rate); int nRet = reader.OpenCom(strComPort, nBaudrate, out strException); if (nRet != 0) { string strLog = "Connection failed, failure cause: " + strException; Logger(strLog); throw new Exception(strLog); } else { #region Set Function Default htxtSendData = "A0 04 FF A0 00"; CalculateCheckSumCommand(null, EventArgs.Empty); string SendCommandStr = htxtSendData + htxtCheckData; string[] reslut = CCommondMethod.StringToStringArray(SendCommandStr.ToUpper(), 2); byte[] btArySendData = CCommondMethod.StringArrayToByteArray(reslut, reslut.Length); reader.SendMessage(btArySendData); #endregion Set Function Default string strLog = "Connect" + strComPort + "@" + nBaudrate.ToString(); Logger(strLog); if (_Start_Read == "Start") { try { strLog = "Started to read tags"; Logger(strLog); m_curInventoryBuffer.ClearInventoryPar(); m_curInventoryBuffer.btRepeat = Convert.ToByte(repeatCommand); m_curInventoryBuffer.bLoopCustomizedSession = false; m_curInventoryBuffer.lAntenna.Add(0x00); m_curInventoryBuffer.lAntenna.Add(0x01); m_curInventoryBuffer.lAntenna.Add(0x02); m_curInventoryBuffer.lAntenna.Add(0x03); if (m_curInventoryBuffer.lAntenna.Count == 0) { Logger("One antenna must be selected"); } m_bInventory = true; m_curInventoryBuffer.bLoopInventory = true; m_curInventoryBuffer.bLoopInventoryReal = true; m_nTotal = 0; byte btWorkAntenna = m_curInventoryBuffer.lAntenna[m_curInventoryBuffer.nIndexAntenna]; reader.SetWorkAntenna(m_curSetting.btReadId, btWorkAntenna); m_curSetting.btWorkAntenna = btWorkAntenna; timerInventory.Enabled = true; timerInventory.Enabled = true; } catch (Exception ex) { Logger(ex.Message); } } } }