Beispiel #1
0
        private void Init()
        {
            try
            {
                var    readerPort = "COM7";
                byte[] comName    = new byte[readerPort.Length + 1];
                comName = StringUtility.string2bytes(readerPort);

                sConnectMode = UHFConstants.RF_CONNECT_MODE.RF_CONNECT_MODE_LOCAL_UART;

                if (InitRFID() != 0)
                {
                    //tipMsg.Text = "初始化RFID库失败!";
                    return;
                }

                if (UHFNative.openCom(comName, 115200) == 0)
                {
                    if (getModuleBaseInfo() != 0)
                    {
                        UHFNative.closeCom();
                        LogHelper.WriteLog("获取模块信息失败!");
                    }

                    else
                    {
                        //byte DR = 0, M = 0, TRext = 0, Sel = 0, Session = 0, Target = 0, Q = 7;
                        //if (UHFNative.setQuery(DR, M, TRext, Sel, Session, Target, Q) == 0)
                        //{
                        int maskFlag = 0;
                        // 清除掉过滤信息
                        UHFNative.resetInventoryFilter();
                        // 启动盘点,发送盘点指令
                        // if (UHFNative.startInventory((byte)1, (byte)maskFlag) == 0)
                        //{
                        //设置读取EPC和tid
                        UHFNative.setInventoryArea((byte)1, (byte)0, (byte)6);
                        UHFNative.startInventory((byte)1, (byte)maskFlag);

                        LogHelper.WriteLog("串口打开成功");
                        // }
                        // }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("初始化端口出错", ex);
            }
        }
 public static extern int setRFConnectMode(UHFConstants.RF_CONNECT_MODE flag);