示例#1
0
 private void AnalyData(Reader.MessageTran msgTran)
 {
     if (msgTran.PacketType != 0xA0)
     {
         return;
     }
 }
示例#2
0
        private int SendMessage(byte btReadId, byte btCmd, byte[] btAryData)
        {
            MessageTran msgTran = new MessageTran(btReadId, btCmd, btAryData);



            return(SendMessage(msgTran.AryTranData));
        }
示例#3
0
        private void ProcessSetWorkAntenna(Reader.MessageTran msgTran)
        {
            int intCurrentAnt = 0;

            intCurrentAnt = m_curSetting.btWorkAntenna + 1;
            string strCmd = "Successfully set working antenna, current working antenna : Ant " + intCurrentAnt.ToString();

            string strErrorCode = string.Empty;

            if (msgTran.AryData.Length == 1)
            {
                if (msgTran.AryData[0] == 0x10)
                {
                    m_curSetting.btReadId = msgTran.ReadId;
                    //WriteLog(lrtxtLog, strCmd, 0);

                    //校验是否盘存操作
                    if (m_bInventory)
                    {
                        RunLoopInventroy();
                    }
                    return;
                }
                else
                {
                    strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]);
                }
            }
            else
            {
                strErrorCode = "Unknown error";
            }

            string strLog = strCmd + "failed , due to: " + strErrorCode;

            //WriteLog(lrtxtLog, strLog, 1);

            if (m_bInventory)
            {
                m_curInventoryBuffer.nCommond       = 1;
                m_curInventoryBuffer.dtEndInventory = DateTime.Now;
                RunLoopInventroy();
            }
        }
示例#4
0
        private void ProcessGetFrequencyRegion(Reader.MessageTran msgTran)
        {
            string strCmd       = "Get RF spectrum ";
            string strErrorCode = string.Empty;

            if (msgTran.AryData.Length == 3)
            {
                m_curSetting.btReadId         = msgTran.ReadId;
                m_curSetting.btRegion         = msgTran.AryData[0];
                m_curSetting.btFrequencyStart = msgTran.AryData[1];
                m_curSetting.btFrequencyEnd   = msgTran.AryData[2];

                //RefreshReadSetting(0x79);
                //WriteLog(lrtxtLog, strCmd, 0);
                return;
            }
            else if (msgTran.AryData.Length == 6)
            {
                m_curSetting.btReadId = msgTran.ReadId;
                m_curSetting.btRegion = msgTran.AryData[0];
                m_curSetting.btUserDefineFrequencyInterval = msgTran.AryData[1];
                m_curSetting.btUserDefineChannelQuantity   = msgTran.AryData[2];
                m_curSetting.nUserDefineStartFrequency     = msgTran.AryData[3] * 256 * 256 + msgTran.AryData[4] * 256 + msgTran.AryData[5];
                //RefreshReadSetting(0x79);
                //WriteLog(lrtxtLog, strCmd, 0);
                return;
            }
            else if (msgTran.AryData.Length == 1)
            {
                strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]);
            }
            else
            {
                strErrorCode = "Unknown error";
            }

            string strLog = strCmd + "failed , due to: " + strErrorCode;
            //WriteLog(lrtxtLog, strLog, 1);
        }
示例#5
0
        private int SendMessage(byte btReadId, byte btCmd, byte[] btAryData)
        {
            MessageTran msgTran = new MessageTran(btReadId, btCmd, btAryData);

            return SendMessage(msgTran.AryTranData);
        }
示例#6
0
        private void RunReceiveDataCallback(byte[] btAryReceiveData)
        {
            try
            {
                if (ReceiveCallback != null)
                {
                    ReceiveCallback(btAryReceiveData);
                }

                int nCount = btAryReceiveData.Length;
                byte[] btAryBuffer = new byte[nCount + m_nLenth];
                Array.Copy(m_btAryBuffer, btAryBuffer, m_nLenth);
                Array.Copy(btAryReceiveData, 0, btAryBuffer, m_nLenth, btAryReceiveData.Length);

                //分析接收数据,以0xA0为数据起点,以协议中数据长度为数据终止点
                int nIndex = 0;//当数据中存在A0时,记录数据的终止点
                int nMarkIndex = 0;//当数据中不存在A0时,nMarkIndex等于数据组最大索引
                for (int nLoop = 0; nLoop < btAryBuffer.Length; nLoop++)
                {
                    if (btAryBuffer.Length > nLoop + 1)
                    {
                        if (btAryBuffer[nLoop] == 0xA0)
                        {
                            int nLen = Convert.ToInt32(btAryBuffer[nLoop + 1]);
                            if (nLoop + 1 + nLen < btAryBuffer.Length)
                            {
                                byte[] btAryAnaly = new byte[nLen + 2];
                                Array.Copy(btAryBuffer, nLoop, btAryAnaly, 0, nLen + 2);

                                MessageTran msgTran = new MessageTran(btAryAnaly);
                                if (AnalyCallback != null)
                                {
                                    AnalyCallback(msgTran);
                                }

                                nLoop += 1 + nLen;
                                nIndex = nLoop + 1;
                            }
                            else
                            {
                                nLoop += 1 + nLen;
                            }
                        }
                        else
                        {
                            nMarkIndex = nLoop;
                        }
                    }
                }

                if (nIndex < nMarkIndex)
                {
                    nIndex = nMarkIndex + 1;
                }

                if (nIndex < btAryBuffer.Length)
                {
                    m_nLenth = btAryBuffer.Length - nIndex;
                    Array.Clear(m_btAryBuffer, 0, 4096);
                    Array.Copy(btAryBuffer, nIndex, m_btAryBuffer, 0, btAryBuffer.Length - nIndex);
                }
                else
                {
                    m_nLenth = 0;
                }
            }
            catch (System.Exception ex)
            {
                string err = ex.Message;
            }
        }
示例#7
0
        public byte CheckValue(byte[] btAryData)
        {
            MessageTran msgTran = new MessageTran();

            return msgTran.CheckSum(btAryData, 0, btAryData.Length);
        }
        public byte CheckValue(byte[] btAryData)
        {
            MessageTran msgTran = new MessageTran();

            return(msgTran.CheckSum(btAryData, 0, btAryData.Length));
        }
        private void RunReceiveDataCallback(byte[] btAryReceiveData)
        {
            try
            {
                if (ReceiveCallback != null)
                {
                    ReceiveCallback(btAryReceiveData);
                }

                int    nCount      = btAryReceiveData.Length;
                byte[] btAryBuffer = new byte[nCount + m_nLenth];
                Array.Copy(m_btAryBuffer, btAryBuffer, m_nLenth);
                Array.Copy(btAryReceiveData, 0, btAryBuffer, m_nLenth, btAryReceiveData.Length);

                int nIndex     = 0;
                int nMarkIndex = 0;
                for (int nLoop = 0; nLoop < btAryBuffer.Length; nLoop++)
                {
                    if (btAryBuffer.Length > nLoop + 1)
                    {
                        if (btAryBuffer[nLoop] == 0xA0)
                        {
                            int nLen = Convert.ToInt32(btAryBuffer[nLoop + 1]);
                            if (nLoop + 1 + nLen < btAryBuffer.Length)
                            {
                                byte[] btAryAnaly = new byte[nLen + 2];
                                Array.Copy(btAryBuffer, nLoop, btAryAnaly, 0, nLen + 2);

                                MessageTran msgTran = new MessageTran(btAryAnaly);
                                if (AnalyCallback != null)
                                {
                                    AnalyCallback(msgTran);
                                }

                                nLoop += 1 + nLen;
                                nIndex = nLoop + 1;
                            }
                            else
                            {
                                nLoop += 1 + nLen;
                            }
                        }
                        else
                        {
                            nMarkIndex = nLoop;
                        }
                    }
                }

                if (nIndex < nMarkIndex)
                {
                    nIndex = nMarkIndex + 1;
                }

                if (nIndex < btAryBuffer.Length)
                {
                    m_nLenth = btAryBuffer.Length - nIndex;
                    Array.Clear(m_btAryBuffer, 0, 4096 * 10);
                    Array.Copy(btAryBuffer, nIndex, m_btAryBuffer, 0, btAryBuffer.Length - nIndex);
                }
                else
                {
                    m_nLenth = 0;
                }
            }
            catch (System.Exception ex)
            {
            }
        }
示例#10
0
        private void RunReceiveDataCallback(byte[] btAryReceiveData)
        {
            try
            {
                if (ReceiveCallback != null)
                {
                    ReceiveCallback(btAryReceiveData);
                }

                int    nCount      = btAryReceiveData.Length;
                byte[] btAryBuffer = new byte[nCount + m_nLenth];
                Array.Copy(m_btAryBuffer, btAryBuffer, m_nLenth);
                Array.Copy(btAryReceiveData, 0, btAryBuffer, m_nLenth, btAryReceiveData.Length);

                //Analyze received data, with 0xA0 as starting point,with data length in protocol as end point
                int nIndex     = 0; //Record data end point when there is AO
                int nMarkIndex = 0; //When there is not AO, nMarkIndex equals to data sets maximum index
                for (int nLoop = 0; nLoop < btAryBuffer.Length; nLoop++)
                {
                    if (btAryBuffer.Length > nLoop + 1)
                    {
                        if (btAryBuffer[nLoop] == 0xA0)
                        {
                            int nLen = Convert.ToInt32(btAryBuffer[nLoop + 1]);
                            if (nLoop + 1 + nLen < btAryBuffer.Length)
                            {
                                byte[] btAryAnaly = new byte[nLen + 2];
                                Array.Copy(btAryBuffer, nLoop, btAryAnaly, 0, nLen + 2);

                                MessageTran msgTran = new MessageTran(btAryAnaly);
                                if (AnalyCallback != null)
                                {
                                    AnalyCallback(msgTran);
                                }

                                nLoop += 1 + nLen;
                                nIndex = nLoop + 1;
                            }
                            else
                            {
                                nLoop += 1 + nLen;
                            }
                        }
                        else
                        {
                            nMarkIndex = nLoop;
                        }
                    }
                }

                if (nIndex < nMarkIndex)
                {
                    nIndex = nMarkIndex + 1;
                }

                if (nIndex < btAryBuffer.Length)
                {
                    m_nLenth = btAryBuffer.Length - nIndex;
                    Array.Clear(m_btAryBuffer, 0, 4096);
                    Array.Copy(btAryBuffer, nIndex, m_btAryBuffer, 0, btAryBuffer.Length - nIndex);
                }
                else
                {
                    m_nLenth = 0;
                }
            }
            catch (System.Exception ex)
            {
            }
        }
示例#11
0
        private void ProcessInventoryReal(Reader.MessageTran msgTran)
        {
            string strCmd = "";

            if (msgTran.Cmd == 0x89)
            {
                strCmd = "Real time mode inventory ";
            }
            if (msgTran.Cmd == 0x8B)
            {
                strCmd = "Customized Session and Inventoried Flag inventory ";
            }
            string strErrorCode = string.Empty;

            if (msgTran.AryData.Length == 1)
            {
                strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]);
                string strLog = strCmd + "failed, due to: " + strErrorCode;

                //WriteLog(lrtxtLog, strLog, 1);
                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]);

                //WriteLog(lrtxtLog, strCmd, 0);
                RefreshInventoryReal(0x01);
                RunLoopInventroy();
            }
            else
            {
                m_nTotal++;
                int    nLength    = msgTran.AryData.Length;
                int    nEpcLength = nLength - 4;
                string strEPC     = CCommondMethod.ByteArrayToString(msgTran.AryData, 3, nEpcLength);
                string strPC      = CCommondMethod.ByteArrayToString(msgTran.AryData, 1, 2);
                string strRSSI    = msgTran.AryData[nLength - 1].ToString();
                SetMaxMinRSSI(Convert.ToInt32(msgTran.AryData[nLength - 1]));
                byte btTemp  = msgTran.AryData[0];
                byte btAntId = (byte)((btTemp & 0x03) + 1);
                m_curInventoryBuffer.nCurrentAnt = btAntId;
                string strAntId = btAntId.ToString();
                EPCPassed = strEPC;

                byte   btFreq  = (byte)(btTemp >> 2);
                string strFreq = GetFreqString(btFreq);

                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);
            }
        }
示例#12
0
        private void AnalyData(Reader.MessageTran msgTran)
        {
            if (msgTran.PacketType != 0xA0)
            {
                return;
            }
            switch (msgTran.Cmd)
            {
            // ONLY FOR SETUP

            /*case 0x69:
             *  ProcessSetProfile(msgTran);
             *  break;
             * case 0x6A:
             *  ProcessGetProfile(msgTran);
             *  break;
             * case 0x71:
             *  ProcessSetUartBaudrate(msgTran);
             *  break;
             * case 0x72:
             *  ProcessGetFirmwareVersion(msgTran);
             *  break;
             * case 0x73:
             *  ProcessSetReadAddress(msgTran);
             *  break;
             * case 0x75:
             *  ProcessGetWorkAntenna(msgTran);
             *  break;
             * case 0x76:
             *  ProcessSetOutputPower(msgTran);
             *  break;
             * case 0x77:
             *  ProcessGetOutputPower(msgTran);
             *  break;
             * case 0x78:
             *  ProcessSetFrequencyRegion(msgTran);
             *  break;
             * case 0x79:
             *  ProcessGetFrequencyRegion(msgTran);
             *  break;
             * case 0x7A:
             *  ProcessSetBeeperMode(msgTran);
             *  break;
             * case 0x7B:
             *  ProcessGetReaderTemperature(msgTran);
             *  break;
             * case 0x7C:
             *  ProcessSetDrmMode(msgTran);
             *  break;
             * case 0x7D:
             *  ProcessGetDrmMode(msgTran);
             *  break;
             * case 0x7E:
             *  ProcessGetImpedanceMatch(msgTran);
             *  break;
             * case 0x60:
             *  ProcessReadGpioValue(msgTran);
             *  break;
             * case 0x61:
             *  ProcessWriteGpioValue(msgTran);
             *  break;
             * case 0x62:
             *  ProcessSetAntDetector(msgTran);
             *  break;
             * case 0x63:
             *  ProcessGetAntDetector(msgTran);
             *  break;
             * case 0x67:
             *  ProcessSetReaderIdentifier(msgTran);
             *  break;
             * case 0x68:
             *  ProcessGetReaderIdentifier(msgTran);
             *  break;
             * case 0x82:
             *  ProcessWriteTag(msgTran);
             *  break;
             * case 0x83:
             *  ProcessLockTag(msgTran);
             *  break;
             * case 0x84:
             *  ProcessKillTag(msgTran);
             *  break;
             * case 0x8D:
             *  ProcessSetMonzaStatus(msgTran);
             *  break;
             * case 0x8E:
             *  ProcessGetMonzaStatus(msgTran);
             *  break;
             * case 0x90:
             *  ProcessGetInventoryBuffer(msgTran);
             *  break;
             * case 0x91:
             *  ProcessGetAndResetInventoryBuffer(msgTran);
             *  break;
             * case 0x92:
             *  ProcessGetInventoryBufferTagCount(msgTran);
             *  break;
             * case 0x93:
             *  ProcessResetInventoryBuffer(msgTran);
             *  break;
             * case 0xb2:
             *  ProcessWriteTagISO18000(msgTran);
             *  break;
             * case 0xb3:
             *  ProcessLockTagISO18000(msgTran);
             *  break;
             * case 0x85:
             *  ProcessSetAccessEpcMatch(msgTran);
             *  break;
             * case 0x86:
             *  ProcessGetAccessEpcMatch(msgTran);
             *  break;
             * case 0x80:
             *  ProcessInventory(msgTran);
             *  break;
             * case 0x81:
             *  ProcessReadTag(msgTran);
             *  break;
             * case 0x8A:
             *  ProcessFastSwitch(msgTran);
             *  break;
             * case 0xb0:
             *  ProcessInventoryISO18000(msgTran);
             *  break;
             * case 0xb1:
             *  ProcessReadTagISO18000(msgTran);
             *  break;
             * case 0xb4:
             *  ProcessQueryISO18000(msgTran);
             *  break;
             */
            case 0x74:
                ProcessSetWorkAntenna(msgTran);
                break;

            case 0x79:
                ProcessGetFrequencyRegion(msgTran);
                break;

            case 0x89:
            case 0x8B:
                ProcessInventoryReal(msgTran);
                break;

            default:
                break;
            }
        }
        private void RunReceiveDataCallback(byte[] btAryReceiveData)
        {
            try
            {
                if (ReceiveCallback != null)
                {
                    ReceiveCallback(btAryReceiveData);
                }

                int    nCount      = btAryReceiveData.Length;
                byte[] btAryBuffer = new byte[nCount + m_nLenth];
                Array.Copy(m_btAryBuffer, btAryBuffer, m_nLenth);
                Array.Copy(btAryReceiveData, 0, btAryBuffer, m_nLenth, btAryReceiveData.Length);

                //Analyzing the received data , starting with 0xA0 data to the data length of the data protocol termination point
                int nIndex     = 0; //When there is data A0 , the recording end point data
                int nMarkIndex = 0; //When the data does not exist in A0, nMarkIndex set equal to the largest index data
                for (int nLoop = 0; nLoop < btAryBuffer.Length; nLoop++)
                {
                    if (btAryBuffer.Length > nLoop + 1)
                    {
                        if (btAryBuffer[nLoop] == 0xA0)
                        {
                            int nLen = Convert.ToInt32(btAryBuffer[nLoop + 1]);
                            if (nLoop + 1 + nLen < btAryBuffer.Length)
                            {
                                byte[] btAryAnaly = new byte[nLen + 2];
                                Array.Copy(btAryBuffer, nLoop, btAryAnaly, 0, nLen + 2);

                                MessageTran msgTran = new MessageTran(btAryAnaly);
                                if (AnalyCallback != null)
                                {
                                    AnalyCallback(msgTran);
                                }

                                nLoop += 1 + nLen;
                                nIndex = nLoop + 1;
                            }
                            else
                            {
                                nLoop += 1 + nLen;
                            }
                        }
                        else
                        {
                            nMarkIndex = nLoop;
                        }
                    }
                }

                if (nIndex < nMarkIndex)
                {
                    nIndex = nMarkIndex + 1;
                }

                if (nIndex < btAryBuffer.Length)
                {
                    m_nLenth = btAryBuffer.Length - nIndex;
                    Array.Clear(m_btAryBuffer, 0, 4096);
                    Array.Copy(btAryBuffer, nIndex, m_btAryBuffer, 0, btAryBuffer.Length - nIndex);
                }
                else
                {
                    m_nLenth = 0;
                }
            }
            catch (System.Exception ex)
            {
            }
        }