Esempio n. 1
0
 //读卡
 public IDCard ReadCard(IDCard IC)
 {
     try
     {
         iConnectionState = IC.InitComm();
         if (iConnectionState == 1)
         {
             int iResult = 0;
             while (iResult != 2)
             {
                 iResult = IC.ReadCardContent();
                 Thread.Sleep(100);
             }
         }
         else
         {
             IC = null;
         }
     }
     catch (Exception ex)
     {
         IC = null;
         LogImpl.Error(string.Format("{0}{2}{1}", ex.StackTrace, ex.Message, System.Environment.NewLine));
     }
     return(IC);
 }
Esempio n. 2
0
 private void button16_Click(object sender, EventArgs e)
 {
     LogImpl.Debug("Debug");
     LogImpl.Error("错误信息");
     LogImpl.Fatal("Fatal");
     LogImpl.Info("Info");
     LogImpl.Warn("警告Warn");
 }
Esempio n. 3
0
 public static void Dispose()
 {
     if (instance != null)
     {
         try
         {
             foreach (var item in instance.opcGrpsDic)
             {
                 item.Value.Remove(false);
             }
             instance.opcSrv.Disconnect();
             instance = null;
         }
         catch (Exception ex)
         {
             LogImpl.Error(string.Format("{0}{2}{1}", ex.StackTrace, ex.Message, System.Environment.NewLine));
         }
     }
 }
Esempio n. 4
0
        private PLCCommand2()
        {
            try
            {
                opcSrv.Connect(strSrvName);
                for (int i = 0; i < arrGrps.Length; i++)
                {
                    string   strGrp = arrGrps[i];
                    OpcGroup grp    = opcSrv.AddGroup(strGrp, true, 9600);
                    opcGrpsDic.Add(strGrp, grp);

                    string[] arrCurrentItems = arrItems[i].Split(',');

                    OPCItemDef[]    opcItems   = new OPCItemDef[arrCurrentItems.Length];
                    OPCItemResult[] opcResults = new OPCItemResult[arrCurrentItems.Length];
                    for (int j = 0; j < arrCurrentItems.Length; j++)
                    {
                        string     strItemName = string.Format("{0}.{1}.{2}", strItemID, strGrp, arrCurrentItems[j]);
                        OPCItemDef item        = new OPCItemDef(strItemName, true, opcResults.Length, System.Runtime.InteropServices.VarEnum.VT_BOOL);
                        opcItems[j] = item;
                    }
                    Dictionary <string, OPCItemResult> oDic = new Dictionary <string, OPCItemResult>();
                    grp.AddItems(opcItems, out opcResults);

                    for (int k = 0; k < opcResults.Length; k++)
                    {
                        oDic.Add(arrCurrentItems[k], opcResults[k]);
                    }
                    opcResultsDic.Add(strGrp, oDic);
                }
            }
            catch (Exception ee)
            {
                LogImpl.Error("plc初始化:" + ee.StackTrace);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 初始化读卡器
        /// </summary>
        private void InitReader()
        {
            iportAdr = int.Parse(System.Configuration.ConfigurationManager.AppSettings["DoorAdr"]);
            byte bytComAdr = 0x02;
            byte bytBaud   = 0x5;

            try
            {
                Thread thread = new Thread(() =>
                {
                    int iResult = StaticClassReaderB.OpenComPort(iportAdr, ref bytComAdr, bytBaud, ref portOpenHandle);
                    if (iResult == 0)
                    {
                        Inventory();
                    }
                });
                thread.IsBackground = true;
                thread.Start();
            }
            catch (Exception ex)
            {
                LogImpl.Error(string.Format("{0}{2}{1}", ex.StackTrace, ex.Message, System.Environment.NewLine));
            }
        }