EPICS S7-200SMART PLC使用示例

在这里使用了S7-200SMART系列中SR20作为主机和AM03扩张模块,如下图所示:

 1) 新建一个目录s7-200smart,并且进入这个目录,用makeBaseApp.pl构建IOC程序架构:

[root@localhost EPICS]# mkdir s7-200smart
[root@localhost EPICS]# cd s7-200smart/
[root@localhost s7-200smart]#
[root@localhost s7-200smart]# makeBaseApp.pl -t ioc s7-200smart
[root@localhost s7-200smart]# makeBaseApp.pl -i -t ioc s7-200smart
Using target architecture linux-x86_64 (only one available)
The following applications are available:
    s7-200smart
What application should the IOC(s) boot?
The default uses the IOC's name, even if not listed above.
Application name?
[root@localhost s7-200smart]# ls
configure  iocBoot  Makefile  s7-200smartApp

2)更改configure/RELEASE文件的内容,使得程序编译过程中,编译链接程序能够找到所需的库文件:

SUPPORT=/usr/local/EPICS/synApps/support
ASYN=$(SUPPORT)/asyn

S7NODAVE=/usr/local/EPICS/moudles/s7nodave
# If using the sequencer, point SNCSEQ at its top directory:
#SNCSEQ = $(MODULES)/seq-ver

# EPICS_BASE should appear last so earlier modules can override stuff:
EPICS_BASE = /usr/local/EPICS/base

# Set RULES here if you want to use build rules from somewhere
# other than EPICS_BASE:
#RULES = $(MODULES)/build-rules

# These lines allow developers to override these RELEASE settings
# without having to modify this file directly.
-include $(TOP)/../RELEASE.local
-include $(TOP)/../RELEASE.$(EPICS_HOST_ARCH).local
-include $(TOP)/configure/RELEASE.local

3) 进入目录/s7-200smart/s7-200smartApp/src,编辑Makefile文件:

TOP=../..

include $(TOP)/configure/CONFIG
#----------------------------------------
#  ADD MACRO DEFINITIONS AFTER THIS LINE
#=============================

#=============================
# Build the IOC application

PROD_IOC = s7-200smart
# s7-200smart.dbd will be created and installed
DBD += s7-200smart.dbd

# s7-200smart.dbd will be made up from these files:
s7-200smart_DBD += base.dbd

# Include dbd files from all support applications:
s7-200smart_DBD += asyn.dbd
s7-200smart_DBD += drvAsynIPPort.dbd
s7-200smart_DBD += s7nodave.dbd


# Add all the support libraries needed by this IOC
#s7-200smart_LIBS += xxx
s7-200smart_LIBS += asyn
s7-200smart_LIBS += s7nodave

# s7-200smart_registerRecordDeviceDriver.cpp derives from s7-200smart.dbd
s7-200smart_SRCS += s7-200smart_registerRecordDeviceDriver.cpp

# Build the main IOC entry point on workstation OSs.
s7-200smart_SRCS_DEFAULT += s7-200smartMain.cpp
s7-200smart_SRCS_vxWorks += -nil-

# Add support from base/src/vxWorks if needed
#s7-200smart_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary

# Finally link to the EPICS Base libraries
s7-200smart_LIBS += $(EPICS_BASE_IOC_LIBS)

#===========================

include $(TOP)/configure/RULES

4) 进入s7-200smartApp/Db/目录,并且新建一个名为aiRecord.db的文件:

record(ai, "$(P):AnalogInput")
{
 field(SCAN, "I/O Intr")
 field(DTYP, "s7nodave")
 field(INP, "@$(PORT)(DLV=0, DHV=10000) IW66")
 field(LINR, "LINEAR")
 field(EGUL, "0")
 field(EGUF, "10")
 field(EGU, "V")
}

record(longout, "$(P):UInt32Out")
{
 field(SCAN, "Passive")
 field(DTYP, "s7nodave")
 field(EGUL, "0")
 field(EGUF, "10000")
 field(OUT, "@$(PORT) IW66")
}
# 读取一路模拟量输入
record(ai, "$(P):VoltageIn")
{
 field(SCAN, "I/O Intr")
 field(DTYP, "s7nodave")
 field(INP, "@$(PORT)  QD10 float")
}

# 设置一路模拟量输出
record(ao, "$(P):VoltageOut")
{
 field(DTYP, "s7nodave")
 field(OUT, "@$(PORT)  ID10 float")
}

编辑相同目录下的Makefile:

TOP=../..
include $(TOP)/configure/CONFIG
#----------------------------------------
#  ADD MACRO DEFINITIONS AFTER THIS LINE

#----------------------------------------------------
# Create and install (or just install) into <top>/db
# databases, templates, substitutions like this
DB += aiRead.db


#----------------------------------------------------
# If <anyname>.db template is not named <anyname>*.template add
# <anyname>_template = <templatename>

include $(TOP)/configure/RULES

5) 后退到这个IOC的顶层目录执行,make命令:

[root@localhost s7-200smart]# make
make -C ./configure install
make[1]: Entering directory `/usr/local/EPICS/s7-200smart/configure'
...
make[1]: Leaving directory `/usr/local/EPICS/s7-200smart/iocBoot'

6) 进入iocBoot/iocs7-200smart/目录,编译st.cmd文件:

#!../../bin/linux-x86_64/s7-200smart

#- You may have to change s7-200smart to something else
#- everywhere it appears in this file

< envPaths

cd "${TOP}"

## Register all support components
dbLoadDatabase "dbd/s7-200smart.dbd"
s7_200smart_registerRecordDeviceDriver pdbbase

s7nodaveConfigureIsoTcpPort("s7-200smart", "192.168.3.83:102", 0, 1, 0)
s7nodaveConfigurePollGroup("s7-200smart", "1s", 1.0, 0)
s7nodaveConfigurePollGroup("s7-200smart", "default", 0.5, 0)


## Load record instances
dbLoadRecords("db/aiRead.db","P=S7-200SMART,PORT=s7-200smart")

cd "${TOP}/iocBoot/${IOC}"

iocInit

7) 用以下命令启动这个程序:

[root@localhost iocs7-200smart]# ../../bin/linux-x86_64/s7-200smart st.cmd

8)  查看这个IOC下加载的记录:

epics> dbl
S7-200SMART:UInt32Out
S7-200SMART:AnalogInput
S7-200SMART:VoltageIn
S7-200SMART:VoltageOut

9) 用通道命令,将一个数值写用longout记录到PLC的输入映像位置:IW66,然后用ai记录将输入映像位置IW66,读出,并且进行线性转换;用ai记录读取PLC中模拟量转换后的浮点值,用ao记录将一个浮点数值写入输出模拟量所要转换的浮点数:

[blctrl@main-machine damaiaoApp]$ caget S7-200SMART:AnalogInput
S7-200SMART:AnalogInput        0
[blctrl@main-machine damaiaoApp]$ caput S7-200SMART:UInt32Out 100
Old : S7-200SMART:UInt32Out          0
New : S7-200SMART:UInt32Out          100
[blctrl@main-machine damaiaoApp]$ caget S7-200SMART:AnalogInput
S7-200SMART:AnalogInput        0.1
[blctrl@main-machine damaiaoApp]$ caput S7-200SMART:UInt32Out 5555
Old : S7-200SMART:UInt32Out          100
New : S7-200SMART:UInt32Out          5555
[blctrl@main-machine damaiaoApp]$ caget S7-200SMART:AnalogInput
S7-200SMART:AnalogInput        5.555
[blctrl@main-machine ~]$ caput S7-200SMART:VoltageOut 2.55
Old : S7-200SMART:VoltageOut         0
New : S7-200SMART:VoltageOut         2.55
[blctrl@main-machine ~]$ camonitor S7-200SMART:VoltageIn
S7-200SMART:VoltageIn          2023-03-09 14:10:55.370152 1.28834
S7-200SMART:VoltageIn          2023-03-09 14:10:56.321801 1.28979
S7-200SMART:VoltageIn          2023-03-09 14:10:58.319010 1.28942
S7-200SMART:VoltageIn          2023-03-09 14:10:59.366981 2.0298
S7-200SMART:VoltageIn          2023-03-09 14:11:00.317474 6.57335
S7-200SMART:VoltageIn          2023-03-09 14:11:01.365179 8.28631
S7-200SMART:VoltageIn          2023-03-09 14:11:02.315698 8.2874
S7-200SMART:VoltageIn          2023-03-09 14:11:03.362613 8.28885
S7-200SMART:VoltageIn          2023-03-09 14:11:06.312394 8.28921

在AM03的模拟量输入端,接入一个-10V到10V的值,S7-200SMART:AnalogInput就能读入这个模拟量值,将一个-10~10之间的浮点数设置到S7-200SMART:VoltageOut中,用电压表测试AM03的模拟量输出端,就能够测量出对应的电压值。

注释:

在此次实验中,设置了AM03扩展模块中模拟量输入范围为-10V ~ 10V,设置模拟量输出的范围也是-10V ~ 10V。 

一个用于读取和设置模拟量简单的图形用户界面:

以下是一个CSS制作的smart 200的数字量输入/输出,以及寄存器的操作界面:

如果有合作开发EPICS IOC项目,请加以下微信:

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值