Esempio n. 1
0
        /// <summary>
        /// 消息发送和数据处理
        /// </summary>
        /// <param name="clientConn"></param>
        /// <param name="com"></param>
        /// <returns></returns>
        private static HashSet <string> DealComData(GClient clientConn, string com, out bool isGetSuccess)
        {
            /// mutex互斥锁,用于人为阻塞当前线程
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            manualEvents.Add(manualResetEvent);

            DelegateGetMsg delegateGetMsg = new DelegateGetMsg(com, clientConn, manualResetEvent);

            // 订阅标签上报事件
            clientConn.OnEncapedTagEpcLog  += new delegateEncapedTagEpcLog(delegateGetMsg.OnEncapedTagEpcLog);
            clientConn.OnEncapedTagEpcOver += new delegateEncapedTagEpcOver(delegateGetMsg.OnEncapedTagEpcOver);

            //停止指令,空闲态
            SendSynBaseStopMsg(clientConn, out isGetSuccess);

            //功率配置, 将 4 个天线功率都设置为 30dBm.
            SendSynBaseSetPowerMsg(clientConn, out isGetSuccess);

            //4个天线读卡, 读取EPC数据区以及TID数据区
            SendSynBaseInventoryEpcMsg(clientConn, out isGetSuccess);

            //返回收集结果
            return(delegateGetMsg.GetDelegateMsg());

            //停止指令,空闲态
            //SendSynBaseStopMsg(clientConn);
        }
Esempio n. 2
0
        /// <summary>
        /// 创建串口连接
        /// </summary>
        /// <param name="com">串口</param>
        /// <param name="baudRate">波特率</param>
        /// <param name="isConnect">是否连接串口成功</param>
        /// <returns></returns>
        private static GClient CreateClientConn(string com, string baudRate, out bool isConnect)
        {
            GClient clientConn = new GClient();

            isConnect = clientConn.OpenSerial(com + ":" + baudRate, 3000, out eConnectionAttemptEventStatusType status);
            return(clientConn);
        }
Esempio n. 3
0
        /// <summary>
        /// 4个天线读卡, 读取EPC数据区以及TID数据区
        /// </summary>
        /// <param name="clientConn">连接</param>
        private static void SendSynBaseInventoryEpcMsg(GClient clientConn, out bool isGetSuccess)
        {
            // 4个天线读卡, 读取EPC数据区以及TID数据区
            MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc
            {
                AntennaEnable = (eAntennaNo._1 | eAntennaNo._2 | eAntennaNo._3 | eAntennaNo._4),
                InventoryMode = (byte)eInventoryMode.Single,
                // tid参数
                ReadTid = new ParamEpcReadTid()
            };

            msgBaseInventoryEpc.ReadTid.Mode = (byte)eParamTidMode.Auto;
            msgBaseInventoryEpc.ReadTid.Len  = 6;
            clientConn.SendSynMsg(msgBaseInventoryEpc);
            if (0 == msgBaseInventoryEpc.RtCode)
            {
                isGetSuccess = true;
                LogUtils.Debug("Inventory epc successful.");
            }
            else
            {
                LogUtils.Debug("Inventory epc error.");
                isGetSuccess = false;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 功率配置, 将4个天线功率都设置为30dBm.
        /// </summary>
        /// <param name="clientConn">连接</param>
        private static void SendSynBaseSetPowerMsg(GClient clientConn, out bool isGetSuccess)
        {
            // 功率配置, 将4个天线功率都设置为30dBm.
            MsgBaseSetPower msgBaseSetPower = new MsgBaseSetPower
            {
                DicPower = new Dictionary <byte, byte>()
                {
                    { 1, 30 },
                    { 2, 30 },
                    { 3, 30 },
                    { 4, 30 }
                }
            };

            clientConn.SendSynMsg(msgBaseSetPower);
            if (0 == msgBaseSetPower.RtCode)
            {
                LogUtils.Debug("Power configuration successful.");
                isGetSuccess = true;
            }
            else
            {
                LogUtils.Debug("Power configuration error.");
                isGetSuccess = false;
            }
        }
Esempio n. 5
0
        static void DoSend()
        {
            String aRequest = String.Empty;
            String aData    = String.Empty;

            byte[] aDataBytes = null;
            Int32  aDataLen   = 0;

            Console.Write("Enter Request: ");
            aRequest = Console.ReadLine();

            Console.Write("Include Data? (Y/N) ");
            aData = Console.ReadLine();

            if (aData.ToLower() == "y")
            {
                Console.Write("Enter Data: ");
                aData      = Console.ReadLine();
                aDataBytes = System.Text.Encoding.ASCII.GetBytes(aData);
                aDataLen   = aDataBytes.Length;
            }
            else
            {
                aDataBytes = null;
                aDataLen   = 0;
            }

            GClient.Submit(ref aRequest, aDataBytes, aDataLen);
        }
Esempio n. 6
0
        static void DoConnect()
        {
            String aIPAdd = String.Empty;
            UInt16 aPort  = 0;

            Console.Write("Enter IP: ");
            aIPAdd = Console.ReadLine();

            Console.Write("Enter Port: ");
            aPort = UInt16.Parse(Console.ReadLine());

            GClient.OpenConnection(ref aIPAdd, aPort);
        }
Esempio n. 7
0
        /// <summary>
        /// 停止指令,空闲态(当读写器处于读卡状态时,所有配置消息将无法发送,必须发送停止指令)
        /// </summary>
        /// <param name="clientConn">连接</param>
        private static void SendSynBaseStopMsg(GClient clientConn, out bool isGetSuccess)
        {
            // 停止指令,空闲态
            MsgBaseStop msgBaseStop = new MsgBaseStop();

            clientConn.SendSynMsg(msgBaseStop);
            if (0 == msgBaseStop.RtCode)
            {
                isGetSuccess = true;
                LogUtils.Debug("Stop successful.");
            }
            else
            {
                LogUtils.Debug("Stop error.");
                isGetSuccess = false;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 新版epc数据获取,规则rf码扫描到的字段的后八位,前加RF。例:2019072800000001 =》 RF00000001
        /// </summary>
        /// <param name="isGetSuccess"></param>
        /// <returns></returns>
        public static Hashtable GetEpcDataNew(out bool isGetSuccess)
        {
            isGetSuccess = true;

            //string com1 = "COM1";
            string com1 = ApplicationState.GetMRfidCOM();

#if DUALCAB
            //string com4 = "COM4";
            string com4 = ApplicationState.GetSRfidCOM();
#endif

            Hashtable currentEpcDataHt = new Hashtable();

            GClient com1ClientConn = CreateClientConn(com1, "115200", out bool isCom1Connect);
            if (isCom1Connect)
            {
                currentEpcDataHt.Add(com1, DealComData(com1ClientConn, com1, out isGetSuccess));
            }
            else
            {
                isGetSuccess = false;
            }

#if DUALCAB
            GClient com4ClientConn = CreateClientConn(com4, "115200", out bool isCom4Connect);
            if (isCom4Connect)
            {
                currentEpcDataHt.Add(com4, DealComData(com4ClientConn, com4, out isGetSuccess));
            }
            else
            {
                isGetSuccess = false;
            }
#endif
            WaitHandle.WaitAll(manualEvents.ToArray());
            manualEvents.Clear();

            return(currentEpcDataHt);
        }
Esempio n. 9
0
 public DelegateGetMsg(String com, GClient currentClientConn, ManualResetEvent manualResetEvent)
 {
     this.com = com;
     this.currentClientConn = currentClientConn;
     this.manualResetEvent  = manualResetEvent;
 }
Esempio n. 10
0
        public static void TestRFID(object sender, ElapsedEventArgs elapsed)
        {
            GClient clientConn = new GClient();

            //COM1  主柜rfid串口
            //COM4  副柜rfid串口
            if (clientConn.OpenSerial("COM1:115200", 3000, out eConnectionAttemptEventStatusType status))
            //if (clientConn.OpenTcp("192.168.1.168:8160", 3000, out status))
            {
                // 订阅标签上报事件
                clientConn.OnEncapedTagEpcLog  += new delegateEncapedTagEpcLog(OnEncapedTagEpcLog);
                clientConn.OnEncapedTagEpcOver += new delegateEncapedTagEpcOver(OnEncapedTagEpcOver);

                // 停止指令,空闲态
                MsgBaseStop msgBaseStop = new MsgBaseStop();
                clientConn.SendSynMsg(msgBaseStop);
                if (0 == msgBaseStop.RtCode)
                {
                    LogUtils.Debug("Stop successful.");
                }
                else
                {
                    LogUtils.Debug("Stop error.");
                }

                // 功率配置, 将4个天线功率都设置为30dBm.
                MsgBaseSetPower msgBaseSetPower = new MsgBaseSetPower
                {
                    DicPower = new Dictionary <byte, byte>()
                    {
                        { 1, 30 },
                        { 2, 30 },
                        { 3, 30 },
                        { 4, 30 }
                    }
                };
                clientConn.SendSynMsg(msgBaseSetPower);
                if (0 == msgBaseSetPower.RtCode)
                {
                    LogUtils.Debug("Power configuration successful.");
                }
                else
                {
                    LogUtils.Debug("Power configuration error.");
                }
                LogUtils.Debug("Enter any character to start reading the tag.");
                Console.ReadKey();

                // 4个天线读卡, 读取EPC数据区以及TID数据区
                MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc
                {
                    AntennaEnable = (uint)(eAntennaNo._1 | eAntennaNo._2 | eAntennaNo._3 | eAntennaNo._4),
                    InventoryMode = (byte)eInventoryMode.Inventory,
                    // tid参数
                    ReadTid = new ParamEpcReadTid()
                };
                msgBaseInventoryEpc.ReadTid.Mode = (byte)eParamTidMode.Auto;
                msgBaseInventoryEpc.ReadTid.Len  = 6;
                clientConn.SendSynMsg(msgBaseInventoryEpc);
                if (0 == msgBaseInventoryEpc.RtCode)
                {
                    LogUtils.Debug("Inventory epc successful.");
                }
                else
                {
                    LogUtils.Debug("Inventory epc error.");
                }
                Console.ReadKey();

                // 停止读卡,空闲态
                clientConn.SendSynMsg(msgBaseStop);
                if (0 == msgBaseStop.RtCode)
                {
                    LogUtils.Debug("Stop successful.");
                }
                else
                {
                    LogUtils.Debug("Stop error.");
                }
            }
            else
            {
                LogUtils.Debug("Connect failure.");
            }
            Console.ReadKey();
            clientConn.Close();
        }
Esempio n. 11
0
        /// <summary>
        /// 根据eps json获取eps对象数据
        /// </summary>
        /// <param name="isGetSuccess"></param>
        /// <returns></returns>
        public static HashSet <CommodityEps> GetEpcDataJson(out bool isGetSuccess)
        {
            isGetSuccess = true;

            //string com1 = "COM1";
            string           com1        = ApplicationState.GetMRfidCOM();
            HashSet <string> com1HashSet = new HashSet <string>();

            string log = "";

#if DUALCAB
            //string com4 = "COM4";
            string           com4        = ApplicationState.GetSRfidCOM();
            HashSet <string> com4HashSet = new HashSet <string>();
#endif
            HashSet <CommodityEps> currentEpcDataHs = new HashSet <CommodityEps>();

            //TODO:需要补充id
            GClient com1ClientConn = CreateClientConn(com1, "115200", out bool isCom1Connect);
            if (isCom1Connect)
            {
                com1HashSet = DealComData(com1ClientConn, com1, out isGetSuccess);
            }
            else
            {
                isGetSuccess = false;
            }

#if DUALCAB
            GClient com4ClientConn = CreateClientConn(com4, "115200", out bool isCom4Connect);
            if (isCom4Connect)
            {
                com4HashSet = DealComData(com4ClientConn, com4, out isGetSuccess);
            }
            else
            {
                isGetSuccess = false;
            }
#endif

            WaitHandle.WaitAll(manualEvents.ToArray());
            manualEvents.Clear();

            //提取com1的标签epc,并组装
            foreach (string rfid in com1HashSet)
            {
                CommodityEps commodityEps = new CommodityEps
                {
                    CommodityCodeName = $"RF{rfid.Substring(rfid.Length - 8)}",
                    EquipmentId       = ApplicationState.GetEquipId(),
                    EquipmentName     = ApplicationState.GetEquipName(),
                    StoreHouseId      = ApplicationState.GetHouseId(),
                    StoreHouseName    = ApplicationState.GetHouseName(),
                    GoodsLocationName = ApplicationState.GetCabNameByRFidCom(com1),
                    GoodsLocationId   = ApplicationState.GetCabIdByRFidCom(com1)
                };

                currentEpcDataHs.Add(commodityEps);
                LogUtils.Debug(commodityEps.CommodityCodeName + commodityEps.CommodityName);
                log += commodityEps.CommodityCodeName + " ";
            }

#if DUALCAB
            //提取com4的标签epc,并组装
            foreach (string rfid in com4HashSet)
            {
                CommodityEps commodityEps = new CommodityEps
                {
                    CommodityCodeName = $"RF{rfid.Substring(rfid.Length - 8)}",
                    EquipmentId       = ApplicationState.GetEquipId(),
                    EquipmentName     = ApplicationState.GetEquipName(),
                    StoreHouseId      = ApplicationState.GetHouseId(),
                    StoreHouseName    = ApplicationState.GetHouseName(),
                    GoodsLocationName = ApplicationState.GetCabNameByRFidCom(com1),
                    GoodsLocationId   = ApplicationState.GetCabIdByRFidCom(com1)
                };

                currentEpcDataHs.Add(commodityEps);
                LogUtils.Debug(commodityEps.CommodityCodeName + commodityEps.CommodityName);
                log += commodityEps.CommodityCodeName + " ";
            }
#endif

            Task.Factory.StartNew(a =>
            {
                LogUtils.Debug(log);
            }, log);

            LogUtils.Debug("RFID NUM:" + currentEpcDataHs.Count());
            return(currentEpcDataHs);
        }
Esempio n. 12
0
 static void DoDisconnect()
 {
     GClient.CloseConnection();
 }
Esempio n. 13
0
        static void DoSendLarge()
        {
            String aInput      = String.Empty;
            String aRequest    = String.Empty;
            UInt16 aNumOfBytes = 0;
            byte   aByte       = 0;

            byte[] aByteString = null;
            byte[] aData       = null;
            Int32  aRepeat;
            Int32  aInterval;

            // Get number of bytes to send
            Console.Write("Enter Size of Request (in bytes): ");
            aInput      = Console.ReadLine();
            aNumOfBytes = UInt16.Parse(aInput);

            if (aNumOfBytes > 0)
            {
                aByteString = new byte[aNumOfBytes];

                for (UInt16 i = 0; i < (aNumOfBytes); i++)
                {
                    aByte = (byte)(i % Byte.MaxValue);

                    if (aByte < 33)
                    {
                        aByte = 46;
                    }
                    else if (aByte > 127 && aByte < 160)
                    {
                        aByte = 46;
                    }

                    aByteString[i] = aByte;
                }

                aRequest = System.Text.Encoding.GetEncoding(28591).GetString(aByteString);

                Console.WriteLine(DateTime.Now.TimeOfDay + ": INFO: Request:");
                DumpBytes(aByteString, 0, aByteString.Length);
            }

            Console.Write("Enter Size of Data (in bytes): ");
            aNumOfBytes = UInt16.Parse(Console.ReadLine());

            if (aNumOfBytes > 0)
            {
                aData = new byte[aNumOfBytes];

                for (UInt16 i = 0; i < (aNumOfBytes); i++)
                {
                    aByte = (byte)(i % Byte.MaxValue);

                    if (aByte < 33)
                    {
                        aByte = 46;
                    }
                    else if (aByte > 127 && aByte < 160)
                    {
                        aByte = 46;
                    }

                    aData[i] = aByte;
                }

                Console.WriteLine(DateTime.Now.TimeOfDay + ": INFO: Data: ");
                DumpBytes(aData, 0, aData.Length);
            }
            else
            {
                aNumOfBytes = 0;
            }

            Console.Write("Enter No. of Times to Repeat: ");
            aRepeat = Int32.Parse(Console.ReadLine());

            Console.Write("Enter No. of Interval (in ms): ");
            aInterval = Int32.Parse(Console.ReadLine());

            if (aInterval < 0)
            {
                Console.Error.WriteLine("Error: Invalid Interval Size.");
                return;
            }

            for (int i = 0; i < aRepeat; i++)
            {
                // Send request message
                GClient.Submit(ref aRequest, aData, aNumOfBytes);
                // Sleep
                Thread.Sleep(aInterval);
            }
        }