pvbrowser如何经过Siemens tcp链接PLC

pvbrowser如何经过Siemens tcp链接PLC


pvbrowser是一款德国的基于Qt的开源组态软件。尽管市场中用的不多,咱们仍是能够经过看其源码学习不少东西。web

pvbrowser里有两种方式经过Simens tcp与PLC通信:Daemon与pvbaddon.编程

Daemon

经过Daemon生成EXE文件

打开pvdevelop,选择菜单栏->daemon->Siemens Tcpapi

shared_memory=C:\\automation\\shm\\siemens.shm
mailbox=C:\\automation\\mbx\\siemens.mbx
# type := S7_200 | S7_300 | S7_400 | S5 | S7_1200 | LOGO
slave=0 adr=192.168.1.99 type=S7_1200 fetch_write=0 function=1 rack_slot=0
idletime=50 milliseconds
#eventlog host=localhost port=6000
# ORG := ORG_DB | ORG_M | ORG_E | ORG_A | ORG_PEPA | ORG_Z | ORG_T
# cycle := slave + org + dbnum + start + len
cycle1 slave=0 org=ORG_E  dbnum=0 start=0 len=1
cycle2 slave=0 org=ORG_A  dbnum=0 start=0 len=1

这里面有如下几个须要注意的点:
1. shared memory和mailbox的文件路径是须要本身建的,这个软件不会给你建。
Note that these directories must be created first by you. Note that the size of the shared memory must be equal in the daemon and in the pvserver.
2.关于 fetch_write的设定
fetch_write=1为fetch/write服务,fetch_write=0为S7链接。
(1) There is the old Fetch/Write protocol from the old S5 PLC
(fetch_write=1).Fetch/Write只支持S5和300,400系列.
(2) And there is the current Siemens PLC protocol introduced with the S7 series of PLC (fetch_write=0).
2. FUNCTION := optional parameter for PLC (1=PG,2=OP,3=Step7Basic)
经验证123都可连通。
3. 经验证,rack_slot这个值设随机值都能通
4. ORG_E指的是Eingang(输入),ORG_A指的是Ausgang(输出),ORG_M是Merker(这个单词没查到,经验证是M区),ORG_DB是Datenbaustein(DB区).此外还有ORG_PEPA指的是Peripheral(外围设备) Area R/W ,ORG_Z意思是Zaehler(计数器),ORG_T意思是Timer(计时器)
设置好之后点compile,而后点close.
这时,项目文件夹下会生成siemensdaemon.cpp,siemensdaemon.h,siemensdaemon.exe和siemensdaemon.mksimens四个文件
运行siemensdaemon.exe文件,数据就从PLC里面读取到共享内存里了(可能会遇到缺乏*.dll文件,在pvbrowser安装目录里找到对应的文件放进项目文件便可)。tcp

如何进行调试

当咱们遇到链接不通的时候怎么办呢,由于是pvbrowser是基于Qt的,咱们能够经过Qt对其进行调试。
1. 新建空Qt控制台项目,添加Deamon生成的siemensdaemon.h和siemensdaemon.cpp文件。并将缺乏的头文件放到目录里,这些头文件能够在pvb安装目录底下找到。
2. 在该项目的makefile里添加svg

win32-g++ {
QMAKE_LFLAGS      += -static-libgcc
win32:LIBS        += $(PVBDIR)/win-mingw/bin/libserverlib.a
win32:LIBS        += $(PVBDIR)/win-mingw/bin/librllib.a
win32:LIBS        += -lws2_32 -ladvapi32 -lpthread
win32:INCLUDEPATH += $(PVBDIR)/pvserver
win32:INCLUDEPATH += $(PVBDIR)/rllib/lib
}

这样项目就建好了,能够进行更改调试。学习

pvbaddon

能够在pvbrowser下载pvbaddon
在pvbaddon\pvbaddon\daemons\siemenstcp\client\release目录下有siemenstcp_client.exe 文件,须要配合ini文件使用。
example.inifetch

# ini file for siemenstcp_client
#
# DEBUG       := 1 | 0
# SLAVE<N>    := IP,PLC_TYPE,FETCH_WRITE,FUNCTION,RACK_SLOT
# PLC_TYPE    := ANY | S7_200 | S7_300 | S7_400 | S5 | S7_1200 | LOGO
# FETCH_WRITE := 1 | 0 # default 1
# FUNCTION    := optional parameter for PLC (1=PG,2=OP,3=Step7Basic)
# RACK_SLOT   := optional parameter for PLC  Byte(upper_3_bit_is_rack / lower_5_bit_is_slot)
# CYCLE<N>    := <count>,<name>
# name        := byte<ORG>(slave,dbnum,adr)   | 
#                float<ORG>(slave,dbnum,adr)  |
#                dword<ORG>(slave,dbnum,adr)  |
#                short<ORG>(slave,dbnum,adr)  |
#                udword<ORG>(slave,dbnum,adr) |
#                ushort<ORG>(slave,dbnum,adr)
# ORG         := ORG_DB | ORG_M | ORG_E | ORG_A | ORG_PEPA | ORG_Z | ORG_T
# HAVETO_SWAP := 1 | 0 # must be 1 on intel machines
# CYCLETIME in milliseconds
# SHARED_MEMORY_SIZE must be equal to SHARED_MEMORY_SIZE of pvserver
# MAX_NAME_LENGTH is maximum length of variable name in shared memory 
#

[GLOBAL]
DEBUG=1
CYCLETIME=1000
HAVETO_SWAP=1

[SOCKET]
NUM_SLAVES=1
SLAVE1=192.168.1.101,ANY,0
#SLAVE2=192.168.1.35,S7_200,0,1,2

# You may also specify the TSAPs explicitly.
# In that case the PLC_TYPE does not care. Use ANY.
[SLAVE1_CONNECT_BLOCK]
#S7-200
CB13='M' # remote TSAP        (not necessary to set explicitly)
CB14='W' # remote TSAP        (not necessary to set explicitly)
CB17='M' # local  TSAP PG     (1=PG,2=OP,3=Step7Basic)
CB18='W' # local  TSAP slot 1 (upper_3_bit_is_rack / lower_5_bit_is_slot)
#S7-300
#CB13=2 # remote TSAP        (not necessary to set explicitly)
#CB14=1 # remote TSAP        (not necessary to set explicitly)
#CB17=1 # local  TSAP PG     (1=PG,2=OP,3=Step7Basic)
#CB18=2 # local  TSAP slot 2 (upper_3_bit_is_rack / lower_5_bit_is_slot)
#S7-400
#CB13=2 # remote TSAP        (not necessary to set explicitly)
#CB14=1 # remote TSAP        (not necessary to set explicitly)
#CB17=1 # local  TSAP PG     (1=PG,2=OP,3=Step7Basic)
#CB18=3 # local  TSAP slot 3 (upper_3_bit_is_rack / lower_5_bit_is_slot)
#S7-1200
#CB13=2 # remote TSAP        (not necessary to set explicitly)
#CB14=1 # remote TSAP        (not necessary to set explicitly)
#CB17=1 # local  TSAP PG     (1=PG,2=OP,3=Step7Basic)
#CB18=0 # local  TSAP slot 0 (upper_3_bit_is_rack / lower_5_bit_is_slot)

[RLLIB]
MAX_NAME_LENGTH=30
SHARED_MEMORY=/srv/automation/shm/siemenstcp1.shm
SHARED_MEMORY_SIZE=65536
MAILBOX=/srv/automation/mbx/siemenstcp1.mbx

[CYCLES]
NUM_CYCLES=4
CYCLE1=10,byteORG_M(1,0,0)
CYCLE2=4,byteORG_E(1,0,0)
CYCLE3=4,byteORG_A(1,0,0)
CYCLE4=4,byteORG_DB(1,1,0)
#CYCLE2=1,byteORG_M(2,2,3)

这里我没有作更改,更改的话与Deamon须要注意的地方相同。
打开cmd cd到该目录下运行调试

siemenstcp_client.exe example.ini

数据就到mailbox里面了code

调试的话,里面有Qt项目文件能够直接打开server

这样PLC数据就读取到shared memory或mailbox里了,能够进行后期的上位编程。