1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyModbus;
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
var ipadresses = new List<string>();
int i = 1;
ipadresses.Add("194.176.3.14");
ipadresses.Add("194.176.3.10");
ipadresses.Add("194.176.3.15");
ipadresses.Add("194.176.3.19");
ipadresses.Add("194.176.3.20");
ipadresses.Add("194.176.3.24");
List<List<int>> valeurs = new List<List<int>>();
List<int> registrevaleurs = new List<int>();
List<int> registrevaleurs1 = new List<int>();
List<int> registrevaleurs2 = new List<int>();
foreach (string ip in ipadresses)
{
{
ModbusClient modbusClient = new ModbusClient(ip, 502);
modbusClient.Connect();
int[] readimputregistre = modbusClient.ReadInputRegisters(1, 10);
bool[] readCoils = modbusClient.ReadCoils(1, 5);
bool[] readDiscreteInputs = modbusClient.ReadDiscreteInputs(1, 9);
foreach (int y in readimputregistre)
{
registrevaleurs.Add(y);
}
valeurs.Add(registrevaleurs);
foreach (bool x in readCoils)
{
registrevaleurs1.Add(Convert.ToInt32(x));
}
valeurs.Add(registrevaleurs1);
foreach (bool z in readDiscreteInputs)
{
registrevaleurs2.Add(Convert.ToInt32(z));
}
valeurs.Add(registrevaleurs2);
modbusClient.Disconnect();
}
foreach (int x in registrevaleurs)
{
Console.WriteLine("ReadInputRegisters = "+ x);
}
i++;
foreach (int y in registrevaleurs1)
{
Console.WriteLine("ReadCoils = " + y);
}
foreach (int z in registrevaleurs2)
{
Console.WriteLine("ReadDiscreteInputs = " + z);
}
}
/* for (i = 1; i < registrevaleurs2.Count; i++)
{
Console.WriteLine("Value of imputregistre " + i + " est " + registrevaleurs2[i].ToString());
// Console.WriteLine("Value of HoldingRegisters" + j + " est " + readHoldingRegisters[j].ToString());
}*/
/* for (i = 1; i < registrevaleurs1.Count; i++)
{
// Console.WriteLine("ReadDiscreteInputs " + i + " est " + registrevaleurs[i].ToString());
}
for (i = 0; i < registrevaleurs1.Count; i++)
{
Console.WriteLine("imputregistre_wago " + i + " est " + registrevaleurs1[i].ToString());
}*/
//int valeur = valeurs[5][1];
// Console.WriteLine("test "+ valeur);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
} |
Partager