private void BtnCzasPomiaru_N4_Click(object sender, RoutedEventArgs e)
        {
            ModbusClient modbusClient = new ModbusClient("192.168.1.101", 502);    //Ip-Address and Port of Modbus-TCP-Server

            modbusClient.Connect();
            int CzasPomiaru_N4 = int.Parse(txtCzasPomiaru_N4.Text);

            int[] aaa = ModbusClient.ConvertIntToRegisters(CzasPomiaru_N4);
            modbusClient.WriteMultipleRegisters(4532, aaa);
            modbusClient.Disconnect();
        }
 public override void writeInt16(string var, short value)
 {
     try
     {
         var reg = ModbusClient.ConvertIntToRegisters(value);
         this.client.WriteMultipleRegisters(int.Parse(var), reg); //Read 10 Holding Registers from Server, starting with Address 1
     }
     catch (Exception ex)
     {
         this.client.Disconnect();
         throw ex;
     }
 }
Exemple #3
0
        public List <int[]> getLogs(int startIndexRead)
        {
            modbusClient = ConnectUserControl.getModbusClient();
            List <int[]> RecordNumbers = new List <int[]>();

            if (modbusClient != null && modbusClient.Connected == true)
            {
                try
                {
                    //long OldbestRecordNumber = getOldbestRecordNumber();
                    long NewbestRecordNumber = getNewbestRecordNumber();
                    if (startIndexRead != -1 && NewbestRecordNumber != -1)
                    {
                        modbusClient.WriteMultipleRegisters(1059, ModbusClient.ConvertIntToRegisters(768));
                        for (long i = startIndexRead; i <= NewbestRecordNumber; i++)
                        {
                            int[] numberCurrentWrite = new int[4];
                            numberCurrentWrite = ModbusClient.ConvertLongToRegisters(i);
                            modbusClient.WriteMultipleRegisters(1060, numberCurrentWrite);
                            int[] ArrayLogs = new int[64];
                            ArrayLogs = modbusClient.ReadHoldingRegisters(17344, 64);
                            RecordNumbers.Add(ArrayLogs);
                        }
                    }
                    return(RecordNumbers);
                }
                catch (Exception)
                {
                    Console.WriteLine("Error: Неожиданный обрыв подключения");
                    return(RecordNumbers);//
                }
            }
            else
            {
                return(RecordNumbers);
            }
        }
Exemple #4
0
 public int[] ConvertIntToRegisters(int value)
 {
     return(ModbusClient.ConvertIntToRegisters(value));
 }
Exemple #5
0
        public static List <float[, ]> getDataGrafiksOfDevice(int[] sizelog, ModbusClient modbusClient, int startIndex)
        {
            List <float[, ]> ListAllGraphics = new List <float[, ]>();

            for (int i = 0; i < sizelog.Length; i++)//AllLog
            {
                float[,] WorksAndPointsForGraphs = new float[3, sizelog[i]];
                int NumbersRead      = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(sizelog[i]) / 32));
                int CurrentCountRead = 0;
                for (int j = 0; j < NumbersRead; j++)    //dataMomentForLog
                {
                    modbusClient.WriteMultipleRegisters(1059, ModbusClient.ConvertIntToRegisters(j));
                    modbusClient.WriteMultipleRegisters(1060, ModbusClient.ConvertIntToRegisters(i + startIndex));
                    int[] readRegisters = modbusClient.ReadHoldingRegisters(17344, 64);
                    for (int z = 0; z < readRegisters.Length; z = z + 2)
                    {
                        WorksAndPointsForGraphs[0, CurrentCountRead] = ModbusClient.ConvertRegistersToFloat(new int[2] {
                            readRegisters[z], readRegisters[z + 1]
                        });
                        CurrentCountRead++;
                        if (CurrentCountRead >= sizelog[i])
                        {
                            break;
                        }
                    }
                }
                CurrentCountRead = 0;
                for (int j = 42; j < 42 + NumbersRead; j++)    //dataRevolutionsForLog
                {
                    modbusClient.WriteMultipleRegisters(1059, ModbusClient.ConvertIntToRegisters(j));
                    modbusClient.WriteMultipleRegisters(1060, ModbusClient.ConvertIntToRegisters(i + startIndex));
                    int[] readRegisters = modbusClient.ReadHoldingRegisters(17344, 64);
                    for (int z = 0; z < readRegisters.Length; z = z + 2)
                    {
                        WorksAndPointsForGraphs[1, CurrentCountRead] = ModbusClient.ConvertRegistersToFloat(new int[2] {
                            readRegisters[z], readRegisters[z + 1]
                        });
                        CurrentCountRead++;
                        if (CurrentCountRead == sizelog[i])
                        {
                            break;
                        }
                    }
                }
                CurrentCountRead = 0;
                for (int j = 84; j < 84 + NumbersRead; j++)//dataTimeForLog
                {
                    modbusClient.WriteMultipleRegisters(1059, ModbusClient.ConvertIntToRegisters(j));
                    modbusClient.WriteMultipleRegisters(1060, ModbusClient.ConvertIntToRegisters(i + startIndex));
                    int[] readRegisters = modbusClient.ReadHoldingRegisters(17344, 64);
                    for (int z = 0; z < readRegisters.Length; z = z + 2)
                    {
                        WorksAndPointsForGraphs[2, CurrentCountRead] = ModbusClient.ConvertRegistersToFloat(new int[2] {
                            readRegisters[z], readRegisters[z + 1]
                        });
                        CurrentCountRead++;
                        if (CurrentCountRead == sizelog[i])
                        {
                            break;
                        }
                    }
                }
                AdapterDataBase.writeDataLogDB(WorksAndPointsForGraphs, i + startIndex);
                ListAllGraphics.Add(WorksAndPointsForGraphs);
                Viewer.setProgressBar(i);
            }
            return(ListAllGraphics);
        }