I've got the luxury of testing on S7-1212C AC/DC/RLY V4.0/V4.1.3 (Q3 2016) and on S7-1214C DC\DC\DC V4.0/V4.1.3 (Q1 2017) with python scripting and PLC communication. I am trying to read or write to DB1 some code shown below but an error is thrown back. Apparently the issue is not in the python-snap7 wrapper. See github python-snap7 bugreporting here. I've got the following info and error for you and don't know what to do:
<CDLL 'C:\Python\Anac2\snap7.dll', handle 9bc70000 at 4cc8908>
or (after removal of snapp7.dll and reinstall python-snap7 via pip.)
<CDLL 'C:\Python\Anac2\snap7.dll', handle 9bad0000 at 55c8940>
and Tracback error:
No handlers could be found for logger "snap7.common"
Traceback (most recent call last):
File "D:...\name.py", line 224, in <module>
Tester().test_db()
File "D:...\name.py", line 210, in test_db
client.db_write(db_number, start, data)
File "c:\python\anac2\lib\site-packages\snap7\client.py", line 25, in f
check_error(code, context="client")
File "c:\python\anac2\lib\site-packages\snap7\common.py", line 65, in check_error
raise Snap7Exception(error)
snap7.snap7exceptions.Snap7Exception: CPU : Item not available.
So basically, what's going on and how do I solve this?
Last edit: ZF007 2017-12-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've checked that and I've got no possibility to turn of "optimized" (see also below self-learning answer). The "optimized" checkbox is greyed out under TIAportal V13 basic license. In the mean time I've made DB1 via Step7 TIAportal but now the python script I run raises the error snap7.snap7exceptions.Snap7Exception: CPU : Address out of range. I'd try to figure out if that is me writing wrong information at the point of data = 'ff' or something else (incorrect snap7.dll version). Thus I've also recompiled snap7.dll for win10,x64 and the dll increased by 3kb.
Using VS2017 community (v15.5.2) it runs in VS2015 mode: I get a few warnings but dll seems to work for basic I/O:
1>------ Build started: Project: VS2015, Configuration: Release x64 ------
1>s7_client.cpp
1>s7_isotcp.cpp
1>s7_micro_client.cpp
1>s7_partner.cpp
1>s7_peer.cpp
1>s7_server.cpp
1>s7_text.cpp
1>......\src\core\s7_text.cpp(64): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
1>snap7_libmain.cpp
1>snap_msgsock.cpp
1>......\src\sys\snap_msgsock.cpp(301): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data
1>......\src\sys\snap_msgsock.cpp(325): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data
1>......\src\sys\snap_msgsock.cpp(767): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data
1>snap_sysutils.cpp
1>snap_tcpsrvr.cpp
1>snap_threads.cpp
1> Creating library ....\bin\Win64\snap7.lib and object ....\bin\Win64\snap7.exp
1>Generating code
1>All 588 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
1>Finished generating code
1>VS2015.vcxproj -> D:\Software\Siemens PLC\snap7-full-1.4.2\build\windows\VS2015....\bin\Win64\snap7.dll
1>Done building project "VS2015.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Last edit: ZF007 2018-01-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just got a small step further. I did check again on the Siemens website about the greyed-out "optimized" option. In your manual you state Uncheck Optimized block access, by default it’s checked. thats... not OB1 kenobi we're looking for... but instead Data_block_1 (DB1). Argh... Now I get the error... ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: Don't know how to convert parameter 2. Thats language I can read.. python talk. Perhaps you could add to your manual that its not OB1 kenobi we're looking for but just the bright side of the force ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
clientdemo functions: systeminfo > catalog order code only, multiread/wite for I/O (I see things change $00 > $02 and hear the PCL transistor Q0.1 switching and led is turned on) and readout PG/PC date/time works, nothing else.
6ES7 212-1BE40-0XB0 V 4.1.3
It seems not to read out DB1.
What I understand is "DB1", "Var1 = bool and has default set "false", (Var2, integer, value 3)..etc. In python that translates as DB1 = {'Var1': ('Bool', False), 'Var2' : ('Int', 3)}. Tab Data read/write with lots of $00 and (left colomn) adress (?) detail location.. Tab block - DB get/fill would be handy and is likely translating a lot to plain english I reckon..but... thats not available on S7-1200... So... what settings are needed to check if Tab data read/write works (see with my own eyes... and not scrolling from 0000 to FFF0..whereever that may be).
Just want to write (valuewise in clientdemo.exe; not python) value of variable:
There you will find the compatibility list of S7 Protocol vs S7 PLCs.
Some things are implemented in S71200/1550 firmware of S7 Standard protocol some others NO, for that the extended protocol is required (not yet implemented and don't ask when please).
However the Data Read/Write is fuly implemented.
DBGet does not work because it internally uses GetAgBlockInfo to know the DB size which is not covered by S71200 CPU.
After modifying the optimization of DB1, the permissions and the connection mechanism, did you transfer the full project (including the hardware configuration) into the CPU ?
That firmware is OK, it must work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you mean the step7 examples? If so.. I dont see TIA portal projects (*.ap13). Got TIA Portal version 13. If you mean that I've uploaded DB1 via TIA to PLC-CPU then yes I did. It got the Var1 and Var2 tagnames and settings as above mentioned. OB1 > I0.0. connected to Q0.0 and to DB1.Var1. During "online" mode I see value of Var1 change from false to true.
Last edit: ZF007 2018-01-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No, I mean your user project. When you modify the properties of a DB you need to transfer your project into the CPU even if you didn't modify the DB content.
No Snap7 project is needed CPU side, only some settings (DB optimization and GET/PUT access).
But does DB1 exist into the CPU ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yup! Just removed Var2.. uploaded.. checked in "online" mode.. gone. Now added back and its there again. In the projecttree I see DB1 with name Data_block_1, Atributes \Optimized block access = turned off.
After a couple of PLC factory resets, PC-reboots (cold/warm..lost count) and recompiling the snap7.dll I've purged the seeming so error (which and where... no cleu at all) but it seems to work now. I can see the read/write data on I/O and DB area. Under win10 I still got the VS2015 compiling error but they seem no longer to affect functionality of the compiled snap7.dll (did install windows xp compatibility at prog installation of VS2017). Maybe never did, who knows?
The above erorr like 1>......\src\sys\snap_msgsock.cpp(301): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data remain but seems to have no effect.
And no, I will not ask about " extended protocol" finish date.. I know from experience some stuff takes time and a lot of muscle pain in arms and legs due to long hours of work and deadlines ;-) Just when its there..its there..or someone swings a money bag in front of you it will be faster than later ;-)
Lastely: I'm gonna write a small noob tutorial for others with zero knowledge about physical adressing of this PLC and bridging the pthon gap... done after I got my camera control + PLC + core prog running! That includes some additional stuff for the python wrapper. No need for other to go through similar learning curve like I did the last three days (besides the default amount of frustration). When the "noob" manual is done I'll toss it here in an attachment, okay?
Enjoy..and thanks for the help.
Last edit: ZF007 2018-01-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've got the luxury of testing on S7-1212C AC/DC/RLY V4.0/V4.1.3 (Q3 2016) and on S7-1214C DC\DC\DC V4.0/V4.1.3 (Q1 2017) with python scripting and PLC communication. I am trying to read or write to DB1 some code shown below but an error is thrown back. Apparently the issue is not in the python-snap7 wrapper. See github python-snap7 bugreporting here. I've got the following info and error for you and don't know what to do:
info:
snap7.dll from D:...\snap7-full-1.4.2\build\bin\win64
win10 x64 sp1
python v2.7.14
anaconda v4.3.30
python-snap7 v0.8
my pthon code:
Result:
<CDLL 'C:\Python\Anac2\snap7.dll', handle 9bc70000 at 4cc8908>
or (after removal of snapp7.dll and reinstall python-snap7 via pip.)
<CDLL 'C:\Python\Anac2\snap7.dll', handle 9bad0000 at 55c8940>
and Tracback error:
So basically, what's going on and how do I solve this?
Last edit: ZF007 2017-12-31
CPU : Item not available means either DB1 does not exist or it's optimized.
Read here about S71200/1500
http://snap7.sourceforge.net/snap7_client.html#target_compatibility
I've checked that and I've got no possibility to turn of "optimized" (see also below self-learning answer). The "optimized" checkbox is greyed out under TIAportal V13 basic license. In the mean time I've made DB1 via Step7 TIAportal but now the python script I run raises the error
snap7.snap7exceptions.Snap7Exception: CPU : Address out of range
. I'd try to figure out if that is me writing wrong information at the point of data = 'ff' or something else (incorrect snap7.dll version). Thus I've also recompiled snap7.dll for win10,x64 and the dll increased by 3kb.Using VS2017 community (v15.5.2) it runs in VS2015 mode: I get a few warnings but dll seems to work for basic I/O:
1>------ Build started: Project: VS2015, Configuration: Release x64 ------
1>s7_client.cpp
1>s7_isotcp.cpp
1>s7_micro_client.cpp
1>s7_partner.cpp
1>s7_peer.cpp
1>s7_server.cpp
1>s7_text.cpp
1>......\src\core\s7_text.cpp(64): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
1>snap7_libmain.cpp
1>snap_msgsock.cpp
1>......\src\sys\snap_msgsock.cpp(301): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data
1>......\src\sys\snap_msgsock.cpp(325): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data
1>......\src\sys\snap_msgsock.cpp(767): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data
1>snap_sysutils.cpp
1>snap_tcpsrvr.cpp
1>snap_threads.cpp
1> Creating library ....\bin\Win64\snap7.lib and object ....\bin\Win64\snap7.exp
1>Generating code
1>All 588 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
1>Finished generating code
1>VS2015.vcxproj -> D:\Software\Siemens PLC\snap7-full-1.4.2\build\windows\VS2015....\bin\Win64\snap7.dll
1>Done building project "VS2015.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Last edit: ZF007 2018-01-01
Just got a small step further. I did check again on the Siemens website about the greyed-out "optimized" option. In your manual you state
Uncheck Optimized block access, by default it’s checked.
thats... not OB1 kenobi we're looking for... but insteadData_block_1
(DB1). Argh... Now I get the error...ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: Don't know how to convert parameter 2
. Thats language I can read.. python talk. Perhaps you could add to your manual that its not OB1 kenobi we're looking for but just the bright side of the force ;-)Hi,
as I wrote several time, I don't know Python and I don't like it at all.
It is a language that should never had born (imho obviously :) )
snap7.dll or snap7.so does not rise any exception, if something was wrong the result code is <>0, the execution flow is always consistent.
Into \rich-demos\i386-win32\bin there is clientdemo.exe, use it "as master" to see if the problem is PLC side or DLL side.
clientdemo functions: systeminfo > catalog order code only, multiread/wite for I/O (I see things change $00 > $02 and hear the PCL transistor Q0.1 switching and led is turned on) and readout PG/PC date/time works, nothing else.
6ES7 212-1BE40-0XB0 V 4.1.3
It seems not to read out DB1.
What I understand is "DB1", "Var1 = bool and has default set "false", (Var2, integer, value 3)..etc. In python that translates as DB1 = {'Var1': ('Bool', False), 'Var2' : ('Int', 3)}. Tab Data read/write with lots of $00 and (left colomn) adress (?) detail location.. Tab block - DB get/fill would be handy and is likely translating a lot to plain english I reckon..but... thats not available on S7-1200... So... what settings are needed to check if Tab data read/write works (see with my own eyes... and not scrolling from 0000 to FFF0..whereever that may be).
Just want to write (valuewise in clientdemo.exe; not python) value of variable:
From..: DB1 = {'Var1': ('Bool', False), 'Var2' : ('Int', 3)}
To......: DB1 = {'Var1': ('Bool', True), 'Var2' : ('Int', 4)}
and then read what value var1/var2 has.
Last edit: ZF007 2018-01-02
I repost the link, please read it.
http://snap7.sourceforge.net/snap7_client.html#target_compatibility
There you will find the compatibility list of S7 Protocol vs S7 PLCs.
Some things are implemented in S71200/1550 firmware of S7 Standard protocol some others NO, for that the extended protocol is required (not yet implemented and don't ask when please).
However the Data Read/Write is fuly implemented.
DBGet does not work because it internally uses GetAgBlockInfo to know the DB size which is not covered by S71200 CPU.
After modifying the optimization of DB1, the permissions and the connection mechanism, did you transfer the full project (including the hardware configuration) into the CPU ?
That firmware is OK, it must work.
Do you mean the step7 examples? If so.. I dont see TIA portal projects (*.ap13). Got TIA Portal version 13. If you mean that I've uploaded DB1 via TIA to PLC-CPU then yes I did. It got the Var1 and Var2 tagnames and settings as above mentioned. OB1 > I0.0. connected to Q0.0 and to DB1.Var1. During "online" mode I see value of Var1 change from false to true.
Last edit: ZF007 2018-01-02
No, I mean your user project. When you modify the properties of a DB you need to transfer your project into the CPU even if you didn't modify the DB content.
No Snap7 project is needed CPU side, only some settings (DB optimization and GET/PUT access).
But does DB1 exist into the CPU ?
yup! Just removed Var2.. uploaded.. checked in "online" mode.. gone. Now added back and its there again. In the projecttree I see DB1 with name
Data_block_1
, Atributes \Optimized block access = turned off.After a couple of PLC factory resets, PC-reboots (cold/warm..lost count) and recompiling the snap7.dll I've purged the seeming so error (which and where... no cleu at all) but it seems to work now. I can see the read/write data on I/O and DB area. Under win10 I still got the VS2015 compiling error but they seem no longer to affect functionality of the compiled snap7.dll (did install windows xp compatibility at prog installation of VS2017). Maybe never did, who knows?
The above erorr like
1>......\src\sys\snap_msgsock.cpp(301): warning C4244: 'argument': conversion from 'socket_t' to 'int', possible loss of data
remain but seems to have no effect.And no, I will not ask about " extended protocol" finish date.. I know from experience some stuff takes time and a lot of muscle pain in arms and legs due to long hours of work and deadlines ;-) Just when its there..its there..or someone swings a money bag in front of you it will be faster than later ;-)
Lastely: I'm gonna write a small noob tutorial for others with zero knowledge about physical adressing of this PLC and bridging the pthon gap... done after I got my camera control + PLC + core prog running! That includes some additional stuff for the python wrapper. No need for other to go through similar learning curve like I did the last three days (besides the default amount of frustration). When the "noob" manual is done I'll toss it here in an attachment, okay?
Enjoy..and thanks for the help.
Last edit: ZF007 2018-01-02