Hi Patrick,
welcome to our list.
There is one big difference (if you are calling the code you posted in a loop):
Internally the driver automatically does the translation from a symbolic
address to a handle and to use that handle to read and to give back the handle
when closing the connection.
Perhaps if you run your loop just around this part:
request.execute().whenComplete((response, exception) -> {
Integer x = response.getInteger("value-1");
System.out.println("READ DONE: " + x.toString());
});
Then it would be a similar scenario.
If this isn’t solving the problem, could you possibly do a WireShark recording
oft hat communication and attach that to a Jira issue on:
https://issues.apache.org/jira/projects/PLC4X/
This would be the best way to help us find and possibly resolve the issue.
Hope that helps,
Chris
Von: Patrick Boisclair <[email protected]>
Gesendet: Donnerstag, 17. Dezember 2020 15:34
An: [email protected]
Betreff: Beckhoff with ADS protocol (0.0.8-SNAPSHOT)
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]]