예제 #1
0
        public RFID ReadTagsRFID(bool identify_card)
        {
            try
            {
                Opc.Da.Server  server = null;
                OpcCom.Factory fact   = new OpcCom.Factory();
                server = new Opc.Da.Server(fact, null);

                server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));

                //
                Opc.Da.Subscription      group;
                Opc.Da.SubscriptionState groupState = new Opc.Da.SubscriptionState();
                groupState.Name   = "RFID";
                groupState.Active = true;
                group             = (Opc.Da.Subscription)server.CreateSubscription(groupState);

                //добавление айтемов в группу
                Opc.Da.Item[] items = new Opc.Da.Item[2];
                items[0]          = new Opc.Da.Item();
                items[0].ItemName = "ZREADER.RFID_reader.part1";
                items[1]          = new Opc.Da.Item();
                items[1].ItemName = "ZREADER.RFID_reader.part2";
                items             = group.AddItems(items);
                //List<oldRFID> result_list = new List<oldRFID>();
                ItemValueResult[] res = group.Read(items);
                RFID       rfid       = new RFID();
                EFazsCards ef_card    = new EFazsCards();
                if (res != null)
                {
                    //UInt16? part1 = res[0].Value != null ? res[0].Value as UInt16? : 37;
                    //UInt16? part2 = res[1].Value != null ? res[1].Value as UInt16? : 50907;
                    UInt16?part1 = res[0].Value != null ? res[0].Value as UInt16? : null;
                    UInt16?part2 = res[1].Value != null ? res[1].Value as UInt16? : null;
                    if (part1 != null && part2 != null)
                    {
                        rfid.part1 = part1;
                        rfid.part2 = part2;
                        if (identify_card)
                        {
                            int code1 = int.Parse(part1.ToString());
                            int code2 = int.Parse(part2.ToString());
                            String.Format("Определим ID=карты code1={0}, code2={1}", code1, code2).SaveInformation();
                            azsCards card = ef_card.Get().Where(c => c.Number == (code1).ToString("00") + "," + (code2).ToString("00000")).FirstOrDefault();
                            if (card == null)
                            {
                                card = ef_card.Get().Where(c => c.Number == (code1).ToString("000") + "," + (code2).ToString("00000")).FirstOrDefault();
                            }
                            rfid.card = card;
                        }
                    }
                }
                return(rfid);
            }
            catch (Exception e)
            {
                String.Format("Ошибка выполнения метода ReadTagsRFID(identify_card={0})", identify_card).SaveError(e);
                return(null);
            }
        }
예제 #2
0
 private ClientOPCTRK.Cards GetCardsOfNum(int hi, int lo)
 {
     try
     {
         EFazsCards   ef_card    = new EFazsCards();
         EFazsDeparts ef_departs = new EFazsDeparts();
         if (hi > 0 && lo > 0)
         {
             string     num     = hi.ToString("000") + "," + lo.ToString("00000");
             azsCards   card    = ef_card.Database.SqlQuery <azsCards>("SELECT * FROM [KRR-PA-CNT-Oil].[dbo].[azsCards] where [Number]=N'" + num + "'").ToList().FirstOrDefault();
             azsDeparts departs = null;
             if (card != null)
             {
                 departs = ef_departs.Get().Where(d => d.id == ((int)card.House).ToString("000")).FirstOrDefault();
             }
             ClientOPCTRK.Cards cards = new ClientOPCTRK.Cards()
             {
                 Id         = card.Id,
                 Number     = card.Number,
                 DriverName = card.DriverName,
                 AutoNumber = card.AutoNumber,
                 Debitor    = card.Debitor,
                 Sn1        = card.Sn1,
                 Sn2        = card.Sn2,
                 AutoModel  = card.AutoModel,
                 Street     = card.Street,
                 House      = card.House,
                 CreateDate = card.CreateDate,
                 CreateTime = card.CreateTime,
                 UpdateDate = card.UpdateDate,
                 UpdateTime = card.UpdateTime,
                 Owner      = card.Owner,
                 Active     = card.Active,
                 Name       = departs != null && departs.name != null ? departs.name : "?",
             };
             return(cards);
         }
         return(null);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(null);
     }
 }