Function Refused By CPU

See original GitHub issue

Having an issue with try to read a DB or memory Area I will list below two sample codes I tried. My connection is successful but I get the rejection on the read function. In the memory example I am trying to read M0.0. For the DB example I have created a global DB200 with only 2 bits inside it and I am trying to read DB200.00. The db optimization is turned off as per the instruction.

CPU is 6ES7212-1AE40-0XV0 CPU 1212-C - DC/DC/DC Firmware Version 4.4

Reading Memory Example:

import snap7.client as c
from snap7.util import *
from snap7.types import *
import socket


def ReadMemory(plc,byte,bit,datatype):
    result = plc.read_area(areas['MK'],0,byte,datatype)
    if datatype == S7WLBit:
        return get_bool(result,0,1)
    elif datatype == S7WLByte or datatype == S7WLWord:
        return get_int(result,0)
    elif datatype == S7WLReal:
        return get_real(result,0)
    elif datatype == S7WLDWord:
        return get_dword(result,0)
    else:
        return None

if __name__ == "__main__":
    plc = c.Client()
    plc.connect('192.168.1.10',0,1)
    print("Connection Sucessful") 
    print(ReadMemory(plc,0,0,S7WLBit))

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Example two Reading DB

import snap7.client as c
from snap7.util import *
from snap7.types import *
import socket

def ReadMemory(plc,byte,bit,datatype):
    result = plc.read_area(area = areas['DB'],dbnumber = 200,start = 0,size = 0x01)
    if datatype == S7WLBit:
        return get_bool(result,0,1)
    elif datatype == S7WLByte or datatype == S7WLWord:
        return get_int(result,0)
    elif datatype == S7WLReal:
        return get_real(result,0)
    elif datatype == S7WLDWord:
        return get_dword(result,0)
    else:
        return None

if __name__ == "__main__":
    plc = c.Client()
    plc.connect('192.168.1.10',0,1)
    print("Connection Sucessful") 
    
    print(ReadMemory(plc,0,0,S7WLBit))

Both cases are giving me the same error. I am a pretty experienced siemens programmer but fairly new at Python. Please let me know if you see any errors or what you suggest?

Traceback In Both Cases:

Connection Sucessful
b'CLI : function refused by CPU (Unknown error)'
Traceback (most recent call last):
  File "192025_Main.py", line 23, in <module>
    print(ReadMemory(plc,0,0,S7WLBit))
  File "192025_Main.py", line 7, in ReadMemory
    result = plc.read_area(areas['MK'],0,byte,datatype)
  File "/home/pi/.local/lib/python3.7/site-packages/snap7/client.py", line 259, in read_area
    check_error(result, context="client")
  File "/home/pi/.local/lib/python3.7/site-packages/snap7/common.py", line 66, in check_error
    raise Snap7Exception(error)
snap7.exceptions.Snap7Exception: b'CLI : function refused by CPU (Unknown error)'

Running on raspberry PI 3 python version 3.7.3. I followed a youtube video for setting up the binaries for the library on the PI3

EDIT:

Attempt 3 (Much more basic)

import snap7.client as c
from snap7.util import *
from snap7.types import *

if __name__ == "__main__":
    plc = c.Client()
    plc.connect('192.168.1.10',0,1)
    print("Connection Sucessful")
    data = plc.db_read(200,0,1)
'''

Still the same error

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kevilaycommented, Apr 24, 2021

Iautarodapin that was exactly the problem! Thank you very much for your help.

0reactions
swamper123commented, Jun 28, 2021

@FabioAlmeida25 Please open a new Issue with some backround information (setup? what have you tried? etc…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

S7-1200, Snap7: Exception: CLI : function refused by CPU ...
Running below snap7 client script for python using Siemens S7-1200 PLC shows the below common CLI refusal error. What ...
Read more >
Function refused by cpu R/W DB S7-1500 - Snap7
I reproduced your error. It occurs when in the CPU properties is not enabled the GET/PUT access. Are you completly sure that your...
Read more >
Snap7: Exception: CLI : function refused by CPU after TIA ...
We have an application with a Raspberry pi using SNAP7 and a S7-1214. The application was workin smoothly but the PLC was programmed...
Read more >
Error "function refused by PLC" - Industry Support Siemens
My PLC is currently set to "Full access (no protection)", but I did try to gettheCPU protection level info - Client->GetProtection() - before...
Read more >
Function not available when reading DB from PLC S7 1200
I need help connecting PLC S7 1200 and Labview using Snap7. Using example DBGet.vi, I get Error in DBGet function saying "CPU :...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found