黄学彪
2019-12-12 7e863a33397f317ffc3ffd9288496d0e4f16aa66
ZigbeeApp/Shared/Common/Device.cs
@@ -107,8 +107,14 @@
            List<string> listFile = this.GetAllDeviceFile();
            foreach (string file in listFile)
            {
                CommonDevice device = null;
                //反序列化为指定的类,不然数据会丢失而导致无法强转
                var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file);
                try
                {
                    device = CommonDevice.CommonDeviceByFilePath(file);
                }
                catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
                if (device == null || device.CurrentGateWayId == null)
                {
#if DEBUG
@@ -1745,53 +1751,61 @@
            int receiveCount = 0;
            //设备列表
            var listDevice = new List<CommonDevice>();
            //网关里面有可能会有重复的回路
            var listCheck = new HashSet<string>();
            Action<string, string> getDeviceAction = (topic, message) =>
            {
                try
                if (topic == gatewayID + "/" + "DeviceInfoRespon")
                {
                    if (topic == gatewayID + "/" + "DeviceInfoRespon")
                    try
                    {
                        TimeOut = 0;
                        var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                        var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
                        if (totalNum == 0)
                        lock (listDevice)
                        {
                            //这个网关没有设备
                            canBreak = true;
                            return;
                        }
                        if (deviceCount == -1)
                        {
                            //设置需要接收多少个设备
                            deviceCount = totalNum;
                        }
                        //设备接收数
                        receiveCount++;
                            //设备接收数
                            receiveCount++;
                        var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
                        //根据设备类型创建设备对象的实例
                        var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
                        if (device != null)
                        {
                            try
                            TimeOut = 0;
                            var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                            var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
                            if (totalNum == 0)
                            {
                                //回调函数
                                deviceComingAction?.Invoke(device);
                                //这个网关没有设备
                                canBreak = true;
                                return;
                            }
                            //Log出力
                            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
                            if (deviceCount == -1)
                            {
                                //设置需要接收多少个设备
                                deviceCount = totalNum;
                            }
                            listDevice.Add(device);
                        }
                        if (deviceCount == receiveCount)
                        {
                            //设备全部接收完成
                            canBreak = true;
                            var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
                            //根据设备类型创建设备对象的实例
                            var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
                            if (device != null)
                            {
                                string mainkeys = this.GetDeviceMainKeys(device);
                                //网关里面有可能会有重复的回路
                                if (listCheck.Contains(mainkeys) == false)
                                {
                                    //回调函数
                                    deviceComingAction?.Invoke(device);
                                    listDevice.Add(device);
                                    listCheck.Add(mainkeys);
                                }
                            }
                        }
                    }
                    //Log出力
                    catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
                    if (receiveCount == deviceCount && deviceCount != -1)
                    {
                        //设备全部接收完成
                        canBreak = true;
                    }
                }
                catch { }
            };
            realWay.Actions += getDeviceAction;
@@ -2258,7 +2272,7 @@
        /// </summary>
        AirSwitch = -4100,
        /// <summary>
        /// 微断云控制器 镜像id:4100
        /// 智能空开 镜像id:4100
        /// </summary>
        AirSwitch_CloudContr = 4100,