2

Running below snap7 client script for python using Siemens S7-1200 PLC shows the below common CLI refusal error. What is here the common problem and how to solve it?

Script:

import snap7
from snap7.util import *
import struct
import snap7.client
from snap7.snap7types import S7AreaDB

plc=snap7.client.Client()

plc.connect('192.168.0.69',0,1)

area   = 0x84
start  = 0
length = 1
bit    = 0

byte= plc.read_area(area,0,start,length)

Traceback error:

No handlers could be found for logger "snap7.common" Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/snap7/client.py", line 242, in read_area check_error(result, context="client") File "/usr/local/lib/python2.7/dist-packages/snap7/common.py", line 69, in check_error raise Snap7Exception(error) snap7.snap7exceptions.Snap7Exception: CLI : function refused by CPU (Unknown error)

ZF007
  • 3,708
  • 8
  • 29
  • 48

2 Answers2

5

In TIA portal, check if "optimized block access" property is off for Data block that you want to read data from. Moreover, under CPU access protection; access level must be “full” and the “connection mechanism” must allow GET/PUT. See the following link for more detail:

http://snap7.sourceforge.net/snap7_client.html#1200_1500

Secondly, which data block that you want to access? You should specify that in your plc.read_area() method call. There should be a method argument that specifies "Data Block" number since you are using "0x84" data block area code.

Freeman
  • 51
  • 3
  • Hence, there was much more going on than just what I posted in my answer but I figured that out a few days later. I should update my answer towards a wiki tutorial..but commercial deadline prohibit right now to do so :-( But yes, you point in the right direction for database access read/write. I even managed to modify the info label of a variable inside a database to fit the length of a longer variable; which label would otherwise been cut off at preset display length. – ZF007 Jan 22 '18 at 13:55
  • I have edited my answer, you may want to check access rights too. – Freeman Jan 25 '18 at 10:28
0

First of all check which type/model of PLC you've got and check which firmware version you selected (first revision or newer?). Check on the website with Siemens or TIA portal software if there are earlier firmware versions available.

Try to reset your plc to an earlier firmware version and rerun the script and see if the error message is gone!

S7-1212C Example: firmware version 4.1 gives above described error. If firmware version 4.0 is loaded then the error vanishes and you get access to the pcl..

Enjoy Christmas second!

ZF007
  • 3,708
  • 8
  • 29
  • 48
  • This answer led us as to believe there was a compatibility issue but after facing a similar error and issue and now resolving them, I can state that snap7 is working for S7-1200 firmware up to 4.4. – Craig Jan 18 '21 at 14:55
  • Good to know that this specific type of error has been fixed. Thanks. – ZF007 Jan 19 '21 at 07:05