| | |
| | | Gateway?.Send("DeviceControl", jObject.ToString()); |
| | | } |
| | | |
| | | #region 设置开合帘电机方向. |
| | | /// <summary> |
| | | /// 设置开合帘电机方向 |
| | | /// <para>isDirectionReversed (false:电机方向正向;true:电机方向反向;)</para> . |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetCurtainDirectionAsync(bool isDirectionReversed) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | SetWritableValueResponAllData d = null; |
| | | Action<string, string> action = (topic, message) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "SetWritableValue_Respon") |
| | | { |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SetWritableValueResponAllData { setWritableValueResponData = tempData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | int attributeData = 0; |
| | | int bit0 = 0;
|
| | | if (isDirectionReversed) |
| | | { |
| | | bit0 = 1; |
| | | }
|
| | | attributeData = bit0 * 1; |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } }; |
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } }; |
| | | jObject.Add("Data", data);
|
| | | Gateway.Send("SetWritableValue", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (d != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region 设置开合帘维护模式 |
| | | /// <summary> |
| | | /// 设置开合帘维护模式 |
| | | /// <para>isMotorMaintenance (fasle:电机运转正常;true:电机在维修模式下运行;)</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetCurtianMaintenanceAsync(bool isMotorMaintenance) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | SetWritableValueResponAllData d = null; |
| | | Action<string, string> action = (topic, message) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "SetWritableValue_Respon") |
| | | { |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SetWritableValueResponAllData { setWritableValueResponData = tempData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | int attributeData = 0;
|
| | | int bit2 = 0;
|
| | |
|
| | | if (isMotorMaintenance) |
| | | { |
| | | bit2 = 1; |
| | | } |
| | | attributeData = bit2 * 4; |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } }; |
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } }; |
| | | jObject.Add("Data", data);
|
| | | Gateway.Send("SetWritableValue", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (d != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region 设置开合帘限位参数. |
| | | /// <summary> |
| | | /// 设置开合帘上下限位 |