1

I have a Siemens S7-1212 AC/DC/Rly PLC and i want communicate with a C# application using Snap7. I have successfully made a connection to the PLC in the UI and i can even successfully write values to the PLC. Sometimes however (1 in 3 times) the write function doesnt write the values to the PLC and gives a very high integer as result.

C# code: The connection with the PLC has been established with the following code:

private S7Client Client = new S7Client();
Client.ConnectTo("192.186.0.1", 0, 0);

The write function:

byte[] writeBuffer = new byte[1];
S7.SetBitAt(ref writeBuffer, 0, 0, true);
int result = Client.DbWrite(1,0,writeBuffer.Length, writeBuffer);
if (result == 0)
     // connection successfull
else 
     // Connection unsuccessfull

Now sometimes when i execute the function above the result is 0, so the write action has been executed successfully. I can see the value change to true in the PLC program. But sometimes (about 1 in 3 times) the result is a very high value, most of the times 3145728 (sometimes another number but mostly this). In this case the function does run (no exeption or error given), but the value does not change.

My question:

Why do i get this high value as result and what does it mean?

Thanks in advance, Theo

Theo Tromp
  • 23
  • 4
  • How does the server know how many bytes you are sending? Did you write any of the code on the server side? Are you waiting enough time for PLC to write data (or unlock)? – jdweng Apr 04 '19 at 11:14
  • 1
    According to [this](https://github.com/SCADACS/snap7/blob/master/examples/dot.net/snap7.net.cs), the error code 3145728 (0x300000) means `errParNoRoom`. Apparently, there's an `ErrorText` function that you can pass the code to and get a description for the error back. – 500 - Internal Server Error Apr 04 '19 at 11:34
  • @jdweng I make a new buffer of 8 bits (0000 0000) This buffer gets filled in with S7.SetBitAt(" position"). Then the whole buffer of 8 bits gets send to the PLC which has 8 boolean variables. – Theo Tromp Apr 04 '19 at 12:18
  • @500-InternalServerError Thanks for your answer. I have checked the error message and it says: "CLI: Job pending" Also (0x300000) has 6 digits and my errorcode (3145728) is 7 digits. Not sure if we errParNoRoom is the error we are dealing with here. Thanks anyways – Theo Tromp Apr 04 '19 at 12:31
  • The two number are the same. One is hex and the other decimal. The error is "errCliJobPending". Not sure if this means the previous job didn't complete or the current job is still running. – jdweng Apr 04 '19 at 13:43
  • `errCliJobPending` indeed. My bad, sorry. – 500 - Internal Server Error Apr 04 '19 at 19:20
  • @500-InternalServerError No problem, you helped me a lot. Do you know what that error means? I looked up errCliJobPending and came to this link: https://sourceforge.net/p/snap7/discussion/bugfix/thread/cca5b62b/ Does anyonw know how to fix this? – Theo Tromp Apr 05 '19 at 06:00

0 Answers0