Пример #1
0
        private async Task <bool> UpdateParameterValue(int nodeId, ushort index, byte subIndex, ParameterValue actualValue)
        {
            bool result = false;

            try
            {
                var parameterUpdate = new ParameterValueUpdate
                {
                    ChannelId      = Channel.Id,
                    NodeId         = nodeId,
                    ParameterValue = actualValue,
                    Index          = index,
                    SubIndex       = subIndex
                };

                var path = $"api/parameter/value";

                var json = parameterUpdate.ToJson();

                var response = await Transporter.Put(_identity, Url, path, json);

                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        MsgLogger.WriteDebug($"{GetType().Name} - UpdateParameterValue", $"Device Node id = {nodeId}, Parameter Index = 0x{index:X4}, Subindex = 0x{subIndex} value successfully written");

                        result = true;
                    }
                    else
                    {
                        MsgLogger.WriteError($"{GetType().Name} - UpdateParameterValue", $"Device Node id = {nodeId}, Parameter Index = 0x{index:X4}, Subindex = 0x{subIndex} value write failed, status code = {response.StatusCode}!");
                    }
                }
                else
                {
                    MsgLogger.WriteError($"{GetType().Name} - UpdateParameterValue", $"Device Node id = {nodeId}, Parameter Index = 0x{index:X4}, Subindex = 0x{subIndex} value write failed!");
                }
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
Пример #2
0
 /// <summary>
 /// ToJson
 /// </summary>
 /// <param name="update"></param>
 /// <returns></returns>
 public static string ToJson(this ParameterValueUpdate update)
 {
     return(JsonSerializer.Serialize(update));
 }