基于EPICS stream模块的直流电源的IOC控制程序实例

2023-11-02 13:04

本文主要是介绍基于EPICS stream模块的直流电源的IOC控制程序实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本实例程序实现了对优利德UDP6720系列直流电源的网络控制和访问,先在此介绍这个项目中使用的硬件:

1、UDP6721直流电源:受控设备

2、moxa串口服务器5150:将UDP6721直流电源设备串口连接转成网络连接

3、香橙派Zero3:运行IOC程序。

 需要EPICS软件模块如下:

  1. base
  2. asyn
  3. stream
  4. autosave

以下步骤描述如何建立这个IOC程序的过程:

1、使用工具命令makeBaseApp.pl构建IOC程序架构,程序架构如下:

root@orangepizero3:/usr/local/EPICS/program/udp6721# ls
bin  configure  db  dbd  document  iocBoot  lib  Makefile  udp6721App

2、修改confiure/RELEASE文件,增加依赖模块所在的路径:

...
SUPPORT=/usr/local/EPICS/synApps/support
ASYN=$(SUPPORT)/asyn
STREAM=$(SUPPORT)/stream/streamDevice
AUTOSAVE=$(SUPPORT)/autosave
...

3、进入udp6721App/src/目录下,编写sub记录中所需要调用函数的源代码以及相应的dbd文件:

// ubRecordSleep.c
#include <stdio.h>
#include <dbDefs.h>
#include <epicsThread.h>
#include <registryFunction.h>
#include <subRecord.h>
#include <epicsExport.h>int mySubDebug = 0;static long mySubInit(struct subRecord *precord)
{if (mySubDebug){printf("Record %s called mySubInit(%p)\n", precord->name, (void *)precord);}printf("subInit was called\n");return 0;
}static long mySubProcess(struct subRecord * precord)
{if(mySubDebug){printf("Record %s called mySubProcess(%p)\n", precord->name,(void *)precord);}epicsThreadSleep(precord->val);return 0;
}
# subRecordSleepSupport.dbd
variable(mySubDebug)
function(mySubInit)
function(mySubProcess)

修改这个目录中的Makefile文件,指明所需要的数据库定义文件以及链接的库文件以及需要编译的源文件:

TOP=../..include $(TOP)/configure/CONFIG
#----------------------------------------
#  ADD MACRO DEFINITIONS AFTER THIS LINE
#=============================#=============================
# Build the IOC applicationPROD_IOC = udp6721
# udp6721.dbd will be created and installed
DBD += udp6721.dbd# udp6721.dbd will be made up from these files:
udp6721_DBD += base.dbd
udp6721_DBD += asyn.dbd
udp6721_DBD += stream.dbd
udp6721_DBD += subRecordSleepSupport.dbd
udp6721_DBD += drvAsynIPPort.dbd
udp6721_DBD += asSupport.dbd# Include dbd files from all support applications:
#udp6721_DBD += xxx.dbd# Add all the support libraries needed by this IOC
udp6721_LIBS += asyn
udp6721_LIBS += stream
udp6721_LIBS += autosaveudp6721_SRCS += subRecordSleep.c
# udp6721_registerRecordDeviceDriver.cpp derives from udp6721.dbd
udp6721_SRCS += udp6721_registerRecordDeviceDriver.cpp# Build the main IOC entry point on workstation OSs.
udp6721_SRCS_DEFAULT += udp6721Main.cpp
udp6721_SRCS_vxWorks += -nil-# Add support from base/src/vxWorks if needed
#udp6721_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary# Finally link to the EPICS Base libraries
udp6721_LIBS += $(EPICS_BASE_IOC_LIBS)#===========================include $(TOP)/configure/RULES

4、进入udp6721App/Db/下编写协议文件,数据库实例文件和用于数据保存的req文件:

1)数据库实例文件:

record(stringin, "$(P)DeviceInfo")
{field (DESC, "Read Device Info of PS1")field (DTYP, "stream")field (INP,  "@udp6721.proto getIDNInfo PS1")field (PINI, "YES")field (SCAN, "10 second")
}record(bo, "$(P)OnOff")
{field (DESC, "Turn On/Off the Device")field (DTYP, "stream")field (OUT,  "@udp6721.proto setSwitch PS1")field (ZNAM, "OFF")field (ONAM, "ON")field (PINI, "YES")field (FLNK, "$(P)OnOff_RBV")
}record(bi, "$(P)OnOff_RBV")
{field (DESC, "The Status of  the Device")field (DTYP, "stream")field (INP,  "@udp6721.proto getSwitch PS1")field (ZNAM, "OFF")field (ONAM, "ON")field (PINI, "YES")field (SCAN, "Passive")
}record(ai, "$(P)Voltage_M")
{field (DESC, "Output Voltage")field (DTYP, "stream")field (INP,  "@udp6721.proto measureVoltage PS1")field (PREC, "2")field (PINI, "YES")
}record(ai, "$(P)Current_M")
{field (DESC, "Output Current")field (DTYP, "stream")field (INP,  "@udp6721.proto measureCurrent PS1")field (PREC, "3")field (SCAN, "I/O Intr")
}record(ai, "$(P)Power_M")
{field (DESC, "Output Power")field (DTYP, "stream")field (INP,  "@udp6721.proto measurePower PS1")field (PREC, "4")field (SCAN, "I/O Intr")
}record(bi, "$(P)CVCC_RBV")
{field (DESC, "Device Output Mode CV/CC")field (DTYP, "stream")field (INP,  "@udp6721.proto getCVCC PS1")field (ZNAM, "CV")field (ONAM, "CC")field (SCAN, "1 second")field (PINI, "YES")
}record(ai, "$(P)Voltage_RBV")
{field (DESC, "Output Voltage")field (DTYP, "stream")field (INP,  "@udp6721.proto getVoltage PS1")field (PREC, "2")field (PINI, "YES")
}record(ai, "$(P)Current_RBV")
{field (DESC, "Output Current")field (DTYP, "stream")field (INP,  "@udp6721.proto getCurrent PS1")field (PREC, "3")field (PINI, "YES")
}record(ao, "$(P)SetVoltage")
{field (DESC, "Output Voltage")field (DTYP, "stream")field (OUT,  "@udp6721.proto setVoltage PS1")field (PREC, "2")field (FLNK, "$(P)SubSleep")
}record(ao, "$(P)SetCurrent")
{field (DESC, "Output Current")field (DTYP, "stream")field (OUT,  "@udp6721.proto setCurrent PS1")field (PREC, "3")field (FLNK, "$(P)SubSleep")
}record(fanout, "$(P)Fanout")
{field(SELM,"All")field(SCAN, "Passive")field(LNK0, "$(P)Voltage_M")field(LNK1, "$(P)Voltage_RBV")field(LNK2, "$(P)Current_RBV")
}record(sub,"$(P)SubSleep")
{field(INAM,"mySubInit")field(SNAM,"mySubProcess")field(VAL, "0.8")field(FLNK, "$(P)Fanout.PROC")
}record(ao, "$(P)SetVProtectValue")
{field (DESC, "Set Protect Voltage")field (DTYP, "stream")field (OUT,  "@udp6721.proto setVProtectValue PS1")field (PREC, "2")field (FLNK, "$(P)VProtectValue_RBV")
}record(ai, "$(P)VProtectValue_RBV")
{field (DESC, "Protect Voltage")field (DTYP, "stream")field (INP,  "@udp6721.proto getVProtectValue PS1")field (PREC, "2")field (PINI, "YES")
}record(ao, "$(P)SetCProtectValue")
{field (DESC, "Set Protect Currrent")field (DTYP, "stream")field (OUT,  "@udp6721.proto setCProtectValue PS1")field (PREC, "3")field (FLNK, "$(P)CProtectValue_RBV")
}record(ai, "$(P)CProtectValue_RBV")
{field (DESC, "Protect Current")field (DTYP, "stream")field (INP,  "@udp6721.proto getCProtectValue PS1")field (PREC, "3")field (PINI, "YES")
}record(bo, "$(P)OnOffVProtectState")
{field (DESC, "Set Volt Protect State")field (DTYP, "stream")field (ZNAM, "ON")field (ONAM, "OFF")field (OUT,  "@udp6721.proto switchVProtectState PS1")field (FLNK, "$(P)OnOffVProtectState_RBV")
}record(bi, "$(P)OnOffVProtectState_RBV")
{field (DESC, "Volt Protect State")field (DTYP, "stream")field (ZNAM, "ON")field (ONAM, "OFF")field (INP,  "@udp6721.proto getVProtectState PS1")field (PINI, "YES")
}record(bo, "$(P)OnOffCProtectState")
{field (DESC, "Set Current Protect State")field (DTYP, "stream")field (ZNAM, "ON")field (ONAM, "OFF")field (OUT,  "@udp6721.proto switchCProtectState PS1")field (FLNK, "$(P)OnOffCProtectState_RBV")
}record(bi, "$(P)OnOffCProtectState_RBV")
{field (DESC, "Current Protect State")field (DTYP, "stream")field (ZNAM, "ON")field (ONAM, "OFF")field (INP,  "@udp6721.proto getCProtectState PS1")field (PINI, "YES")
}record(stringout, "$(P)SetRemote")
{field (DESC, "Current Protect State")field (DTYP, "stream")field (OUT,  "@udp6721.proto setRemote PS1")field (FLNK, "$(P)Remote_RBV")
}record(bi, "$(P)Remote_RBV")
{field (DESC, "Remote State")field (DTYP, "stream")field (INP,  "@udp6721.proto getRemote PS1")field (ZNAM, "YES")field (ONAM, "NO")field (PINI, "YES")
}

协议文件:

Terminator = LF;getIDNInfo {out "*IDN?";in "Uni-Trend,%s";
}# Switch is an enum, either OFF or ON
# use bi and bo recordsgetSwitch {out "OUTPUT?"; in "%{OFF|ON}";
}setSwitch {out "OUTPUT %{OFF|ON}";@init { getSwitch; }
}measureVoltage {out "MEASure:ALL?";in  "%f,%*f,%*f";
}measureCurrent {in  "%*f,%f,%*f";
}measurePower {in "%*f,%*f,%f";
}getCVCC {out "OUTPUT:CVCC?"; in "%{CV|CC}";
}setVoltage {out "VOLTage %.2f";
}getVoltage {out "VOLTage?";in "%f";
}setCurrent {out "CURRent %.3f";
}getCurrent {out "CURRent?";in "%f";
}setVProtectValue {out "VOLTage:PROTection %.2f";
}getVProtectValue {out "VOLTage:PROTection?";in "%f";
}setCProtectValue {out "CURRent:PROTection %.3f";
}getCProtectValue {out "CURRent:PROTection?";in "%f";
}switchVProtectState {out "VOLTage:PROTection:STATe %{ON|OFF}";
}getVProtectState {out "VOLTage:PROTection:STATe?";in "%{ON|OFF}";
}switchCProtectState {out "CURRent:PROTection:STATe {ON|OFF}";
}getCProtectState {out "CURRent:PROTection:STATe?";in "%{ON|OFF}";
}setRemote {out "SYSTem:REMote";
}getRemote {out "SYSTem:REMote?";in "%{YES|NO}";
}

存储配置文件:

$(P)SetVoltage
$(P)SetCurrent
$(P)SetVProtectValue
$(P)SetCProtectValue
$(P)SetRemote

编辑相同路径下的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 += udp6721.proto
DB += udp6721.db
DB += udp6721.req#----------------------------------------------------
# If <anyname>.db template is not named <anyname>*.template add
# <anyname>_template = <templatename>include $(TOP)/configure/RULES

5 切换到顶层目录,执行make命令,进行编译。

6 进入启动目录 iocBoot/iocudp6721/:

创建两个目录autosave和req,并且在req下添加一个auto_settings.req文件,内容如下:

file udp6721.req  P=$(P)

7 编辑启动文件st.cmd,内容如下:

#!../../bin/linux-aarch64/udp6721#- You may have to change udp6721 to something else
#- everywhere it appears in this file< envPathscd "${TOP}"## Register all support components
dbLoadDatabase "dbd/udp6721.dbd"
udp6721_registerRecordDeviceDriver pdbbasedrvAsynIPPortConfigure("PS1", "192.168.3.101:4001", 0, 0 ,1)## Load record instances
epicsEnvSet ("STREAM_PROTOCOL_PATH", "$(TOP)/db/")
dbLoadRecords("db/udp6721.db","P=UDP6721:")set_requestfile_path("$(TOP)/db")
set_requestfile_path("$(TOP)/iocBoot/$(IOC)/req/")# 通过调用set_savefile_path函数指定你想要.sav文件被写到哪个目录中。
set_savefile_path("$(TOP)/iocBoot/$(IOC)/autosave/")# 使用set_pass<N>_restoreFile()函数
# 指定哪些save文件要在记录初始化前(pass 0)前被恢复,以及哪些save文件在记录初始化后(pass 1)被恢复
set_pass1_restoreFile("auto_settings.sav")save_restoreSet_numSeqFiles(3)
save_restoreSet_SeqPeriodInSeconds(600)
save_restoreSet_RetrySeconds(60)
save_restoreSet_CAReconnect(1)
save_restoreSet_CallbackTimeout(-1)cd "${TOP}/iocBoot/${IOC}"
iocInitcreate_monitor_set("auto_settings.req",5,"P=UDP6721:")

8 启动这个IOC,用dbl查看加载的记录实例:

 ../../bin/linux-aarch64/udp6721 st.cmd
epics> dbl
UDP6721:Voltage_M
UDP6721:Current_M
UDP6721:Power_M
UDP6721:Voltage_RBV
UDP6721:Current_RBV
UDP6721:VProtectValue_RBV
UDP6721:CProtectValue_RBV
UDP6721:SetVoltage
UDP6721:SetCurrent
UDP6721:SetVProtectValue
UDP6721:SetCProtectValue
UDP6721:OnOff_RBV
UDP6721:CVCC_RBV
UDP6721:OnOffVProtectState_RBV
UDP6721:OnOffCProtectState_RBV
UDP6721:Remote_RBV
UDP6721:OnOff
UDP6721:OnOffVProtectState
UDP6721:OnOffCProtectState
UDP6721:Fanout
UDP6721:DeviceInfo
UDP6721:SetRemote
UDP6721:SubSleep

9 用CSS查看连接以上记录实例:

可以通过以上图形界面设置直流电源的电压和电流输出。 

这篇关于基于EPICS stream模块的直流电源的IOC控制程序实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/330789

相关文章

C# WinForms存储过程操作数据库的实例讲解

《C#WinForms存储过程操作数据库的实例讲解》:本文主要介绍C#WinForms存储过程操作数据库的实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、存储过程基础二、C# 调用流程1. 数据库连接配置2. 执行存储过程(增删改)3. 查询数据三、事务处

springboot security验证码的登录实例

《springbootsecurity验证码的登录实例》:本文主要介绍springbootsecurity验证码的登录实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录前言代码示例引入依赖定义验证码生成器定义获取验证码及认证接口测试获取验证码登录总结前言在spring

tomcat多实例部署的项目实践

《tomcat多实例部署的项目实践》Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,本文主要介绍了tomcat多实例部署的项目实践,具有一定的参考价值,感兴趣的可... 目录1.创建项目目录,测试文China编程件2js.创建实例的安装目录3.准备实例的配置文件4.编辑实例的

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤

Python使用date模块进行日期处理的终极指南

《Python使用date模块进行日期处理的终极指南》在处理与时间相关的数据时,Python的date模块是开发者最趁手的工具之一,本文将用通俗的语言,结合真实案例,带您掌握date模块的六大核心功能... 目录引言一、date模块的核心功能1.1 日期表示1.2 日期计算1.3 日期比较二、六大常用方法详

Spring 中使用反射创建 Bean 实例的几种方式

《Spring中使用反射创建Bean实例的几种方式》文章介绍了在Spring框架中如何使用反射来创建Bean实例,包括使用Class.newInstance()、Constructor.newI... 目录1. 使用 Class.newInstance() (仅限无参构造函数):2. 使用 Construc

python中time模块的常用方法及应用详解

《python中time模块的常用方法及应用详解》在Python开发中,时间处理是绕不开的刚需场景,从性能计时到定时任务,从日志记录到数据同步,时间模块始终是开发者最得力的工具之一,本文将通过真实案例... 目录一、时间基石:time.time()典型场景:程序性能分析进阶技巧:结合上下文管理器实现自动计时

MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析

《MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析》本文将详细讲解MyBatis-Plus中的lambdaUpdate用法,并提供丰富的案例来帮助读者更好地理解和应... 目录深入探索MyBATis-Plus中Service接口的lambdaUpdate用法及示例案例背景

MyBatis-Plus中静态工具Db的多种用法及实例分析

《MyBatis-Plus中静态工具Db的多种用法及实例分析》本文将详细讲解MyBatis-Plus中静态工具Db的各种用法,并结合具体案例进行演示和说明,具有很好的参考价值,希望对大家有所帮助,如有... 目录MyBATis-Plus中静态工具Db的多种用法及实例案例背景使用静态工具Db进行数据库操作插入

Java之并行流(Parallel Stream)使用详解

《Java之并行流(ParallelStream)使用详解》Java并行流(ParallelStream)通过多线程并行处理集合数据,利用Fork/Join框架加速计算,适用于大规模数据集和计算密集... 目录Java并行流(Parallel Stream)1. 核心概念与原理2. 创建并行流的方式3. 适