コード例 #1
0
ファイル: clsWgInfo.cs プロジェクト: wollfman/ToolsManage
 public clsWgInfo()
 {
     if (wgController == null)
     {
         wgController = new wgMjController();
     }
 }
コード例 #2
0
ファイル: clsDoor.cs プロジェクト: wollfman/ToolsManage
        /// <summary>
        /// 获取门的状态 门号
        /// </summary>
        /// <param name="doorNo"></param>
        /// <returns></returns>
        public DoorsState GetDoorState(int doorNo)
        {
            DoorsState state = DoorsState.初值;

            if (wgController == null)
            {
                wgController = new wgMjController();
                wgController.ControllerSN = (int)intSn;
                wgController.PORT         = 60000;
                wgController.IP           = strIp;
            }
            if (wgController.GetMjControllerRunInformationIP() > 0) //取控制器信息
            {
                bool bl = wgController.RunInfo.IsOpen(doorNo);
                if (bl)
                {
                    state = DoorsState.关门;
                }
                else
                {
                    state = DoorsState.开门;
                }
            }
            else
            {
                state = DoorsState.通信;
            }
            return(state);
        }
コード例 #3
0
ファイル: Gate.cs プロジェクト: Cyuliang/ZBYGate_201810111245
        public Gate()
        {
            GetTimer = new System.Threading.Timer(GetStatus, null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));

            wgMjController1 = new wgMjController
            {
                IP           = Properties.Settings.Default.Gate_InDoorIp,
                PORT         = Properties.Settings.Default.Gate_Port,
                ControllerSN = Int32.Parse(Properties.Settings.Default.Gate_InDoorSN)
            };

            wgMjController2 = new wgMjController
            {
                IP           = Properties.Settings.Default.Gate_OutDoorIp,
                PORT         = Properties.Settings.Default.Gate_Port,
                ControllerSN = Int32.Parse(Properties.Settings.Default.Gate_OutDoorSN)
            };

            selectedControllers = new Dictionary <int, wgMjController>
            {
                { wgMjController1.ControllerSN, wgMjController1 },
                { wgMjController2.ControllerSN, wgMjController2 }
            };

            wgWatching = new wgWatchingService();
            wgWatching.EventHandler      += WgWatching_EventHandler;
            wgWatching.WatchingController = selectedControllers;
        }
コード例 #4
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // Serial Number
            int serialNumber = 0;

            foreach (string s in req.Headers.GetValues("X-M46-RFID-SN"))
            {
                serialNumber = int.Parse(s);
            }

            // IP
            string ip = "";

            foreach (string i in req.Headers.GetValues("X-M46-RFID-IP"))
            {
                ip = i;
            }

            // Port
            int port = 60000;

            foreach (string p in req.Headers.GetValues("X-M46-RFID-PORT"))
            {
                port = int.Parse(p);
            }

            var controller = new wgMjController
            {
                ControllerSN = serialNumber,
                IP           = ip,
                PORT         = port
            };

            dynamic data = await req.Content.ReadAsAsync <object>();

            string tag = data?.tag;

            bool success = false;

            await Task.Run(() =>
            {
                wgMjControllerPrivilege privilege = new wgMjControllerPrivilege();
                success = privilege.DelPrivilegeOfOneCardIP(controller.ControllerSN, controller.IP, controller.PORT, uint.Parse(tag)) > 0;
            });

            if (success)
            {
                return(req.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Tag removed" }));
            }
            else
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, "Unable to remove card, please try again..."));
            }
        }
コード例 #5
0
 /// <summary>
 /// 开闸动作
 /// </summary>
 /// <param name="SN"></param>
 /// <returns></returns>
 public static int OpenDoor(string Ip, int Port, string SN)
 {
     using (wgMjController wgMjController1 = new wgMjController())
     {
         wgMjController1.IP           = Ip;
         wgMjController1.PORT         = Port;
         wgMjController1.ControllerSN = Int32.Parse(SN);
         return(wgMjController1.RemoteOpenDoorIP(1));
     }
 }
コード例 #6
0
ファイル: clsDoor.cs プロジェクト: wollfman/ToolsManage
        private wgMjController wgController = null; //2011-11-15_23:50:42 要监控的控制器

        public clsDoor(string ip, uint sn)
        {
            strIp = ip;
            intSn = sn;

            wgController = new wgMjController();
            wgController.ControllerSN = (int)intSn;
            wgController.PORT         = 60000;
            wgController.IP           = strIp;
        }
コード例 #7
0
ファイル: clsWgInfo.cs プロジェクト: wollfman/ToolsManage
 /// <summary>
 /// 清除 微耕控制器类 及所控制的所有门
 /// </summary>
 public void Clear()
 {
     if (wgController != null)
     {
         wgController = null;
     }
     if (listDoor.Count > 0)
     {
         listDoor.Clear();
     }
 }
コード例 #8
0
        private wgMjController wgController = null; //2011-11-15_23:50:42 要监控的控制器

        public clsDoorBox(string ip, uint sn, string name, string area)
        {
            wgController = new wgMjController();
            wgController.ControllerSN = (int)sn;
            wgController.PORT         = 60000;
            wgController.IP           = ip;

            strIp      = ip;
            intSn      = sn;
            strBoxName = name;
            strArea    = area;
        }
コード例 #9
0
ファイル: BoxDoor.cs プロジェクト: wollfman/ToolsManage
        private wgMjController wgMjController = null; //2011-11-15_23:50:42 要监控的控制器

        public BoxDoor(string ip, int sn, string name, string area)
        {
            if (wgMjController == null)
            {
                wgMjController = new wgMjController();
                wgMjController.ControllerSN = sn;
                wgMjController.PORT         = 60000;
                wgMjController.IP           = ip;
            }
            strBoxName = name;
            strArea    = area;
        }
コード例 #10
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("Getting version...");

            // Serial Number
            int serialNumber = 0;

            foreach (string s in req.Headers.GetValues("X-M46-RFID-SN"))
            {
                serialNumber = int.Parse(s);
            }

            // IP
            string ip = "";

            foreach (string i in req.Headers.GetValues("X-M46-RFID-IP"))
            {
                ip = i;
            }

            // Port
            int port = 60000;

            foreach (string p in req.Headers.GetValues("X-M46-RFID-PORT"))
            {
                port = int.Parse(p);
            }

            var controller = new wgMjController
            {
                ControllerSN = serialNumber,
                IP           = ip,
                PORT         = port
            };

            bool success = false;

            await Task.Run(() =>
            {
                success = controller.GetMjControllerRunInformationIP() > 0;
            });

            if (success)
            {
                return(req.CreateResponse(HttpStatusCode.OK, new { version = controller.RunInfo.driverVersion }));
            }
            else
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Unable to get remote information"));
            }
        }
コード例 #11
0
        public void StartWatch()
        {
            if (listWg.Count <= 0)
            {
                return;
            }
            if (watching == null)
            {
                watching = new wgWatchingService();                              //加载监视服务
                watching.EventHandler += new OnEventHandler(evtNewInfoCallBack); //事件处理
            }
            timerWg.Stop();                                                      //停止刷新


            //选定要监控的控制表
            Dictionary <int, wgMjController> selectedControllers = new Dictionary <int, wgMjController>();

            int iCount = listWg.Count;

            for (int iIndex = 0; iIndex < iCount; iIndex++)
            {
                if (listWg[iIndex] != null)
                {
                    string strIp = listWg[iIndex].StrIp;
                    int    iSn   = (int)listWg[iIndex].IntSn;
                    if (!string.IsNullOrEmpty(strIp) && iSn != 0)
                    {
                        wgController = new wgMjController();
                        wgController.ControllerSN = iSn;
                        wgController.PORT         = 60000;
                        wgController.IP           = strIp;
                        selectedControllers.Add(wgController.ControllerSN, wgController);
                    }
                }
            }
            if (selectedControllers.Count > 0)
            {
                System.Diagnostics.Debug.WriteLine("selectedControllers.Count=" + selectedControllers.Count.ToString());
                watching.WatchingController = selectedControllers;

                //timerWg.Interval = 1000;
                timerWg.Start();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("selectedControllers.Count=" + selectedControllers.Count.ToString());
                watching.WatchingController = null;
                timerWg.Stop();
            }
        }
コード例 #12
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            // Serial Number
            int serialNumber = 0;

            foreach (string s in req.Headers.GetValues("X-M46-RFID-SN"))
            {
                serialNumber = int.Parse(s);
            }

            // IP
            string ip = "";

            foreach (string i in req.Headers.GetValues("X-M46-RFID-IP"))
            {
                ip = i;
            }

            // Port
            int port = 60000;

            foreach (string p in req.Headers.GetValues("X-M46-RFID-PORT"))
            {
                port = int.Parse(p);
            }

            var controller = new wgMjController
            {
                ControllerSN = serialNumber,
                IP           = ip,
                PORT         = port
            };

            bool success = false;

            await Task.Run(() =>
            {
                success = controller.RestoreAllSwipeInTheControllersIP() > 0;
            });

            if (success)
            {
                return(req.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Records restored" }));
            }
            else
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Unable restore"));
            }
        }
コード例 #13
0
ファイル: clsWgInfo.cs プロジェクト: wollfman/ToolsManage
        public clsWgInfo(string ip, int port, int sn)
        {
            if (wgController == null)
            {
                wgController = new wgMjController();
            }
            strIp   = ip;
            intPort = port;
            intSn   = sn;

            wgController              = new wgMjController();
            wgController.IP           = ip;
            wgController.PORT         = port;
            wgController.ControllerSN = sn;
        }
コード例 #14
0
        private void sbtnSearch_Click(object sender, EventArgs e)
        {
            lblCount.Text = "0";
            this.dgvFoundControllers.Rows.Clear();
            this.sbtnAlter.Enabled = false;

            System.Collections.ArrayList arrControllers = new System.Collections.ArrayList();

            using (wgMjController control = new wgMjController())
            {
                control.SearchControlers(ref arrControllers);
            }
            if (arrControllers != null)
            {
                if (arrControllers.Count <= 0)
                {
                    MessageBox.Show("Not Found");
                    this.sbtnAlter.Enabled = true;
                    return;
                }
                this.dgvFoundControllers.Rows.Clear();
                wgMjControllerConfigure conf;
                for (int i = 0; i < arrControllers.Count; i++)
                {
                    conf = (wgMjControllerConfigure)arrControllers[i];
                    string[] subItems = new string[] {
                        (this.dgvFoundControllers.Rows.Count + 1).ToString().PadLeft(4, '0'), //
                        conf.controllerSN.ToString(),                                         //SN
                        conf.ip.ToString(),                                                   //IP
                        conf.mask.ToString(),                                                 //"MASK",
                        conf.gateway.ToString(),                                              //"Gateway",
                        conf.port.ToString(),                                                 //"PORT"
                        conf.MACAddr,                                                         //MAC
                        conf.pcIPAddr                                                         //Note [pcIPAddr]
                    };
                    this.dgvFoundControllers.Rows.Add(subItems);
                }
            }
            this.sbtnSearch.Enabled = true;
            if (this.dgvFoundControllers.Rows.Count > 0)
            {
                this.sbtnAlter.Enabled = true;
            }
            lblCount.Text = this.dgvFoundControllers.Rows.Count.ToString();
        }
コード例 #15
0
ファイル: Gate.cs プロジェクト: Cyuliang/ZBYGate_201810111245
 /// <summary>
 /// 开闸动作
 /// </summary>
 /// <param name="SN"></param>
 /// <returns></returns>
 public void OpenDoor(string Ip, int Port, string SN)
 {
     using (wgMjController wgMjController1 = new wgMjController())
     {
         wgMjController1.IP           = Ip;
         wgMjController1.PORT         = Port;
         wgMjController1.ControllerSN = Int32.Parse(SN);
         if (wgMjController1.RemoteOpenDoorIP(1) > 0)
         {
             _Log.logInfo.Info(string.Format("Open {0} Door Success", SN));
             SetMessageAction?.Invoke(string.Format("Open {0} Door Success", SN));
         }
         else
         {
             _Log.logInfo.Info(string.Format("Open {0} Door Failed", SN));
             SetMessageAction?.Invoke(string.Format("Open {0} Door Failed", SN));
         }
     }
 }
コード例 #16
0
        protected override void OnStart(string[] args)
        {
            sw = new StreamWriter(this.fs);

            if (File.Exists(@"maps.txt"))
            {
                string[] maps = File.ReadAllLines(@"maps.txt");
                foreach (string map in maps)
                {
                    string[] ms = map.Split('=');
                    ctrlmaps[ms[0]] = ms[1];
                }
            }
            else
            {
                sw.WriteLine("no maps.txt file");
            }

            Dictionary <int, wgMjController> controllers = new Dictionary <int, wgMjController>();

            string[] list = client.getController();

            foreach (string s in list)
            {
                string[] ss = s.Split(':');
                if (!ss[0].Trim().Equals(""))
                {
                    sw.WriteLine(s);
                    sw.Flush();

                    wgMjController ctrl = new wgMjController();
                    ctrl.IP           = ss[0].Trim();
                    ctrl.ControllerSN = System.Int32.Parse(ss[1].Trim());
                    ctrl.PORT         = 60000;
                    controllers.Add(ctrl.ControllerSN, ctrl);
                }
            }

            service.EventHandler      += new OnEventHandler(evtNewInfoCallBack);
            service.WatchingController = controllers;
        }
コード例 #17
0
        private void sbtnAlter_Click(object sender, EventArgs e)
        {
            if (this.dgvFoundControllers.SelectedRows.Count <= 0)
            {
                return;
            }
            using (frmDoorConfig frm = new frmDoorConfig())
            {
                DataGridViewRow dgvdr = this.dgvFoundControllers.SelectedRows[0];

                frm.strSN      = dgvdr.Cells["f_ControllerSN"].Value.ToString();
                frm.strMac     = dgvdr.Cells["f_MACAddr"].Value.ToString();
                frm.strIP      = dgvdr.Cells["f_IP"].Value.ToString();
                frm.strMask    = dgvdr.Cells["f_Mask"].Value.ToString();
                frm.strGateway = dgvdr.Cells["f_Gateway"].Value.ToString();
                frm.strTCPPort = dgvdr.Cells["f_PORT"].Value.ToString();
                string pcIPAddr = "";
                if (dgvdr.Cells["f_PCIPAddr"].Value != null)
                {
                    pcIPAddr = dgvdr.Cells["f_PCIPAddr"].Value.ToString();
                }

                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    string strSN      = frm.strSN;
                    string strMac     = frm.strMac;
                    string strIP      = frm.strIP;
                    string strMask    = frm.strMask;
                    string strGateway = frm.strGateway;
                    string strTCPPort = frm.strTCPPort;
                    string strOperate = frm.Text;
                    this.Refresh();

                    Cursor.Current = Cursors.WaitCursor;
                    using (wgMjController control = new wgMjController())
                    {
                        control.NetIPConfigure(strSN, strMac, strIP, strMask, strGateway, strTCPPort, pcIPAddr);
                    }
                }
            }
        }
コード例 #18
0
ファイル: clsDoor.cs プロジェクト: wollfman/ToolsManage
        /// <summary>
        /// 开门 门号
        /// </summary>
        /// <param name="iDoorNo"></param>
        /// <returns></returns>
        public bool OpenDoor(int iDoorNo)
        {
            if (wgController == null)
            {
                wgController = new wgMjController();
                wgController.ControllerSN = (int)intSn;
                wgController.PORT         = 60000;
                wgController.IP           = strIp;
            }
            bool blRet = false;

            if (wgController.RemoteOpenDoorIP(1) > 0)
            {
                blRet = true;
            }
            else
            {
                blRet = false;
            }
            return(blRet);
        }
コード例 #19
0
        protected void OnStart()
        {
            string uuid = Guid.NewGuid().ToString();

            try
            {
                sw = new StreamWriter(this.fs);

                Dictionary <int, wgMjController> controllers = new Dictionary <int, wgMjController>();
                GetControllerListRequest         r           = new GetControllerListRequest();
                Controller[] list = websvc.GetControllerList(r);
                if (list != null)
                {
                    foreach (Controller s in list)
                    {
                        log(uuid, "控制器: " + s.sn + " " + s.ip);
                        sw.Flush();

                        wgMjController ctrl = new wgMjController();
                        ctrl.ControllerSN = System.Int32.Parse(s.sn);
                        ctrl.IP           = s.ip;
                        ctrl.PORT         = 60000;
                        controllers.Add(ctrl.ControllerSN, ctrl);
                    }
                }
                else
                {
                    log(uuid, "异常: 请求控制器列表返回null");
                }

                service.EventHandler      += new OnEventHandler(evtNewInfoCallBack);
                service.WatchingController = controllers;
            }
            catch (Exception e)
            {
                log(uuid, "异常: " + e.Message);
            }
        }
コード例 #20
0
ファイル: clsWgRunWatch.cs プロジェクト: wollfman/ToolsManage
 /// <summary>
 /// 清除所有 类
 /// </summary>
 public void DisposeAndClear()
 {
     try
     {
         if (timerWg != null)
         {
             if (timerWg.State == TimerState.Running)
             {
                 timerWg.Stop();
                 Thread.Sleep(1100);
             }
             timerWg = null;
         }
         if (commonCls != null)
         {
             commonCls = null;
         }
         if (listWg.Count > 0)
         {
             listWg.Clear();// watching
         }
         if (wgController != null)
         {
             wgController = null;
         }
         if (watching != null)
         {
             watching = null;
         }
     }
     catch (Exception ex)
     {
         if (frmMain.blDebug)
         {
             MessageUtil.ShowTips(ex.Message);
         }
     }
 }
コード例 #21
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // Serial Number
            int serialNumber = 0;

            foreach (string s in req.Headers.GetValues("X-M46-RFID-SN"))
            {
                serialNumber = int.Parse(s);
            }

            // IP
            string ip = "";

            foreach (string i in req.Headers.GetValues("X-M46-RFID-IP"))
            {
                ip = i;
            }

            // Port
            int port = 60000;

            foreach (string p in req.Headers.GetValues("X-M46-RFID-PORT"))
            {
                port = int.Parse(p);
            }

            var controller = new wgMjController
            {
                ControllerSN = serialNumber,
                IP           = ip,
                PORT         = port
            };

            MjRegisterCard card = new MjRegisterCard();

            dynamic data = await req.Content.ReadAsAsync <object>();

            card.CardID   = data?.tag;
            card.Password = 123456;
            card.ymdStart = DateTime.Now;
            card.ymdEnd   = card.ymdStart.AddYears(10);
            card.ControlSegIndexSet(1, 1);
            card.ControlSegIndexSet(2, 1);
            card.ControlSegIndexSet(3, 1);
            card.ControlSegIndexSet(4, 1);


            bool success = false;

            await Task.Run(() =>
            {
                wgMjControllerPrivilege privilege = new wgMjControllerPrivilege();
                success = privilege.AddPrivilegeOfOneCardIP(controller.ControllerSN, controller.IP, controller.PORT, card) > 0;
            });

            if (success)
            {
                return(req.CreateResponse(HttpStatusCode.Created, new { success = true, message = $"Tag ({card.CardID}) added" }));
            }
            else
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, "Unable to save card, please try again..."));
            }
        }
コード例 #22
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("Getting swipe records");

            // Serial Number
            int serialNumber = 0;

            foreach (string s in req.Headers.GetValues("X-M46-RFID-SN"))
            {
                serialNumber = int.Parse(s);
            }

            // IP
            string ip = "";

            foreach (string i in req.Headers.GetValues("X-M46-RFID-IP"))
            {
                ip = i;
            }

            // Port
            int port = 60000;

            foreach (string p in req.Headers.GetValues("X-M46-RFID-PORT"))
            {
                port = int.Parse(p);
            }

            var controller = new wgMjController
            {
                ControllerSN = serialNumber,
                IP           = ip,
                PORT         = port
            };

            DataTable dtSwipeRecords = new DataTable("SwipeRecords");

            dtSwipeRecords.Columns.Add("f_Index", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_ReadDate", System.Type.GetType("System.DateTime"));
            dtSwipeRecords.Columns.Add("f_CardNO", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_DoorNO", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_InOut", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_ReaderNO", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_EventCategory", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_ReasonNo", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_ControllerSN", System.Type.GetType("System.UInt32"));
            dtSwipeRecords.Columns.Add("f_RecordAll", System.Type.GetType("System.String"));

            var passes = new List <Pass>();

            int num = -1;

            await Task.Run(() =>
            {
                using (wgMjControllerSwipeOperate swipe4GetRecords = new wgMjControllerSwipeOperate())
                {
                    swipe4GetRecords.Clear();
                    num = swipe4GetRecords.GetSwipeRecords(controller.ControllerSN, controller.IP, controller.PORT, ref dtSwipeRecords);
                }
                Console.WriteLine($"Got {num} records");

                if (num > 0)
                {
                    wgMjControllerSwipeRecord mjrec = new wgMjControllerSwipeRecord();
                    for (int i = 0; i < num; i++)
                    {
                        mjrec.Update(dtSwipeRecords.Rows[i]["f_RecordAll"] as string);
                        log.Info(mjrec.CardID.ToString());
                        var pass = new Pass
                        {
                            id           = (int)mjrec.CardID,
                            readerNumber = mjrec.DoorNo,
                            readDate     = mjrec.ReadDate,
                            direction    = mjrec.IsEnterIn ? "in" : "out"
                        };
                        passes.Add(pass);
                    }
                }
            });

            if (num < 0)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, "Unable to get records"));
            }

            return(req.CreateResponse(HttpStatusCode.OK, passes, JsonMediaTypeFormatter.DefaultMediaType));
        }