S7-1200, python and TSAP

babido10

Member
Join Date
Nov 2017
Location
rabat
Posts
28
I'm currently struggling to make libnodave work with my S7-1200 plc over ethernet. The testISO_TCP.exe makes a connection and gets some info out of it, but I cannot for the life of me reproduce this. Every setting I try I get a -1 from libnodave.daveConnectPLC(dc).

My code:
debugEnable = True
def debug(string):
if(debugEnable):
print string
import ctypes
import os
daveProtoPPI = 10 # PPI for S7 200
daveProtoAS511 = 20 # S5 programming port protocol
daveProtoS7online = 50 # use s7onlinx.dll for transport
daveProtoISOTCP = 122 # ISO over TCP */
daveProtoISOTCP243 = 123 # ISO over TCP with CP243 */
daveProtoISOTCPR = 124 # ISO over TCP with Routing */
daveSpeed9k = 0
daveSpeed19k = 1
daveSpeed187k = 2
daveSpeed500k = 3
daveSpeed1500k = 4
daveSpeed45k = 5
daveSpeed93k = 6
daveBlockType_OB = '8'
daveBlockType_DB = 'A'
daveBlockType_SDB = 'B'
daveBlockType_FC = 'C'
daveBlockType_SFC = 'D'
daveBlockType_FB = 'E'
daveBlockType_SFB = 'F'
class daveOSserialType(ctypes.Structure):
_fields_ = [("rfd", ctypes.c_int),
("wfd", ctypes.c_int)]
debug("Starter script")
debug("Laster inn dll")
libnodave = ctypes.windll.LoadLibrary("libnodave_jfkmod.dll")
fds = daveOSserialType()
debug("Prover a koble til")
fds.rdf = libnodave.openSocket(102,'192.168.0.1')
fds.wdf = fds.rdf
if(fds.rfd >= 0):

di = libnodave.daveNewInterface(fds, 'IF1', 0 ,daveProtoISOTCP ,daveSpeed187k)
libnodave.daveSetTimeout(di, 500000000)
res = libnodave.daveInitAdapter(di)
debug ("InitAdapter: " + str(res))

dc = libnodave.daveNewConnection(di,2,10,0)
res = libnodave.daveConnectPLC(dc)
debug( "ConnectPLC: " + str(res))
 
There might be more errors but i think the connection line is wrong

Try
dc = New libnodave.daveConnection(di, 0, 0, 0)
MPI shall be zero for IsoOnTCP and also rack and slot for S71200 and S71500.
 
Honest question, is the slot on the new family of PLC's starting at 0 instead of the 2 (for 300) and 3 (for 400)?

For the protocol at least. I can successfully connect to S7-1500 using rack 0 slot 0. I don't have a 1200 but according to others on the web it should work with 0,0 for 1200 also.

Maybe this example can help you
 
Last edited:
Snap 7 manual but its the same settings for libnodave
Sharp7.jpg

I have switched from Libnodave to Snap7 because its more actively developed and documented. You might want consider trying Snap7 instead
 
Last edited:
Other things to consider with 1200. (Snippet from Snap7 manual)

S7 1200/1500 Notes An external equipment can access to S71200/1500 CPU using the S7 “base” protocol, only working as an HMI, i.e. only basic data transfer are allowed.
All other PG operations (control/directory/etc..) must follow the extended protocol, not (yet) covered by Snap7.
Particularly to access a DB in S71500 some additional setting plc-side are needed.
1. Only global DBs can be accessed.
2. The optimized block access must be turned off.
3. The access level must be “full” and the “connection mechanism” must allow GET/PUT.
 
Last edited:

Similar Topics

Hi, I have a 1214 on ip 192.168.0.100. This is connected to other modules through a switch on same network. I need to connect this to a company...
Replies
1
Views
94
Hi. I’m trying to upload program from existing PLC S7-1200. Create new project in TIA v15.1 then upload. After upload successfully, go online but...
Replies
5
Views
143
Hi all, I am trying to do Modbus communications via the CB1241 RS485 Communication Board on a Siemens S71200 PLC. I am using a 1215C CPU. After...
Replies
6
Views
177
Dear Friends, I have few Profinet slaves connected to S7-1200 over Profinet. I wish get alarms and disagnostics from the devices. (IO-Link...
Replies
3
Views
137
Hi Experts, I would like to make firmware upgrade from v3.0 to v4.5 (S7-1200 CPU 1215C). Can I do it from v3.0 to v4.5? Do I need to take some...
Replies
6
Views
179
Back
Top Bottom