Hello everyone,
Im' able to connect to my beckhoff PLC, read a value, but sometimes the read
just "hang". The code below works like half the time.
Some time, I run the program, it reads the value, sometimes it just hang on the
"execute".
I dont know what Im doing wrong.
PlcDriverManager driver = new PlcDriverManager();
try {
//
PlcConnection connection = driver.getConnection(
"ads:tcp://10.10.11.77?sourceAmsNetId=172.29.48.1.1.1&sourceAmsPort=36&targetAmsNetId=5.62.206.200.1.1&targetAmsPort=851");
if (connection.isConnected()) {
if (connection.getMetadata().canRead()) {
PlcReadRequest.Builder builder =
connection.readRequestBuilder();
builder.addItem("value-1", "MAIN.Rand_1:DINT");
PlcReadRequest request = builder.build();
request.execute().whenComplete((response, exception) -> {
Integer x = response.getInteger("value-1");
System.out.println("READ DONE: " + x.toString());
});
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Dong the same in C# with the TwinCAT dll from beckhoff works flawlessly:
int handle = tcClient.CreateVariableHandle("MAIN.Rand_1");
for (int i = 0; i < 1000000; i++) {
tcClient.Read(handle, dataStream);
var v = binRead.ReadInt32().ToString();
Console.WriteLine(v);
dataStream.Position = 0;
}
Patrick Boisclair
Analyste - Programmeur senior / Senior Analyst Programmer
[cid:[email protected]]<https://www.noovelia.com>
462, rue des Forges, Trois-Rivières (Québec) G9A 2H5 CANADA
noovelia.com<https://www.noovelia.com>
[cid:[email protected]]