Ejemplo n.º 1
0
        public void AddReadOrder(FunctionCode functionCode, int quantity, int startingAddress, int cycleTime)
        {
            ReadOrder readOrder = new ReadOrder();

            readOrder.CylceTime       = cycleTime;
            readOrder.FunctionCode    = functionCode;
            readOrder.Quantity        = quantity;
            readOrder.StartingAddress = startingAddress;
            readOrder.Topic           = new string[quantity];
            readOrder.Retain          = new bool[quantity];
            readOrder.oldvalue        = new object[quantity];
            int index = 0;

            while (index < quantity)
            {
                if (functionCode == FunctionCode.ReadCoils)
                {
                    readOrder.Topic[index] = this.mqttRootTopic + "/coils/" + checked (index + readOrder.StartingAddress).ToString();
                }
                if (functionCode == FunctionCode.ReadDiscreteInputs)
                {
                    readOrder.Topic[index] = this.mqttRootTopic + "/discreteinputs/" + checked (index + readOrder.StartingAddress).ToString();
                }
                if (functionCode == FunctionCode.ReadHoldingRegisters)
                {
                    readOrder.Topic[index] = this.mqttRootTopic + "/holdingregisters/" + checked (index + readOrder.StartingAddress).ToString();
                }
                if (functionCode == FunctionCode.ReadInputRegisters)
                {
                    readOrder.Topic[index] = this.mqttRootTopic + "/inputregisters/" + checked (index + readOrder.StartingAddress).ToString();
                }
                checked { ++index; }
            }
            this.readOrders.Add(readOrder);
        }
Ejemplo n.º 2
0
        public void AddReadOrder(FunctionCode functionCode, int quantity, int startingAddress, int cycleTime)
        {
            ReadOrder readOrder = new ReadOrder();

            readOrder.CylceTime       = cycleTime;
            readOrder.FunctionCode    = functionCode;
            readOrder.Quantity        = quantity;
            readOrder.StartingAddress = startingAddress;
            readOrder.Topic           = new string[quantity];
            readOrder.oldvalue        = new object[quantity];
            for (int i = 0; i < quantity; i++)
            {
                if (functionCode == FunctionCode.ReadCoils)
                {
                    readOrder.Topic[i] = mqttRootTopic + "/coils/" + (i + readOrder.StartingAddress).ToString();
                }
                if (functionCode == FunctionCode.ReadDiscreteInputs)
                {
                    readOrder.Topic[i] = mqttRootTopic + "/discreteinputs/" + (i + readOrder.StartingAddress).ToString();
                }
                if (functionCode == FunctionCode.ReadHoldingRegisters)
                {
                    readOrder.Topic[i] = mqttRootTopic + "/holdingregisters/" + (i + readOrder.StartingAddress).ToString();
                }
                if (functionCode == FunctionCode.ReadInputRegisters)
                {
                    readOrder.Topic[i] = mqttRootTopic + "/inputregisters/" + (i + readOrder.StartingAddress).ToString();
                }
            }
            readOrders.Add(readOrder);
        }
Ejemplo n.º 3
0
        public void AddReadOrder(FunctionCode functionCode, int quantity, int startingAddress, int cycleTime, string[] topic)
        {
            ReadOrder readOrder = new ReadOrder();

            readOrder.FunctionCode    = functionCode;
            readOrder.Quantity        = quantity;
            readOrder.StartingAddress = startingAddress;
            readOrder.CylceTime       = cycleTime;
            readOrder.Topic           = topic;
            this.AddReadOrder(readOrder);
        }
Ejemplo n.º 4
0
 public void AddReadOrder(ReadOrder readOrder)
 {
     if (readOrder.FunctionCode == 0)
     {
         throw new ArgumentOutOfRangeException("FunctionCode must be initialized");
     }
     if (readOrder.Quantity == 0)
     {
         throw new ArgumentOutOfRangeException("Quantity cannot be 0");
     }
     if (readOrder.Topic != null)
     {
         if (readOrder.Topic.Length != readOrder.Quantity)
         {
             throw new ArgumentOutOfRangeException("Size of the Topic array must mach with quantity");
         }
     }
     if (readOrder.CylceTime == 0)
     {
         readOrder.CylceTime = 500;
     }
     if (readOrder.Topic == null)
     {
         readOrder.Topic = new string[readOrder.Quantity];
         for (int i = 0; i < readOrder.Quantity; i++)
         {
             if (readOrder.FunctionCode == FunctionCode.ReadCoils)
             {
                 readOrder.Topic[i] = mqttRootTopic + "/coils/" + (i + readOrder.StartingAddress).ToString();
             }
             if (readOrder.FunctionCode == FunctionCode.ReadDiscreteInputs)
             {
                 readOrder.Topic[i] = mqttRootTopic + "/discreteinputs/" + (i + readOrder.StartingAddress).ToString();
             }
             if (readOrder.FunctionCode == FunctionCode.ReadHoldingRegisters)
             {
                 readOrder.Topic[i] = mqttRootTopic + "/holdingregisters/" + (i + readOrder.StartingAddress).ToString();
             }
             if (readOrder.FunctionCode == FunctionCode.ReadInputRegisters)
             {
                 readOrder.Topic[i] = mqttRootTopic + "/inputregisters/" + (i + readOrder.StartingAddress).ToString();
             }
         }
     }
     readOrder.oldvalue = new object[readOrder.Quantity];
     readOrders.Add(readOrder);
 }
Ejemplo n.º 5
0
 public void AddReadOrder(ReadOrder readOrder)
 {
     if (readOrder.FunctionCode == (FunctionCode)0)
     {
         throw new ArgumentOutOfRangeException("FunctionCode must be initialized");
     }
     if (readOrder.Quantity == 0)
     {
         throw new ArgumentOutOfRangeException("Quantity cannot be 0");
     }
     if (readOrder.Topic != null && readOrder.Topic.Length != readOrder.Quantity)
     {
         throw new ArgumentOutOfRangeException("Size of the Topic array must mach with quantity");
     }
     if (readOrder.Retain != null && readOrder.Retain.Length != readOrder.Quantity)
     {
         throw new ArgumentOutOfRangeException("Size of the Retain array must mach with quantity");
     }
     if (readOrder.Hysteresis != null && readOrder.Hysteresis.Length != readOrder.Quantity)
     {
         throw new ArgumentOutOfRangeException("Size of the Hysteresis array must mach with quantity");
     }
     if (readOrder.Scale != null && readOrder.Scale.Length != readOrder.Quantity)
     {
         throw new ArgumentOutOfRangeException("Size of the Scale array must mach with quantity");
     }
     if (readOrder.Retain != null && readOrder.Retain.Length != readOrder.Quantity)
     {
         throw new ArgumentOutOfRangeException("Size of the Retain array must mach with quantity");
     }
     if (readOrder.CylceTime == 0)
     {
         readOrder.CylceTime = 500;
     }
     if (readOrder.Topic == null)
     {
         readOrder.Topic = new string[readOrder.Quantity];
         int index = 0;
         while (index < readOrder.Quantity)
         {
             if (readOrder.FunctionCode == FunctionCode.ReadCoils)
             {
                 readOrder.Topic[index] = this.mqttRootTopic + "/coils/" + checked (index + readOrder.StartingAddress).ToString();
             }
             if (readOrder.FunctionCode == FunctionCode.ReadDiscreteInputs)
             {
                 readOrder.Topic[index] = this.mqttRootTopic + "/discreteinputs/" + checked (index + readOrder.StartingAddress).ToString();
             }
             if (readOrder.FunctionCode == FunctionCode.ReadHoldingRegisters)
             {
                 readOrder.Topic[index] = this.mqttRootTopic + "/holdingregisters/" + checked (index + readOrder.StartingAddress).ToString();
             }
             if (readOrder.FunctionCode == FunctionCode.ReadInputRegisters)
             {
                 readOrder.Topic[index] = this.mqttRootTopic + "/inputregisters/" + checked (index + readOrder.StartingAddress).ToString();
             }
             checked { ++index; }
         }
     }
     readOrder.oldvalue = new object[readOrder.Quantity];
     this.readOrders.Add(readOrder);
 }
Ejemplo n.º 6
0
 private void ProcessData(object param)
 {
     while (!this.shouldStop)
     {
         try
         {
             if (!this.mqttClient.IsConnected)
             {
                 this.mqttClient = new MqttClient(this.mqttBrokerAddress, this.mqttBrokerPort, false, (X509Certificate)null, (X509Certificate)null, MqttSslProtocols.None);
                 string clientId = Guid.NewGuid().ToString();
                 if (this.MqttUserName == null || this.MqttPassword == null)
                 {
                     int num1 = (int)this.mqttClient.Connect(clientId);
                 }
                 else
                 {
                     int num2 = (int)this.mqttClient.Connect(clientId, this.MqttUserName, this.MqttPassword);
                 }
             }
         }
         catch (Exception ex)
         {
             if (!this.AutomaticReconnect)
             {
                 throw ex;
             }
         }
         ReadOrder readOrder = (ReadOrder)param;
         lock (this.lockProcessData)
         {
             try
             {
                 if (readOrder.FunctionCode == FunctionCode.ReadCoils)
                 {
                     bool[] flagArray = this.modbusClient.ReadCoils(readOrder.StartingAddress, readOrder.Quantity);
                     int    index     = 0;
                     while (index < flagArray.Length)
                     {
                         if (readOrder.oldvalue[index] == null)
                         {
                             int num1 = (int)this.mqttClient.Publish(readOrder.Topic[index], Encoding.UTF8.GetBytes(flagArray[index].ToString()), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                         }
                         else if ((bool)readOrder.oldvalue[index] != flagArray[index])
                         {
                             int num2 = (int)this.mqttClient.Publish(readOrder.Topic[index], Encoding.UTF8.GetBytes(flagArray[index].ToString()), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                         }
                         readOrder.oldvalue[index] = (object)flagArray[index];
                         checked { ++index; }
                     }
                 }
                 if (readOrder.FunctionCode == FunctionCode.ReadDiscreteInputs)
                 {
                     bool[] flagArray = this.modbusClient.ReadDiscreteInputs(readOrder.StartingAddress, readOrder.Quantity);
                     int    index     = 0;
                     while (index < flagArray.Length)
                     {
                         if (readOrder.oldvalue[index] == null)
                         {
                             int num1 = (int)this.mqttClient.Publish(readOrder.Topic[index], Encoding.UTF8.GetBytes(flagArray[index].ToString()), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                         }
                         else if ((bool)readOrder.oldvalue[index] != flagArray[index])
                         {
                             int num2 = (int)this.mqttClient.Publish(readOrder.Topic[index], Encoding.UTF8.GetBytes(flagArray[index].ToString()), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                         }
                         readOrder.oldvalue[index] = (object)flagArray[index];
                         checked { ++index; }
                     }
                 }
                 if (readOrder.FunctionCode == FunctionCode.ReadHoldingRegisters)
                 {
                     int[] numArray = this.modbusClient.ReadHoldingRegisters(readOrder.StartingAddress, readOrder.Quantity);
                     int   index    = 0;
                     while (index < numArray.Length)
                     {
                         float num1 = readOrder.Scale != null ? ((double)readOrder.Scale[index] == 0.0 ? 1f : readOrder.Scale[index]) : 1f;
                         if (readOrder.oldvalue[index] == null)
                         {
                             int num2 = (int)this.mqttClient.Publish(readOrder.Topic[index], readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)numArray[index] * num1).ToString()) : Encoding.UTF8.GetBytes(((double)numArray[index] * (double)num1).ToString() + " " + readOrder.Unit[index]), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                             readOrder.oldvalue[index] = (object)numArray[index];
                         }
                         else if ((int)readOrder.oldvalue[index] != numArray[index] && (readOrder.Hysteresis == null || numArray[index] < checked ((int)readOrder.oldvalue[index] - readOrder.Hysteresis[index]) | numArray[index] > checked ((int)readOrder.oldvalue[index] + readOrder.Hysteresis[index])))
                         {
                             int num2 = (int)this.mqttClient.Publish(readOrder.Topic[index], readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)numArray[index] * num1).ToString()) : Encoding.UTF8.GetBytes(((float)numArray[index] * num1).ToString() + " " + readOrder.Unit[index]), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                             readOrder.oldvalue[index] = (object)numArray[index];
                         }
                         checked { ++index; }
                     }
                 }
                 if (readOrder.FunctionCode == FunctionCode.ReadInputRegisters)
                 {
                     int[] numArray = this.modbusClient.ReadInputRegisters(readOrder.StartingAddress, readOrder.Quantity);
                     int   index    = 0;
                     while (index < numArray.Length)
                     {
                         float num1 = readOrder.Scale != null ? ((double)readOrder.Scale[index] == 0.0 ? 1f : readOrder.Scale[index]) : 1f;
                         if (readOrder.oldvalue[index] == null)
                         {
                             int num2 = (int)this.mqttClient.Publish(readOrder.Topic[index], readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)numArray[index] * num1).ToString()) : Encoding.UTF8.GetBytes(((float)numArray[index] * num1).ToString() + " " + readOrder.Unit[index]), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                             readOrder.oldvalue[index] = (object)numArray[index];
                         }
                         else if ((int)readOrder.oldvalue[index] != numArray[index] && (readOrder.Hysteresis == null || numArray[index] < checked ((int)readOrder.oldvalue[index] - readOrder.Hysteresis[index]) | numArray[index] > checked ((int)readOrder.oldvalue[index] + readOrder.Hysteresis[index])))
                         {
                             int num2 = (int)this.mqttClient.Publish(readOrder.Topic[index], readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)numArray[index] * num1).ToString()) : Encoding.UTF8.GetBytes(((float)numArray[index] * num1).ToString() + " " + readOrder.Unit[index]), (byte)2, readOrder.Retain != null && readOrder.Retain[index]);
                             readOrder.oldvalue[index] = (object)numArray[index];
                         }
                         checked { ++index; }
                     }
                 }
             }
             catch (Exception ex1)
             {
                 this.modbusClient.Disconnect();
                 Thread.Sleep(2000);
                 if (!this.AutomaticReconnect)
                 {
                     throw ex1;
                 }
                 Debug.WriteLine(ex1.StackTrace);
                 if (!this.modbusClient.Connected)
                 {
                     try
                     {
                         this.modbusClient.Connect();
                     }
                     catch (Exception ex2)
                     {
                     }
                 }
             }
         }
         Thread.Sleep(readOrder.CylceTime);
     }
 }
Ejemplo n.º 7
0
        private void ProcessData(object param)
        {
            while (!shouldStop)
            {
                ReadOrder readOrder = (ReadOrder)param;
                lock (lockProcessData)
                {
                    if (readOrder.FunctionCode == FunctionCode.ReadCoils)
                    {
                        bool[] value = modbusClient.ReadCoils(readOrder.StartingAddress, readOrder.Quantity);
                        for (int i = 0; i < value.Length; i++)
                        {
                            if (readOrder.oldvalue[i] == null)
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            else if ((bool)readOrder.oldvalue[i] != value[i])
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            readOrder.oldvalue[i] = value[i];
                        }
                    }
                    if (readOrder.FunctionCode == FunctionCode.ReadDiscreteInputs)
                    {
                        bool[] value = modbusClient.ReadDiscreteInputs(readOrder.StartingAddress, readOrder.Quantity);
                        for (int i = 0; i < value.Length; i++)
                        {
                            if (readOrder.oldvalue[i] == null)
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            else if ((bool)readOrder.oldvalue[i] != value[i])
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            readOrder.oldvalue[i] = value[i];
                        }
                    }
                    if (readOrder.FunctionCode == FunctionCode.ReadHoldingRegisters)
                    {
                        int[] value = modbusClient.ReadHoldingRegisters(readOrder.StartingAddress, readOrder.Quantity);
                        for (int i = 0; i < value.Length; i++)
                        {
                            if (readOrder.oldvalue[i] == null)
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            else if ((int)readOrder.oldvalue[i] != value[i])
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            readOrder.oldvalue[i] = value[i];
                        }
                    }

                    if (readOrder.FunctionCode == FunctionCode.ReadInputRegisters)
                    {
                        int[] value = modbusClient.ReadInputRegisters(readOrder.StartingAddress, readOrder.Quantity);
                        for (int i = 0; i < value.Length; i++)
                        {
                            if (readOrder.oldvalue[i] == null)
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            else if ((int)readOrder.oldvalue[i] != value[i])
                            {
                                mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            }
                            readOrder.oldvalue[i] = value[i];
                        }
                    }
                }
                System.Threading.Thread.Sleep(readOrder.CylceTime);
            }
        }
Ejemplo n.º 8
0
        private void ProcessData(object param)
        {
            while (!shouldStop)
            {
                try
                {
                    if (!mqttClient.IsConnected)
                    {
                        mqttClient = new uPLibrary.Networking.M2Mqtt.MqttClient(mqttBrokerAddress, mqttBrokerPort, false, null, null, uPLibrary.Networking.M2Mqtt.MqttSslProtocols.None);
                        string clientID = Guid.NewGuid().ToString();
                        if (MqttUserName == null || MqttPassword == null)
                        {
                            mqttClient.Connect(clientID);
                        }
                        else
                        {
                            mqttClient.Connect(clientID, MqttUserName, MqttPassword);
                        }
                    }
                }
                catch (Exception exc)
                {
                    if (!this.AutomaticReconnect)
                    {
                        throw exc;
                    }
                }
                ReadOrder readOrder = (ReadOrder)param;
                lock (lockProcessData)
                {
                    try
                    {
                        if (readOrder.FunctionCode == FunctionCode.ReadCoils)
                        {
                            bool[] value = modbusClient.ReadCoils(readOrder.StartingAddress, readOrder.Quantity);
                            for (int i = 0; i < value.Length; i++)
                            {
                                if (readOrder.oldvalue[i] == null)
                                {
                                    mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                }
                                else if ((bool)readOrder.oldvalue[i] != value[i])
                                {
                                    mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                }
                                readOrder.oldvalue[i] = value[i];
                            }
                        }
                        if (readOrder.FunctionCode == FunctionCode.ReadDiscreteInputs)
                        {
                            bool[] value = modbusClient.ReadDiscreteInputs(readOrder.StartingAddress, readOrder.Quantity);
                            for (int i = 0; i < value.Length; i++)
                            {
                                if (readOrder.oldvalue[i] == null)
                                {
                                    mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                }
                                else if ((bool)readOrder.oldvalue[i] != value[i])
                                {
                                    mqttClient.Publish(readOrder.Topic[i], Encoding.UTF8.GetBytes(value[i].ToString()), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                }
                                readOrder.oldvalue[i] = value[i];
                            }
                        }
                        if (readOrder.FunctionCode == FunctionCode.ReadHoldingRegisters)
                        {
                            int[] value = modbusClient.ReadHoldingRegisters(readOrder.StartingAddress, readOrder.Quantity);
                            for (int i = 0; i < value.Length; i++)
                            {
                                float scale = readOrder.Scale != null ? (readOrder.Scale[i] == 0) ? 1 : readOrder.Scale[i] : 1;
                                if (readOrder.oldvalue[i] == null)
                                {
                                    mqttClient.Publish(readOrder.Topic[i], (readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)value[i] * scale).ToString()) : Encoding.UTF8.GetBytes(((float)value[i] * scale) + " " + readOrder.Unit[i])), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                    readOrder.oldvalue[i] = value[i];
                                }
                                else if (((int)readOrder.oldvalue[i] != value[i]) && (readOrder.Hysteresis != null ? ((value[i] < (int)readOrder.oldvalue[i] - (int)readOrder.Hysteresis[i]) | (value[i] > (int)readOrder.oldvalue[i] + (int)readOrder.Hysteresis[i])) : true))
                                {
                                    mqttClient.Publish(readOrder.Topic[i], (readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)value[i] * scale).ToString()) : Encoding.UTF8.GetBytes(((float)value[i] * scale).ToString() + " " + readOrder.Unit[i])), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                    readOrder.oldvalue[i] = value[i];
                                }
                            }
                        }

                        if (readOrder.FunctionCode == FunctionCode.ReadInputRegisters)
                        {
                            int[] value = modbusClient.ReadInputRegisters(readOrder.StartingAddress, readOrder.Quantity);
                            for (int i = 0; i < value.Length; i++)
                            {
                                float scale = readOrder.Scale != null ? (readOrder.Scale[i] == 0) ? 1 : readOrder.Scale[i] : 1;
                                if (readOrder.oldvalue[i] == null)
                                {
                                    mqttClient.Publish(readOrder.Topic[i], (readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)value[i] * scale).ToString()) : Encoding.UTF8.GetBytes(((float)value[i] * scale).ToString() + " " + readOrder.Unit[i])), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                    readOrder.oldvalue[i] = value[i];
                                }
                                else if (((int)readOrder.oldvalue[i] != value[i]) && (readOrder.Hysteresis != null ? ((value[i] < (int)readOrder.oldvalue[i] - (int)readOrder.Hysteresis[i]) | (value[i] > (int)readOrder.oldvalue[i] + (int)readOrder.Hysteresis[i])) : true))
                                {
                                    mqttClient.Publish(readOrder.Topic[i], (readOrder.Unit == null ? Encoding.UTF8.GetBytes(((float)value[i] * scale).ToString()) : Encoding.UTF8.GetBytes(((float)value[i] * scale).ToString() + " " + readOrder.Unit[i])), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, readOrder.Retain[i]);
                                    readOrder.oldvalue[i] = value[i];
                                }
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        modbusClient.Disconnect();
                        Thread.Sleep(2000);
                        if (!AutomaticReconnect)
                        {
                            throw exc;
                        }
                        if (!modbusClient.Connected)
                        {
                            try
                            {
                                modbusClient.Connect();
                            }
                            catch (Exception) { }
                        }
                    }
                }
                System.Threading.Thread.Sleep(readOrder.CylceTime);
            }
        }