Пример #1
0
        public bool conn()
        {
            hreader = (UIntPtr)0x00;
            int     iret;
            UIntPtr InvenParamSpecList = UIntPtr.Zero;

            InvenParamSpecList = RfidBLL.RDR_CreateInvenParamSpecList();
            RfidBLL.RDR_SetInvenStopTrigger(InvenParamSpecList, 3, 1000, 0);
            UIntPtr AIPIso18000p6c = RfidBLL.ISO18000p6C_CreateInvenParam(InvenParamSpecList, 0,
                                                                          0, 0, 0x00,
                                                                          0xff);

            if (AIPIso18000p6c.ToUInt64() != 0)
            {
                string connstr = "RDType=M60;CommType=COM;COMName=COM8;BaudRate=38400;Frame=8E1;BusAddr=255";
                UInt32 nCOMCnt = RfidBLL.COMPort_Enum();
                for (uint i = 0; i < nCOMCnt; i++)
                {
                    StringBuilder comName = new StringBuilder();
                    comName.Append('\0', 64);
                    RfidBLL.COMPort_GetEnumItem(i, comName, (UInt32)comName.Capacity);
                    connstr = "RDType=M60;CommType=COM;COMName=" + comName + ";BaudRate=38400;Frame=8E1;BusAddr=255";
                    int r = RfidBLL.RDR_Open(connstr, ref hreader);
                    if (r == 0)
                    {
                        StringBuilder devInfor = new StringBuilder();
                        devInfor.Append('\0', 128);
                        UInt32 nSize;
                        nSize = (UInt32)devInfor.Capacity;
                        r     = RfidBLL.RDR_GetReaderInfor(hreader, 0, devInfor, ref nSize);
                        if (r == 0)
                        {
                            ServerConfig.connState = true;
                            _shouldStop            = false;
                            return(true);
                        }
                        return(false);
                    }
                }
                return(false);
            }
            return(false);
        }
Пример #2
0
        public int tag_inventory(
            Byte AIType,
            Byte AntennaSelCount,
            Byte[] AntennaSel,
            ref UInt32 nTagCount)
        {
            int     iret;
            UIntPtr InvenParamSpecList = UIntPtr.Zero;

            InvenParamSpecList = RfidBLL.RDR_CreateInvenParamSpecList();
            if (InvenParamSpecList.ToUInt64() != 0)
            {
                /* set timeout */
                RfidBLL.RDR_SetInvenStopTrigger(InvenParamSpecList, 3, 100, 0);
                /* create ISO18000p6C air protocol inventory parameters */
                UIntPtr AIPIso18000p6c = RfidBLL.ISO18000p6C_CreateInvenParam(InvenParamSpecList, 0, 0, 0, 0x00, 0xff);
                if (AIPIso18000p6c.ToUInt64() != 0)
                {
                    if (result)
                    {
                        p = 0x01;//epc
                    }
                    else
                    {
                        p = 0x03;//uid 0x02 tid
                    }
                    /* set inventory read parameter for TID */
                    RfidBLL.ISO18000p6C_SetInvenReadParam(AIPIso18000p6c, (Byte)p, 0, 0);
                    /*only TID return */
                    UInt32 metaFlags = 0x20;
                    RfidBLL.ISO18000p6C_SetInvenMetaDataFlags(AIPIso18000p6c, metaFlags);
                }
            }
            nTagCount = 0;
LABEL_TAG_INVENTORY:
            try
            {
                iret = RfidBLL.RDR_TagInventory(hreader, AIType, AntennaSelCount, AntennaSel, InvenParamSpecList);

                if (iret == 0 || iret == -21)
                {
                    nTagCount += RfidBLL.RDR_GetTagDataReportCount(hreader);
                    UIntPtr TagDataReport;
                    TagDataReport = (UIntPtr)0;
                    TagDataReport = RfidBLL.RDR_GetTagDataReport(hreader, 0); //first
                    while (TagDataReport.ToUInt64() > 0)
                    {
                        UInt32 aip_id    = 0;
                        UInt32 tag_id    = 0;
                        UInt32 ant_id    = 0;
                        Byte[] tagData   = new Byte[256];
                        UInt32 nSize     = (UInt32)tagData.Length;
                        UInt32 metaFlags = 0;

                        iret = RfidBLL.ISO18000p6C_ParseTagReport(TagDataReport, ref aip_id, ref tag_id, ref ant_id, ref metaFlags, tagData, ref nSize);
                        if (iret == 0)
                        {
                            object[] pList = { aip_id, tag_id, ant_id, metaFlags, tagData, nSize, "", "" };

                            byte[] epc = new byte[12];
                            Array.Copy(tagData, 4, epc, 0, 12);
                            StringBuilder @string = new StringBuilder();
                            foreach (var temp in epc)
                            {
                                @string.Append(temp.ToString("X2"));
                            }

                            if (@string.ToString().Contains("E200680A8AA8"))//层架判断
                            {
                                result = false;
                            }
                            else if (result && !ServerConfig.EpcList.Contains(@string.ToString()))
                            {
                                ServerConfig.EpcList.Enqueue(@string.ToString());
                                result = true;
                            }
                            else if (result && !ServerConfig.EpcS.Contains(@string.ToString()))
                            {
                                ServerConfig.EpcS.Add(@string.ToString());
                                result = true;
                            }
                            else
                            {
                                result = true;
                            }
                            ///user判断
                            byte[] user = new byte[28];
                            Array.Copy(tagData, 0, user, 0, 28);
                            @string = new StringBuilder();
                            foreach (var temp in user)
                            {
                                @string.Append(temp.ToString("X2"));
                            }
                            if (@string.ToString().Contains("AA0CFFA5"))
                            {
                                //可用user
                                if (!ServerConfig.UserList.Contains(@string.ToString()))
                                {
                                    ServerConfig.UserList.Enqueue(@string.ToString());
                                }
                            }
                            //else if(p==0x03)
                            //{
                            //    result = false;
                            //    //保持最后一个epc为层架标签和最后一个user对应
                            //}
                        }
                        TagDataReport = RfidBLL.RDR_GetTagDataReport(hreader, 2); //next
                    }
                    if (iret == -21)                                              // stop trigger occur,need to inventory left tags
                    {
                        AIType = 2;                                               //use only-new-tag inventory
                        goto LABEL_TAG_INVENTORY;
                    }
                    iret = 0;
                }
                if (InvenParamSpecList.ToUInt64() != 0)
                {
                    RfidBLL.DNODE_Destroy(InvenParamSpecList);
                }
                return(iret);
            }
            catch {
                return(0);
            }
        }