Esempio n. 1
0
        int?getData(DataType type, ModbusClient modbus, int adres)
        {
            int?dön = null;

            try
            {
                switch (type)
                {
                case DataType.Bool:
                    dön = Convert.ToInt32(modbus.ReadCoils(adres, 1).FirstOrDefault());
                    break;

                case DataType.Word:
                    dön = modbus.ReadHoldingRegisters(adres, 1).FirstOrDefault();
                    break;

                case DataType.DoubleWord:
                    dön = ModbusClient.ConvertRegistersToInt(modbus.ReadHoldingRegisters(adres, 2));
                    break;

                case DataType.RaporBiti:
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(dön);
        }
Esempio n. 2
0
        public void read()
        {
            try
            {
                if (type == "WORD HOLDING")
                {
                    reg = modbusClient.ReadHoldingRegisters(registr_number, 1);
                    num = reg[0];
                }
                if (type == "INT HOLDING")
                {
                    reg = modbusClient.ReadHoldingRegisters(registr_number, 2);
                    num = ModbusClient.ConvertRegistersToInt(reg);
                }
                if (type == "REAL HOLDING")
                {
                    reg = modbusClient.ReadHoldingRegisters(registr_number, 2);
                    num = ModbusClient.ConvertRegistersToFloat(reg);
                }

                if (type == "WORD INPUT")
                {
                    reg = modbusClient.ReadInputRegisters(registr_number, 1);
                    num = reg[0];
                }
                if (type == "INT INPUT")
                {
                    reg = modbusClient.ReadInputRegisters(registr_number, 2);
                    num = ModbusClient.ConvertRegistersToInt(reg);
                }
                if (type == "REAL INPUT")
                {
                    reg = modbusClient.ReadInputRegisters(registr_number, 2);
                    num = ModbusClient.ConvertRegistersToFloat(reg);
                }

                if (type == "BOOL COIL")
                {
                    reg_bool = modbusClient.ReadCoils(registr_number, 1);
                    num      = reg_bool[0];
                }
                if (type == "BOOL INPUT")
                {
                    reg_bool = modbusClient.ReadDiscreteInputs(registr_number, 1);
                    num      = reg_bool[0];
                }
                Action action = () =>
                {
                    dataGrid.Rows[tag_number].Cells["value"].Value = num.ToString();
                };
                dataGrid.Invoke(action);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public override short readInt16(string var)
 {
     try
     {
         int[] readHoldingRegisters = this.client.ReadHoldingRegisters(int.Parse(var), 2);    //Read 10 Holding Registers from Server, starting with Address 1
         return((short)ModbusClient.ConvertRegistersToInt(readHoldingRegisters));
     } catch (Exception ex)
     {
         this.client.Disconnect();
         throw ex;
     }
 }
Esempio n. 4
0
        public void OdczytajRejestry()
        {
            ModbusClient modbusClient = new ModbusClient(PLC_IP, PLC_PORT);    //Ip-Address and Port of Modbus-TCP-Server

            modbusClient.Connect();

            CisnienieZadaneN1 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4512, 2));
            CisnienieZadaneN2 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4514, 2));
            CisnienieZadaneN3 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4516, 2));
            CisnienieZadaneN4 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4518, 2));

            TolerancjaCisnieniaN1 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4510, 2));
            TolerancjaCisnieniaN2 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4526, 2));
            TolerancjaCisnieniaN3 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4528, 2));
            TolerancjaCisnieniaN4 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4530, 2));

            CisnienieN1 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2000, 2));
            CisnienieN2 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2002, 2));
            CisnienieN3 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2004, 2));
            CisnienieN4 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2006, 2));

            CzasPomiaru_N1 = ModbusClient.ConvertRegistersToInt(modbusClient.ReadHoldingRegisters(4532, 2));

            PracaGrzalek = modbusClient.ReadCoils(1296, 1);

            PracaMieszadla = modbusClient.ReadCoils(1298, 1);

            Elektrozawor_N1 = modbusClient.ReadCoils(1298, 1);
            Elektrozawor_N2 = modbusClient.ReadCoils(1299, 1);
            Elektrozawor_N3 = modbusClient.ReadCoils(1300, 1);
            Elektrozawor_N4 = modbusClient.ReadCoils(1301, 1);

            TemperaturaZadana = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4506, 2));

            TolerancjaTemperatury = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4508, 2));

            Temperatura_T1     = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2008, 2));
            Temperatura_T2     = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2010, 2));
            TemperaturaSrednia = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2012, 2));

            GrzanieWody = modbusClient.ReadCoils(2248, 1);

            WodaNagrzana = modbusClient.ReadCoils(2251, 1);

            BadanieZasadnicze = modbusClient.ReadCoils(2249, 1);

            ProbkowanieCisnienia = modbusClient.ReadHoldingRegisters(4504, 1);

            ProbkowanieTemperatury = modbusClient.ReadHoldingRegisters(4505, 1);

            modbusClient.Disconnect();
        }
Esempio n. 5
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //var hosts = Pinger.PingAll("192.168.20.254");
            try
            {
                ModbusClient modbusClient = new ModbusClient("192.168.20.167", 502);    //Ip-Address and Port of Modbus-TCP-Server
                modbusClient.Connect();
                //int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(310, 2);

                float CisnienieZadaneN1 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4512, 2));
                float CisnienieZadaneN2 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4514, 2));
                float CisnienieZadaneN3 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4516, 2));
                float CisnienieZadaneN4 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4518, 2));

                txtCisnienieZadane_N1.Text = CisnienieZadaneN1.ToString();
                txtCisnienieZadane_N2.Text = CisnienieZadaneN2.ToString();
                txtCisnienieZadane_N3.Text = CisnienieZadaneN3.ToString();
                txtCisnienieZadane_N4.Text = CisnienieZadaneN4.ToString();

                float TolerancjaCisnienia_N1 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4510, 2));
                float TolerancjaCisnienia_N2 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4526, 2));
                float TolerancjaCisnienia_N3 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4528, 2));
                float TolerancjaCisnienia_N4 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4530, 2));

                txtCisnienieTolerancja_N1.Text = TolerancjaCisnienia_N1.ToString();
                txtCisnienieTolerancja_N2.Text = TolerancjaCisnienia_N2.ToString();
                txtCisnienieTolerancja_N3.Text = TolerancjaCisnienia_N3.ToString();
                txtCisnienieTolerancja_N4.Text = TolerancjaCisnienia_N4.ToString();

                float CisnienieN1 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2000, 2));
                float CisnienieN2 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2002, 2));
                float CisnienieN3 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2004, 2));
                float CisnienieN4 = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2006, 2));

                lblCisnienie_N1.Content = CisnienieN1.ToString();
                lblCisnienie_N2.Content = CisnienieN2.ToString();
                lblCisnienie_N3.Content = CisnienieN3.ToString();
                lblCisnienie_N4.Content = CisnienieN4.ToString();

                int CzasPomiaru_N1 = ModbusClient.ConvertRegistersToInt(modbusClient.ReadHoldingRegisters(4532, 2));

                txtCzasPomiaru_N1.Text = CzasPomiaru_N1.ToString();

                bool[] PracaGrzalek = modbusClient.ReadCoils(1296, 1);
                lblPracaGrzalek.Content = PracaGrzalek[0].ToString();

                bool[] PracaMieszadla = modbusClient.ReadCoils(1298, 1);
                lblPracaMieszadla.Content = PracaMieszadla[0].ToString();

                bool[] Elektrozawor_N1 = modbusClient.ReadCoils(1298, 1);
                bool[] Elektrozawor_N2 = modbusClient.ReadCoils(1299, 1);
                bool[] Elektrozawor_N3 = modbusClient.ReadCoils(1300, 1);
                bool[] Elektrozawor_N4 = modbusClient.ReadCoils(1301, 1);
                lblElektrozawor_N1.Content = Elektrozawor_N1[0].ToString();
                lblElektrozawor_N2.Content = Elektrozawor_N2[0].ToString();
                lblElektrozawor_N3.Content = Elektrozawor_N3[0].ToString();
                lblElektrozawor_N4.Content = Elektrozawor_N4[0].ToString();

                float TemperaturaZadana = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4506, 2));
                txtTemperaturaZadana.Text = TemperaturaZadana.ToString();

                float TolerancjaTemperatury = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(4508, 2));
                txtTolerancjaTemperatury.Text = TolerancjaTemperatury.ToString();

                float Temperatura_T1     = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2008, 2));
                float Temperatura_T2     = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2010, 2));
                float TemperaturaSrednia = ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(2012, 2));
                lblTemperaturaWody1.Content   = Temperatura_T1.ToString();
                lblTemperaturaWody2.Content   = Temperatura_T2.ToString();
                lblTemperaturaSrednia.Content = TemperaturaSrednia.ToString();

                bool[] GrzanieWody = modbusClient.ReadCoils(2248, 1);
                lblGrzanieWody.Content = GrzanieWody[0].ToString();

                bool[] WodaNagrzana = modbusClient.ReadCoils(2251, 1);
                lblWodaNagrzana.Content = WodaNagrzana[0].ToString();

                bool[] BadanieZasadnicza = modbusClient.ReadCoils(2249, 1);
                lblBadanieZasadnicze.Content = BadanieZasadnicza[0].ToString();

                int[] ProbkowanieCisnienia = modbusClient.ReadHoldingRegisters(4504, 1);
                txtProbkowanieCisnienia.Text = ProbkowanieCisnienia[0].ToString();

                int[] ProbkowanieTemperatury = modbusClient.ReadHoldingRegisters(4505, 1);
                txtProbkowanieTemperatury.Text = ProbkowanieTemperatury[0].ToString();

                modbusClient.Disconnect();
            }
            catch
            {
                MessageBox.Show("nie można podłączyć PLC");
            }
        }
Esempio n. 6
0
        static void startCollecting(bool status)
        {
            try
            {
                ModbusClient modbusClient = new ModbusClient("COM3");
                modbusClient.Baudrate          = 115200; // Not necessary since default baudrate = 9600
                modbusClient.Parity            = System.IO.Ports.Parity.None;
                modbusClient.StopBits          = System.IO.Ports.StopBits.Two;
                modbusClient.ConnectionTimeout = 5000;
                modbusClient.Connect();
                Console.WriteLine("Device Connection Successful");

                String[] sensordata = { "ID", "Temp", "Humidity", "Part03", "Part05", "DateTime" };
                Console.WriteLine("Count\t" + string.Join("\t", sensordata) + "\t\t Run Time");

                SqlConnection myConnection = new SqlConnection(@"Data Source=DESKTOP-DLIT;Initial Catalog=SensorDataDB;Integrated Security=True");
                myConnection.Open();
                status = true;
                DateTime startTime = DateTime.Now;
                int      dataCount = 0;

                while (status)
                {
                    for (byte j = 1; j < 4; j++)
                    {
                        dataCount += 1;
                        modbusClient.UnitIdentifier = j;

                        //string timestamp0 = now.ToString("yyyy-MM-dd HH:mm:ss.fff"); //

                        int[]    test1      = modbusClient.ReadInputRegisters(10, 6);
                        DateTime timestamp  = DateTime.Now;
                        var      timeCount  = DateTime.Now - startTime;
                        string   timestamp0 = timestamp.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        decimal  temp       = test1[0];
                        decimal  humid      = test1[1];
                        int[]    part03_arr = { 0, 0 };
                        int[]    part05_arr = { 0, 0 };
                        part03_arr[0] = test1[3];
                        part03_arr[1] = test1[2];
                        part05_arr[0] = test1[5];
                        part05_arr[1] = test1[4];
                        Int64 part03 = ModbusClient.ConvertRegistersToInt(part03_arr);
                        Int64 part05 = ModbusClient.ConvertRegistersToInt(part05_arr);
                        Console.WriteLine(dataCount + "\t" + j + "\t" + (temp / 100m).ToString("F", CultureInfo.InvariantCulture) + "\t" + (humid / 100m).ToString("F", CultureInfo.InvariantCulture) + "\t\t" + String.Format("{0:n0}", part03) + "\t" + String.Format("{0:n0}", part05) + "\t" + timestamp0 + "\t  {0}일 {1}시간 {2}분 {3}초", timeCount.Days, timeCount.Hours, timeCount.Minutes, timeCount.Seconds);

                        string sql_str_temp   = "INSERT INTO DEV_TEMP_" + j.ToString() + " (Temperature, DateAndTime) Values (@Temperature, @DateAndTime)";
                        string sql_str_humid  = "INSERT INTO DEV_HUMID_" + j.ToString() + " (Humidity, DateAndTime) Values (@Humidity, @DateAndTime)";
                        string sql_str_part03 = "INSERT INTO DEV_PART03_" + j.ToString() + " (Particle03, DateAndTime) Values (@Particle03, @DateAndTime)";
                        string sql_str_part05 = "INSERT INTO DEV_PART05_" + j.ToString() + " (Particle05, DateAndTime) Values (@Particle05, @DateAndTime)";

                        SqlCommand myCommand_temp   = new SqlCommand(sql_str_temp, myConnection);
                        SqlCommand myCommand_humid  = new SqlCommand(sql_str_humid, myConnection);
                        SqlCommand myCommand_part03 = new SqlCommand(sql_str_part03, myConnection);
                        SqlCommand myCommand_part05 = new SqlCommand(sql_str_part05, myConnection);

                        myCommand_temp.Parameters.AddWithValue("@Temperature ", (temp / 100m).ToString("F", CultureInfo.InvariantCulture));
                        myCommand_temp.Parameters.AddWithValue("@DateAndTime", timestamp0);
                        myCommand_temp.ExecuteNonQuery();

                        myCommand_humid.Parameters.AddWithValue("@Humidity", (humid / 100m).ToString("F", CultureInfo.InvariantCulture));
                        myCommand_humid.Parameters.AddWithValue("@DateAndTime", timestamp0);
                        myCommand_humid.ExecuteNonQuery();

                        myCommand_part03.Parameters.AddWithValue("@Particle03", part03);
                        myCommand_part03.Parameters.AddWithValue("@DateAndTime", timestamp0);
                        myCommand_part03.ExecuteNonQuery();

                        myCommand_part05.Parameters.AddWithValue("@Particle05", part05);
                        myCommand_part05.Parameters.AddWithValue("@DateAndTime", timestamp0);
                        myCommand_part05.ExecuteNonQuery();
                    }
                }
                myConnection.Close();
                modbusClient.Disconnect();
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 7
0
        public void VerileriOku(bool isReporting, Control invokeControl = null)
        {
            ct = tokenSource.Token;
            if (ct.IsCancellationRequested)
            {
                tokenSource = new CancellationTokenSource(); ct = tokenSource.Token;
            }
            if (isReporting)
            {
                görev = Task.Factory.StartNew(() =>
                {
                    ct.ThrowIfCancellationRequested();
                    try
                    {
                        if (!Modbus.Connected)
                        {
                            Modbus.Connect();
                        }
                    }
                    catch (ConnectionException ex)
                    {
                        string msg = string.Format("Cihaz:{0}\nBağlanılamadı Ayarlarınızı Kontrol edin! ", DeviceName);
                        if (ConException == null)
                        {
                            MessageBox.Show(msg);
                        }
                        else
                        {
                            ConException?.Invoke(this, msg);
                        }
                        return;
                    }
                    catch (Exception ex)
                    {
                        string msg = string.Format("Cihaz:{0}\n{1}", DeviceName, ex.ToString());
                        if (ConException == null)
                        {
                            MessageBox.Show(msg);
                        }
                        else
                        {
                            ConException?.Invoke(this, msg);
                        }
                        return;
                    }
                    var StartDatapoint = DataPoints.FirstOrDefault(x => x.DataType == DataType.RaporBiti);
                    if (StartDatapoint == null)
                    {
                        MessageBox.Show(string.Format("Cihaz:{0}\nRapor Başlama Biti/Adresi Ayarlanmamış!", DeviceName));
                        return;
                    }
                    Stopwatch sw = new Stopwatch();
                    List <Datapoint> Pointler = new List <Datapoint>(DataPoints.Where(x => x.DataType != DataType.RaporBiti).ToList());
                    while (Modbus.Connected)
                    {
                        sw.Start();
                        if (ct.IsCancellationRequested)
                        {
                            try
                            {
                                ct.ThrowIfCancellationRequested();
                            }
                            catch (OperationCanceledException ex)
                            {
                                StopsReads?.Invoke(this, ex.ToString());
                                invokeControl.InvokeIfRequired(() => Reporting = false);
                                ReportBitStatus?.Invoke(this, Reporting);
                                break;
                            }
                        }
                        try
                        {
                            var reportbit = Modbus.ReadCoils(StartDatapoint.Address, 1).FirstOrDefault();
                            invokeControl.InvokeIfRequired(() =>
                            {
                                if (reportbit != Reporting)
                                {
                                    Reporting = reportbit;
                                    ReportBitStatus?.Invoke(this, Reporting);
                                }
                            });
                        }
                        catch (Exception ex)
                        {
                            string msg = string.Format("Cihaz:{0}\nAdres:{1}\nOkuma Hatası!.\n{2}", DeviceName, StartDatapoint.Address, ex.ToString());
                            if (ConException == null)
                            {
                                MessageBox.Show(msg);
                            }
                            else
                            {
                                ConException?.Invoke(this, msg);
                            }
                            return;
                        }


                        Pointler.ForEach(Point =>
                        {
                            switch (Point.DataType)
                            {
                            case DataType.Bool:
                                Point.Value = modbus.ReadCoils(Point.Address, 1).FirstOrDefault();
                                break;

                            case DataType.Word:
                                Point.Value = modbus.ReadHoldingRegisters(Point.Address, 1).FirstOrDefault();
                                break;

                            case DataType.DoubleWord:
                                Point.Value = ModbusClient.ConvertRegistersToInt(modbus.ReadHoldingRegisters(Point.Address, 2));
                                break;

                            case DataType.RaporBiti:
                                break;

                            default:
                                break;
                            }
                        });
                        sw.Stop();
                        Cycle?.Invoke(this, sw.Elapsed.TotalMilliseconds);
                        //Console.WriteLine("\nCycle Time:{0}ms", sw.Elapsed.TotalMilliseconds);
                        sw.Reset();
                    }
                }, tokenSource.Token);
                //if (görev.Status != TaskStatus.Running)
                //    görev.Start();
            }
            else
            {
                if (görev.Status == TaskStatus.Running)
                {
                    tokenSource.Cancel();
                }
            }
        }
Esempio n. 8
0
 public int ConvertRegistersToInt(int[] registers)
 {
     return(ModbusClient.ConvertRegistersToInt(registers));
 }
Esempio n. 9
0
        private void FetchFromModbusServer()
        {
            if (ModbusHost.HasValue && ModbusAddress1.Value > 0)
            {
                int registerToRead;
                switch (DataType.Value)
                {
                case DataTypeEnum.INT32:
                case DataTypeEnum.FLOAT:
                    registerToRead = 2;
                    break;

                case DataTypeEnum.LONG:
                case DataTypeEnum.DOUBLE:
                    registerToRead = 4;
                    break;

                case DataTypeEnum.INT16_SIGNED:
                case DataTypeEnum.INT16_UNSIGNED:
                default:
                    registerToRead = 1;
                    break;
                }
                ModbusClient.RegisterOrder regOrder;
                if (!RegisterOrder.HasValue || RegisterOrder.Value == ByteOrderEnum.LOW_HIGH)
                {
                    regOrder = ModbusClient.RegisterOrder.LowHigh;
                }
                else
                {
                    regOrder = ModbusClient.RegisterOrder.HighLow;
                }
                ModbusClient modbusClient = null;
                try
                {
                    modbusClient = new ModbusClient(ModbusHost.Value, ModbusPort.Value);
                    modbusClient.ConnectionTimeout = 5000;
                    modbusClient.Connect();
                    modbusClient.UnitIdentifier = (byte)ModbusID.Value;

                    int[] readHoldingRegisters;
                    switch (FunctionCode.Value)
                    {
                    case FunctionCodeEnum.FC_04:
                        readHoldingRegisters = modbusClient.ReadInputRegisters(ModbusAddress1.Value, registerToRead);
                        break;

                    case FunctionCodeEnum.FC_03:
                    default:
                        readHoldingRegisters = modbusClient.ReadHoldingRegisters(ModbusAddress1.Value, registerToRead);
                        break;
                    }

                    double result     = 0;
                    string result_str = "";

                    switch (DataType.Value)
                    {
                    case DataTypeEnum.INT32:
                        // probably signed ...
                        result = ModbusClient.ConvertRegistersToInt(readHoldingRegisters, regOrder);
                        break;

                    case DataTypeEnum.FLOAT:
                        result = ModbusClient.ConvertRegistersToFloat(readHoldingRegisters, regOrder);
                        break;

                    case DataTypeEnum.LONG:
                        result = ModbusClient.ConvertRegistersToLong(readHoldingRegisters, regOrder);
                        break;

                    case DataTypeEnum.DOUBLE:
                        result = ModbusClient.ConvertRegistersToDouble(readHoldingRegisters, regOrder);
                        break;

                    case DataTypeEnum.INT16_SIGNED:
                        result = readHoldingRegisters[0];
                        break;

                    case DataTypeEnum.INT16_UNSIGNED:
                        // unsigned
                        for (int i = 0; i < (readHoldingRegisters.Length); i++)
                        {
                            int tmp = readHoldingRegisters[i];
                            if (tmp == -32768)     // fix for 0x00
                            {
                                tmp = 0;
                            }
                            if (tmp < 0)     // no negative values !
                            {
                                tmp = tmp + (int)Math.Pow(2, 16);
                            }

                            result     = result + (tmp * Math.Pow(2, (16 * ((readHoldingRegisters.Length) - (i + 1)))));
                            result_str = result_str + " 0x" + tmp.ToString("X4");
                        }
                        break;

                    default:
                        result_str = "internal: invalid datatype";
                        break;
                    }

                    OutputValue1.Value = result;
                    ErrorMessage.Value = result_str;
                    this.SchedulerService.InvokeIn(new TimeSpan(0, 0, TimeSpan.Value), FetchFromModbusServer);
                }
                catch (Exception e)
                {
                    this.ErrorMessage.Value = e.ToString();
                    this.SchedulerService.InvokeIn(new TimeSpan(0, 1, 0), FetchFromModbusServer);
                }
                finally
                {
                    if (modbusClient != null)
                    {
                        modbusClient.Disconnect();
                    }
                }
            }
        }