S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.33k stars 588 forks source link

Help! I ran into some problems #403

Open wanqi121 opened 3 years ago

wanqi121 commented 3 years ago

I Read the data of DB1
ushort result = (ushort)SIMATIC_PLC.Read("DB1.DBW0"); Return error "Received 12 bytes: '32-02-00-00-00-00-00-00-00-00-81-04', expected 20 bytes." Can someone tell me what is going on?

mycroes commented 3 years ago

Hi @wanqi121,

Probably you forgot to enable Permit access with PUT/GET communication from remote partner (PLC, HMI, OPC, ...) in TIA portal. Please report back if that was indeed the issue.

Regards, Michael

scamille commented 3 years ago

Is there a way we can parse this response to assert that missing put/get communication is the problem, and throw a better exception?

With the first 4 bytes being TPKT header, I have a hard time parsing the TPDU. Its dynamic header length is 0 which we don't handle well but that could be changed. Problem is that I can't even fit those 8 bytes into the TPDU header without any dynamic length, and that means I can't make much of the last 2 bytes which would have non-zero values in this example.

mycroes commented 3 years ago

@scamille I'm not sure about all the zeroes, but 0x8104 probably is the error that PUT/GET is not enabled. Also, I'm not sure if first 4 bytes here are actually TPKT, or if this is just the TPKT contents.

scamille commented 3 years ago

Oh right of course all of that data is just S7 payload. Too early in the morning.

I think we generally under-parse the S7 header of the read response in AssertReadResponse

http://gmiru.com/article/s7comm/ neatly explains the data here a bit: The second byte being 0x2 identifies this as a ACK message, with 0x81 being the error class and 0x4 the error code.

irongiants commented 3 years ago

Hi guys,I met the same question.The reason is not the configuration . Finally I resolved it by updating the Siemens TIA_Portal_STEP_7_Pro software from v14 to v15.