Beckhof PLC communcation with .net 6

51 views Asked by At

I'm trying to read and write towards a Beckhof PLC. So i wrote the function below which is used in a program, though nothing seems to happen. The program runs, the task completes, but nothing ends up at the PLC side. I'm running Twincat3 IDE locally besides VS2023, the code runs.

The Route to the PLC shows that it is connected (i can debug the PLC, inside twincat3, it is a twincat3 ARM model)

As far as i can tell the code below is conform Beckhof's syntax for C#6 my amsNetID is the same as in the PLC, port is OK, and the the ip adres is valid as well. I did got errors when i tried below on ip + port, so now i use the amsNetId + port but still no success, i can trace to the code all is fine but nothing endsup at the other side or get read from it, am i missing something maybe its not even the C# code (though that is a bit new to me so i post it), i can also ping the PLC there are no firewalls (disabled win10 firewall)

public static async Task<T> TestAsync<T>( ConnectionADS connectionAds, string variable) {
int valueToWrite = 42;
float valueFloat = (float)(4 * System.Math.Atan(1.0));  //pi in float 32bit
double valueDouble = 4 * System.Math.Atan(1);
float[] valFloatArr = new float[12];
for (int i = 0; i < valFloatArr.Length; i++) {valFloatArr[i] = (float)(i * System.Math.Atan(1));}

 using AdsClient client = new AdsClient();
 client.Connect(connectionAds.amsNetId, connectionAds.port);  //just a string and an int here inside my ConnectionADS class.
 // perform some writing actions
 ResultWrite resultWrite = await client.WriteValueAsync("Global_vars.gix_integer", 
 valueToWrite,CancellationToken.None);
 ResultWrite resultWritefloat = await client.WriteValueAsync("Global_vars.gfx_float", valueFloat, CancellationToken.None);
 ResultWrite resultWritedouble = await client.WriteValueAsync("Global_vars.double", valueDouble, CancellationToken.None);
 ResultWrite resultWriteFloatArr = await client.WriteValueAsync("Global_vars.gfx_arr", valFloatArr, CancellationToken.None);
 // do a read value
ResultValue<T> resultRead = await client.ReadValueAsync<T>(variable, CancellationToken.None);
     
client.Close();
}
0

There are 0 answers