Ejemplo n.º 1
0
 public void GetCoreTab(object source, System.Timers.ElapsedEventArgs e)
 {
     CoreTabDAMux.WaitOne();
     CoreTabDA = MyManager.GetDataADP("Exec GetCoreTablePRC");
     //this.Invoke(new TextOption(f));//invok 委托实现跨线程的调用
     CoreTabDAMux.ReleaseMutex();
 }
Ejemplo n.º 2
0
        void TagMonitorThread(object Mach)
        {
            Mach mc     = (Mach)Mach;
            int  MachID = mc.MachID;

            while (isInventory)
            {
                try
                {
                    TagReadData[] Tags = mc.rd.Read(500);
                    foreach (TagReadData tag in Tags)
                    {
                        AddTagToDic(tag, MachID);
                    }
                }
                catch (OpFaidedException ex1)
                {
                    MyManager.AddInfoToDB("警告", mc.MachName + "->" + ex1.ToString());
                }
                catch (Exception ex2)//需要重新连接机器
                {
                    MyManager.AddInfoToDB("错误", mc.MachName + "->" + ex2.ToString() + ",开始重新连接。");
                    ReConnect(mc);
                }
            }
        }
Ejemplo n.º 3
0
        void ReConnect(Mach mc)
        {
            int    i, j, k;
            String Ret = "";

            if (mc.ReConnectedCount > 5)
            {
                /*本设备重连超过五次不成功,可能连接存在问题
                 */

                MyManager.AddInfoToDB("错误", mc.MachName + "重连5次不成功,不再尝试连接。");
                return;
            }

            try
            {
                mc.ReConnectedCount++;

                MyManager.AddInfoToDB("信息", mc.MachName + "开始重连.");
                mc.rd = Reader.Create(mc.MachIP, ModuleTech.Region.NA, 4);

                int[] connectedants = (int[])mc.rd.ParamGet("ConnectedAntennas");

                if (connectedants.Length < 1)
                {
                    Ret = "";
                    int[] xx = { 0, 0, 0, 0 };
                    for (j = 0; j < connectedants.Length; j++)
                    {
                        xx[connectedants[j] - 1] = 1;
                    }
                    for (k = 0; k < 4; k++)
                    {
                        if (xx[k] == 0)
                        {
                            Ret += (k + 1).ToString() + " ";
                        }
                    }
                    Ret = mc.MachName + "," + Ret + "号天线未连接!!";
                    MyManager.AddInfoToDB("错误", Ret);
                }
                mc.ConnectedAnts = (int[])connectedants.Clone();
                Gen2TagFilter filter = new Gen2TagFilter(ByteFormat.FromHex("FFFFFFFF"), MemBank.EPC, 32, false);
                mc.rd.ParamSet("Singulation", filter);
                SimpleReadPlan searchPlan = new SimpleReadPlan(mc.ConnectedAnts);
                mc.rd.ParamSet("ReadPlan", searchPlan);
                mc.Mthread = new Thread(new ParameterizedThreadStart(TagMonitorThread));
                mc.Mthread.Start(mc);
                MyManager.AddInfoToDB("信息", mc.MachName + "重连并启动监视线程成功!");
                mc.ReConnectedCount--;
            }
            catch (Exception ex)
            {
                Ret = mc.MachName + ",重连-->" + ex.ToString();
                MyManager.AddInfoToDB("错误", Ret);
                ReConnect(mc);
            }
            mc.ReConnectedCount = 0;
        }
Ejemplo n.º 4
0
        void  initMach()
        {
            Mach      mc;
            String    Ant;
            DataTable dt = MyManager.GetDataSet("SELECT * FROM MachList");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                mc          = new Mach();
                mc.MachID   = Convert.ToInt32(dt.Rows[i]["ID"].ToString());
                mc.MachName = dt.Rows[i]["MachineName"].ToString();
                mc.MachIP   = dt.Rows[i]["IP"].ToString();
                // mc.ConnectedAnts = Array.ConvertAll<string, int>(dt.Rows[i]["ConnectedAnt"].ToString().Split('|'), delegate(string s) { return int.Parse(s); });
                mc.rd = null;
                MachLst.Add(mc);
            }
        }
Ejemplo n.º 5
0
        String CheckAntAndInitReaders()
        {
            String Ret = "OK";
            int    i, j, k;

            for (i = 0; i < MachLst.Count; i++)
            {
                try
                {
                    MachLst[i].rd = Reader.Create(MachLst[i].MachIP, ModuleTech.Region.NA, 4);

                    int[] connectedants = (int[])MachLst[i].rd.ParamGet("ConnectedAntennas");
                    if (connectedants.Length < 1)
                    {
                        Ret = "";
                        int[] xx = { 0, 0, 0, 0 };
                        for (j = 0; j < connectedants.Length; j++)
                        {
                            xx[connectedants[j] - 1] = 1;
                        }
                        for (k = 0; k < 4; k++)
                        {
                            if (xx[k] == 0)
                            {
                                Ret += (k + 1).ToString() + " ";
                            }
                        }
                        Ret = MachLst[i].MachName + "," + Ret + "号天线未连接!!";
                        MyManager.AddInfoToDB("错误", Ret);
                        break;
                    }
                    MachLst[i].ConnectedAnts = (int[])connectedants.Clone();
                    MyManager.AddInfoToDB("信息", MachLst[i].MachName + "连接成功!");
                }
                catch (Exception ex)
                {
                    Ret = MachLst[i].MachName + "-->" + ex.ToString();
                    MyManager.AddInfoToDB("错误", Ret);
                    break;
                }
            }
            return(Ret);
        }
Ejemplo n.º 6
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            TagMux.WaitOne();
            BinaryFormatter Formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
            MemoryStream    stream    = new MemoryStream();

            Formatter.Serialize(stream, TagDic);
            TagMux.ReleaseMutex();

            stream.Position = 0;
            clonedObj       = Formatter.Deserialize(stream);
            stream.Close();

            Dictionary <String, TagInfo> tmpTagDic = (Dictionary <String, TagInfo>)clonedObj;

            foreach (String Key in tmpTagDic.Keys)
            {
                lst1.Items.Add(Key + "-->" + tmpTagDic[Key].PosY + "->" + TagDic[Key].Rssi);
                if (lv1.Items.ContainsKey(Key))
                {
                    ListViewItem item = lv1.Items[Key];

                    item.SubItems[1].Text = MyManager.DecodeEPC(Key);
                    item.SubItems[2].Text = tmpTagDic[Key].LastSeen.ToString();
                    item.SubItems[3].Text = tmpTagDic[Key].ReadCount.ToString();
                    item.SubItems[4].Text = tmpTagDic[Key].Rssi.ToString();
                    item.SubItems[5].Text = tmpTagDic[Key].PosY.ToString();
                    item.SubItems[6].Text = tmpTagDic[Key].PosX.ToString();
                }
                else
                {
                    ListViewItem item = new ListViewItem(Key);
                    item.Name = Key;
                    item.SubItems.Add(MyManager.DecodeEPC(Key));
                    item.SubItems.Add(tmpTagDic[Key].LastSeen.ToString());
                    item.SubItems.Add(tmpTagDic[Key].ReadCount.ToString());
                    item.SubItems.Add(tmpTagDic[Key].Rssi.ToString());
                    item.SubItems.Add(tmpTagDic[Key].PosY.ToString());
                    item.SubItems.Add(tmpTagDic[Key].PosX.ToString());
                    lv1.Items.Add(item);
                }
            }
        }
Ejemplo n.º 7
0
        void  CreateMonitorThreads()
        {
            int i, unFinished = 0;

            if (MachLst.Count == 0)
            {
                return;
            }

            for (i = 0, unFinished = 0; i < MachLst.Count; i++)
            {
                if (MachLst[i].rd == null)
                {
                    unFinished = 1;
                    MyManager.AddInfoToDB("错误", MachLst[i].MachName + "未建立连接!");
                    lst1.Items.Add(MachLst[i].MachName + "未建立连接!");
                    break;
                }
                //只显示EPC以FFFF FFFF开头的标签
                Gen2TagFilter filter = new Gen2TagFilter(ByteFormat.FromHex("FFFFFFFF"), MemBank.EPC, 32, false);
                MachLst[i].rd.ParamSet("Singulation", filter);
                SimpleReadPlan searchPlan = new SimpleReadPlan(MachLst[i].ConnectedAnts);
                MachLst[i].rd.ParamSet("ReadPlan", searchPlan);
                MachLst[i].Mthread = new Thread(new ParameterizedThreadStart(TagMonitorThread));
            }

            if (unFinished == 1)
            {
                return;
            }

            for (i = 0; i < MachLst.Count; i++)
            {
                MachLst[i].Mthread.Start(MachLst[i]);
                lst1.Items.Add("启动" + MachLst[i].Mthread);
            }

            lst1.Items.Add("创建线程完毕!");
        }
Ejemplo n.º 8
0
 static public int AddInfoToDB(String Type, String Txt)
 {
     return(MyManager.ExecSQL("INSERT INTO MachMsg(Time,Type,txt) VALUES('" + DateTime.Now.ToString() + "','" + Type + "','" + Txt + "')"));
 }