Function Refused By CPU
See original GitHub issueHaving 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Related StackOverflow Question
Iautarodapin that was exactly the problem! Thank you very much for your help.
@FabioAlmeida25 Please open a new Issue with some backround information (setup? what have you tried? etc…)