Esempio n. 1
0
        public bool AddOrModifyAuthority(Controller controller, string hexCardNum, DateTime startTime, DateTime endTime, Dictionary <int, int> doorNumAuthorities, int password = 0)
        {
            WGPacket packet = new WGPacket(0x50);

            packet.SetDevSn(controller.sn);
            // hexCardNum = DataHelper.ToWGAccessCardNo(hexCardNum);
            packet.SetCardNum(hexCardNum);
            packet.SetAuthoriTimeTime(startTime, endTime);
            if (controller.doorType == ControllerDoorType.Elevator)
            {
                packet.SetAuthoriElevator(doorNumAuthorities);
            }
            else
            {
                packet.SetAuthoriDoors(doorNumAuthorities);
            }

            packet.SetAuthoriPassword(password);

            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 2
0
        public bool SetSuperPwds(Controller controller, int doorIndex, List <string> pwds)
        {
            WGPacket packet = new WGPacket(0x8C);

            packet.SetDevSn(controller.sn);
            packet.SetDoorNum(doorIndex);
            try
            {
                packet.SetSuperPwds(pwds);
            }
            catch (Exception ex)
            {
                log.Error("密码转换发生异常:", ex);
                return(false);
            }

            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 3
0
        public List <Controller> SearchController()
        {
            List <Controller> list = new List <Controller>();

            try
            {
                WGPacket packet = new WGPacket(0x94);
                if (DoSend(packet))
                {
                    List <byte[]> dics = this.RecieveFrom(64);
                    if (dics.Count > 0)
                    {
                        foreach (var item in dics)
                        {
                            WGPacket   p    = ToWGPacket(item);
                            Controller ctrl = p.ToController();
                            ctrl.port = 60000;
                            if (ctrl != null)
                            {
                                list.Add(ctrl);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                this.Close();
            }
            return(list);
        }
Esempio n. 4
0
 public bool AddTimeTask(Controller controller, TimeTask task)
 {
     try
     {
         WGPacket packet = new WGPacket(0xA8);
         packet.SetDevSn(controller.sn);
         packet.SetTimeTask(task);
         bool ret = true;
         foreach (var item in task.doorIndexs)
         {
             if (item < 1 || item > 4)
             {
                 continue;
             }
             packet.SetTimeTaskDoorIndex(item);
             DoSend(packet, controller.ip, controller.port);
             List <WGPacket> packets = WGRecievePacket(1);
             if (packets.Count == 1)
             {
                 ret = ret && (packets[0].data[0] == 1);
             }
         }
         return(ret);
     }
     finally
     {
         this.Close();
     }
 }
Esempio n. 5
0
        public void SetControllerIP(Controller controller)
        {
            WGPacket packet = new WGPacket(0x96);

            packet.SetControllerIP(controller);
            DoSend(packet, controllerPort: controller.port);
            Close();
        }
Esempio n. 6
0
        public static WGPacket ToWGPacket(byte[] buffer)
        {
            IntPtr ptr = Marshal.AllocHGlobal(64);

            Marshal.Copy(buffer, 0, ptr, 64);
            WGPacket p = (WGPacket)Marshal.PtrToStructure(ptr, typeof(WGPacket));

            Marshal.FreeHGlobal(ptr);
            return(p);
        }
Esempio n. 7
0
        public DateTime GetControllerTime(Controller controller)
        {
            WGPacket packet = new WGPacket(0x32);

            packet.SetDevSn(controller.sn);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].ToDateTime());
            }
            return(DateTime.Now);
        }
Esempio n. 8
0
        public ControllerState GetControllerState(Controller controller)
        {
            WGPacket packet = new WGPacket(0x20);

            packet.SetDevSn(controller.sn);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].ToControllerState());
            }
            return(null);
        }
Esempio n. 9
0
        public long GetControllerReadedIndex(Controller controller)
        {
            WGPacket packet = new WGPacket(0xB4);

            packet.SetDevSn(controller.sn);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].GetRecordIndex());
            }
            return(-1);
        }
Esempio n. 10
0
        public bool SetHoliday(Controller controller, HolidayPrm holiday)
        {
            WGPacket packet = new WGPacket(0xCC);

            packet.SetDevSn(controller.sn);
            packet.SetHoliday(holiday);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 11
0
        public bool ClearTimeTask(Controller controller)
        {
            WGPacket packet = new WGPacket(0xA6);

            packet.SetDevSn(controller.sn);
            packet.SetClearTag();
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 12
0
        public bool SetTimeScales(Controller controller, TimeScaleNum tsNum)
        {
            WGPacket packet = new WGPacket(0x88);

            packet.SetDevSn(controller.sn);
            packet.SetTimeScale(tsNum);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 13
0
        public bool GetReceiveServer(Controller controller, ref string ip, ref int port)
        {
            WGPacket packet = new WGPacket(0x92);

            packet.SetDevSn(controller.sn);

            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].GetReceiveServer(ref ip, ref port));
            }
            return(false);
        }
Esempio n. 14
0
        public bool SetRecordButtonRecords(Controller controller, bool record)
        {
            WGPacket packet = new WGPacket(0x8E);

            packet.SetDevSn(controller.sn);
            packet.data[0] = record ? (byte)1 : (byte)0;
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 15
0
        public List <WGPacket> WGRecievePacket(int maxCount = -1)
        {
            List <byte[]>   dics = WGRecieveFrom(maxCount);
            List <WGPacket> list = new List <WGPacket>();

            if (dics.Count > 0)
            {
                foreach (var item in dics)
                {
                    WGPacket p = ToWGPacket(item);
                    list.Add(p);
                }
            }
            return(list);
        }
Esempio n. 16
0
        public bool SetAlarmConnectPortSetting(Controller controller, AlarmConnectPortSetting setting)
        {
            WGPacket packet = new WGPacket(0xC6);

            packet.SetDevSn(controller.sn);
            packet.SetAlarmConnectPortSetting(setting);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 17
0
        public bool OpenRemoteControllerDoor(Controller controller, int doorNum)
        {
            WGPacket packet = new WGPacket(0x40);

            packet.SetDevSn(controller.sn);
            packet.SetDoorNum(doorNum);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 18
0
        public ControllerState GetControllerRecord(Controller controller, long recordIndex)
        {
            WGPacket packet = new WGPacket(0xB0);

            packet.SetDevSn(controller.sn);
            packet.SetRecordIndex(recordIndex);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].ToControllerState(true));
            }
            return(null);
        }
Esempio n. 19
0
        public bool DeleteAuthority(Controller controller, string hexCardNum)
        {
            WGPacket packet = new WGPacket(0x52);

            packet.SetDevSn(controller.sn);
            //hexCardNum = DataHelper.ToWGAccessCardNo(hexCardNum);
            packet.SetCardNum(hexCardNum);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 20
0
        public bool SetControllerReadedIndex(Controller controller, long recordIndex)
        {
            WGPacket packet = new WGPacket(0xB2);

            packet.SetDevSn(controller.sn);
            packet.SetRecordIndex(recordIndex);
            packet.SetReadedIndexTag();
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }
Esempio n. 21
0
        public bool SetDoorControlStyle(Controller controller, int doorNum, DoorControlStyle ctrlStyle, int delaySecond = 3)
        {
            WGPacket packet = new WGPacket(0x80);

            packet.SetDevSn(controller.sn);
            packet.SetDoorNum(doorNum);
            packet.SetCtrlStyle(ctrlStyle, delaySecond);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] > 0);
            }
            return(false);
        }
Esempio n. 22
0
        private bool DoSend(WGPacket packet, string controllerIp = null, int controllerPort = 60000)
        {
            if (string.IsNullOrWhiteSpace(controllerIp))
            {
                BindPort(true);
                controllerIp = "255.255.255.255";
            }
            else
            {
                BindPort();
            }
            if (controllerPort <= 0)
            {
                controllerPort = 60000;
            }
            bool ret = this.SendTo(DataHelper.GetBytes(typeof(WGPacket), packet), controllerIp, controllerPort);

            return(ret);
        }
Esempio n. 23
0
        public bool SetControllerTime(Controller controller, DateTime dateTime)
        {
            WGPacket packet = new WGPacket(0x30);

            packet.SetDevSn(controller.sn);
            packet.SetDateTime(dateTime);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                DateTime dt = packets[0].ToDateTime();
                return(dt.Year == dateTime.Year &&
                       dt.Month == dateTime.Month &&
                       dt.Day == dateTime.Day &&
                       dt.Hour == dateTime.Hour &&
                       dt.Minute == dateTime.Minute &&
                       dt.Second == dateTime.Second);
            }
            return(false);
        }
Esempio n. 24
0
        public bool SetReceiveServer(Controller controller, string ip, int port)
        {
            WGPacket packet = new WGPacket(0x90);

            packet.SetDevSn(controller.sn);
            var bts = DataHelper.GetIPBytes(ip);

            if (bts == null)
            {
                return(false);
            }
            packet.SetRecieverIPAndPort(bts, port);
            DoSend(packet, controller.ip, controller.port);
            List <WGPacket> packets = WGRecievePacketAddClose(1);

            if (packets.Count == 1)
            {
                return(packets[0].data[0] == 1);
            }
            return(false);
        }