Ortec974A EPICS IOC程序

2023-10-30 17:53
文章标签 程序 ioc epics ortec974a

本文主要是介绍Ortec974A EPICS IOC程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1) 创建一个用户存放这个IOC程序结构的目录:

root@orangepi4-lts:/usr/local/EPICS/program# mkdir ortec974A
root@orangepi4-lts:/usr/local/EPICS/program# cd ortec974A/
root@orangepi4-lts:/usr/local/EPICS/program/ortec974A# ls

2)使用makeBaseApp.pl构建这个IOC程序架构:

root@orangepi4-lts:/usr/local/EPICS/program/ortec974A# makeBaseApp.pl -t ioc ortec974A
root@orangepi4-lts:/usr/local/EPICS/program/ortec974A# makeBaseApp.pl -i -t ioc ortec974A
Using target architecture linux-aarch64 (only one available)
The following applications are available:ortec974A
What application should the IOC(s) boot?
The default uses the IOC's name, even if not listed above.
Application name?
root@orangepi4-lts:/usr/local/EPICS/program/ortec974A# ls
configure  iocBoot  Makefile  ortec974AApp

3)编辑configure/RELEASE文件,添加这个IOC程序所需要的其它依赖模块:

...
SUPPORT=/usr/local/EPICS/synApps/support
ASYN=$(SUPPORT)/asyn
AUTOSAVE=$(SUPPORT)/autosave
CALC=$(SUPPORT)/calc
SCALER=$(SUPPORT)/scaler
...

4) 进入源文件目录ortec974AApp/src目录下:

a) 编写974A驱动程序源文件:

// drvOrtec974A.cpp
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <math.h>#include <asynPortDriver.h>
#include <asynOctetSyncIO.h>
#include <epicsEvent.h>
#include <epicsThread.h>
#include <epicsTime.h>
#include <errlog.h>
#include <iocsh.h>
#include <epicsExport.h> /* Defines epicsExportSharedSymbols */#include "devScalerAsyn.h"#define MAX_CHANNELS 4#define timeOut 0.1
static const char *driverName= "Scaler974A";class Scaler974A:public asynPortDriver
{
public:Scaler974A(const char *portName, const char *serialPort, int serialAddr, int poll);virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);virtual asynStatus readInt32Array(asynUser *pasynUser,epicsInt32 *value, size_t nElements, size_t *nIn);virtual void report(FILE *fp, int details);void eventThread();private:int scalerReset;int scalerChannels;int scalerRead;int scalerReadSingle;int scalerPreset;int scalerArm;int scalerDone;double polltime;epicsEventId eventId;asynUser *pasynUserScaler;asynStatus sendCommand(const char *command, char *statusString, size_t maxStatusLen, size_t *statusLen);
};static void eventThreadC(void *pPvt)
{Scaler974A *pScaler974A = (Scaler974A *)pPvt;pScaler974A->eventThread();
}Scaler974A::Scaler974A(const char *portName, const char *serialPort, int serialAddr, int poll):asynPortDriver(portName, MAX_CHANNELS,asynInt32Mask | asynInt32ArrayMask | asynDrvUserMask,asynInt32Mask,/* Should also be ASYN_CANBLOCK, but device support does not work with asynchronous devices */ASYN_MULTIDEVICE,1,0,0)
{int i;asynStatus status;static const char *functionName="Scaler974A";if (poll==0) poll=100;this->polltime=poll / 1000.;this->eventId = epicsEventCreate(epicsEventEmpty);status = pasynOctetSyncIO->connect(serialPort, serialAddr, &this->pasynUserScaler, NULL);if (status != asynSuccess) {asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,"%s:%s: error connecting to port %s address %d\n",driverName, functionName, serialPort, serialAddr);return;}createParam(SCALER_RESET_COMMAND_STRING,        asynParamInt32,     &this->scalerReset);createParam(SCALER_CHANNELS_COMMAND_STRING,     asynParamInt32,     &this->scalerChannels);createParam(SCALER_READ_COMMAND_STRING,         asynParamInt32Array,&this->scalerRead);createParam(SCALER_READ_SINGLE_COMMAND_STRING,  asynParamInt32,     &this->scalerReadSingle);createParam(SCALER_PRESET_COMMAND_STRING,       asynParamInt32,     &this->scalerPreset);createParam(SCALER_ARM_COMMAND_STRING,          asynParamInt32,     &this->scalerArm);createParam(SCALER_DONE_COMMAND_STRING,         asynParamInt32,     &this->scalerDone);setIntegerParam(scalerChannels, MAX_CHANNELS);setIntegerParam(scalerDone, 1);for (i=0; i<MAX_CHANNELS; i++) setIntegerParam(i, scalerReadSingle, 0);epicsThreadCreate("Scaler974A",epicsThreadPriorityMedium,epicsThreadGetStackSize(epicsThreadStackMedium),(EPICSTHREADFUNC)eventThreadC,this);
}asynStatus Scaler974A::sendCommand(const char *command, char *statusString, size_t maxStatusLen, size_t *statusLen)
{size_t nWrite;asynStatus status;double timeout = 1.0;int eomReason;static const char *functionName = "sendCommand";/** asynStatus (*writeRead)(asynUser *pasynUser,const char *write_buffer, size_t write_buffer_len,char *read_buffer, size_t read_buffer_len,double timeout,size_t *nbytesOut, size_t *nbytesIn, int *eomReason);要写的字符串,要写的字符串长度,读出缓存,要读的字节数目,超时时间,实际写出的字节数,实际读入的字符数,结束原因asynStatus (*write)(asynUser *pasynUser,  char const *buffer, size_t buffer_len,double timeout,size_t *nbytesTransfered);asynStatus (*read)(asynUser *pasynUser, char *buffer, size_t buffer_len,double timeout, size_t *nbytesTransfered,int *eomReason);** */status = pasynOctetSyncIO->write(this->pasynUserScaler, command, strlen(command),  timeout, &nWrite);
//      printf("In sendCommand write status: %d,write content:%s,write length:%d\n", status, command, nWrite);if (status != asynSuccess) goto done;epicsThreadSleep(.1);status = pasynOctetSyncIO->read(this->pasynUserScaler,statusString, maxStatusLen, timeout, statusLen, &eomReason);
//      printf("In sendCommand read status: %d, statusString:%s\n", status, statusString);done:if (status != asynSuccess) {asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,"%s:%s: writing command %s, error=%s\n",driverName, functionName, command, this->pasynUserScaler->errorMessage);}return(status);
}asynStatus Scaler974A::writeInt32(asynUser *pasynUser, epicsInt32 value)
{int function = pasynUser->reason;char response[256];size_t responseLen;asynStatus status = asynSuccess;static const char *functionName="writeInt32";setIntegerParam(function, value);if(function==this->scalerReset){this->sendCommand("STOP\r", response, sizeof(response), &responseLen);//printf("STOP:%s\n", response);this->sendCommand("CLEAR_ALL\r", response, sizeof(response), &responseLen);//printf("CLEAR_ALL:%s\n", response);asynPrint(pasynUser, ASYN_TRACE_FLOW, "%s:%s scalerReset\n",driverName, functionName);}else if(function==this->scalerArm){if(value !=0){/* Start counting */this->sendCommand("START\r", response, sizeof(response), &responseLen);
//          printf("START:%s\n", response);setIntegerParam(scalerDone, 0);epicsEventSignal(this->eventId);}else{/* Stop counting */status = this->sendCommand("STOP\r", response, sizeof(response), &responseLen);
//          printf("STOP:%s\n", response);setIntegerParam(scalerDone, 1);}asynPrint(pasynUser, ASYN_TRACE_FLOW, "%s:%s scalerArm=%d\n", driverName, functionName,value);}else if(function==this->scalerPreset){int m,n;char newstr[25];n=(int)log10(double(value));m=(int)(value/pow(10.0,n));sprintf(newstr, "SET_COUNT_PRESET %d,%d\r", m, n);this->sendCommand(newstr, response, sizeof(response), &responseLen);
//      printf("SET_COUNT_PRESET:%s\n", response);asynPrint(pasynUser, ASYN_TRACE_FLOW, "%s;%s scalerPreset channel", driverName, functionName);}else{asynPrint(pasynUser,ASYN_TRACE_ERROR,"%s:%s got illegal function %d\n", driverName, functionName, function);}callParamCallbacks();return(status);
}asynStatus Scaler974A::readInt32Array(asynUser *pasynUser, epicsInt32 *value, size_t maxChannel, size_t *nIn)
{static const char *functionName="readInt32Array";int function = pasynUser->reason;int temp;int i;if (maxChannel > MAX_CHANNELS) maxChannel = MAX_CHANNELS;*nIn = maxChannel;if (function==scalerRead){for (i=0; i<(int)maxChannel; i++){getIntegerParam(i, scalerReadSingle, &temp);value[i] = temp;}asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,"%s:%s: value=%d %d %d %d\n",driverName, functionName, value[0], value[1], value[2], value[3]);} else {asynPrint(pasynUser,ASYN_TRACE_ERROR,"%s:%s got illegal function %d\n", driverName, functionName,  function);return(asynError);}return(asynSuccess);
}void Scaler974A::report(FILE *fp, int details)
{asynPortDriver::report(fp, details);
}void Scaler974A::eventThread()
{int done, presetCount;char response[100], statusString[256];size_t responseLen, statusLen;int counts[MAX_CHANNELS];int i;asynStatus status;static const char *functionName="eventThread";while(1){epicsEventMustWait(this->eventId);while(1){status = this->sendCommand("SHOW_COUNTS\r", statusString, sizeof(statusString), &statusLen);sscanf(statusString, "%d;%d;%d;%d;",&counts[0], &counts[1], &counts[2], &counts[3]);
//          printf("%d;%d;%d;%d\n", counts[0],counts[1],counts[2],counts[3]);asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"%s:%s status=%d, counts=%d %d %d %d\n",driverName, functionName, status, counts[0], counts[1], counts[2], counts[3]);this->lock();/* Get value of done in case scaler was stopped by scalerArm(0) */getIntegerParam(scalerDone, &done);getIntegerParam(scalerPreset, &presetCount);if (!done && (counts[0] >= presetCount)) done = 1;setIntegerParam(scalerDone, done);for (i=0; i<MAX_CHANNELS; i++) {setIntegerParam(i, scalerReadSingle, counts[i]);callParamCallbacks(i, i);}this->unlock();if (done) break;epicsThreadSleep(this->polltime/1000.0);}}
}extern "C" int initScaler974A(const char *portName, const char *serialPort, int serialAddr, int poll)
{new Scaler974A(portName, serialPort, serialAddr, poll);return(asynSuccess);
}/* iocsh function */
static const iocshArg initArg0 = {"Port Name", iocshArgString};
static const iocshArg initArg1 = {"IPPort", iocshArgString};
static const iocshArg initArg2 = {"Addr", iocshArgString};
static const iocshArg initArg3 = {"Poll", iocshArgInt};
static const iocshArg *const initArgs[] = {&initArg0,&initArg1,&initArg2,&initArg3};
static const iocshFuncDef initFuncDef = {"initScaler974A",4, initArgs};
static void initCallFunc(const iocshArgBuf *args)
{initScaler974A(args[0].sval, args[1].sval, args[2].ival, args[3].ival);
}void Scaler974ARegister(void)
{iocshRegister(&initFuncDef,initCallFunc);
}extern "C" {
epicsExportRegistrar(Scaler974ARegister);
}

b) 添加一个dbd文件ortec974ASupport.dbd:

registrar(Scaler974ARegister)

c) 修改同一目录下Makefile文件,指定编译中需要包含的库文件和源文件:

TOP=../..include $(TOP)/configure/CONFIG
#----------------------------------------
#  ADD MACRO DEFINITIONS AFTER THIS LINE
#=============================#=============================
# Build the IOC applicationPROD_IOC = ortec974A
# ortec974A.dbd will be created and installed
DBD += ortec974A.dbd# ortec974A.dbd will be made up from these files:
ortec974A_DBD += base.dbd
ortec974A_DBD += ortec974ASupport.dbd# Include dbd files from all support applications:
#ortec974A_DBD += xxx.dbdortec974A_DBD += drvAsynIPPort.dbd
ortec974A_DBD += asyn.dbd
ortec974A_DBD += scalerSupport.dbd
ortec974A_DBD += calcSupport.dbd
ortec974A_DBD += asSupport.dbd# Include dbd files from all support applications:
#ortec974A_DBD += xxx.dbd# Add all the support libraries needed by this IOC
ortec974A_LIBS += asyn
ortec974A_LIBS += scaler
ortec974A_LIBS += calc
ortec974A_LIBS += autosave# Add all the support libraries needed by this IOC
#ortec974A_LIBS += xxxortec974A_SRCS += drvOrtec974A.cpp
# ortec974A_registerRecordDeviceDriver.cpp derives from ortec974A.dbd
ortec974A_SRCS += ortec974A_registerRecordDeviceDriver.cpp# Build the main IOC entry point on workstation OSs.
ortec974A_SRCS_DEFAULT += ortec974AMain.cpp
ortec974A_SRCS_vxWorks += -nil-# Add support from base/src/vxWorks if needed
#ortec974A_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary# Finally link to the EPICS Base libraries
ortec974A_LIBS += $(EPICS_BASE_IOC_LIBS)#===========================include $(TOP)/configure/RULES
#----------------------------------------
#  ADD RULES AFTER THIS LINE

5) 进入ortec974AApp/Db目录,编写一个用于自动保存的文件scaler4_settings.req:

$(P)$(S).TP
$(P)$(S).TP1
$(P)$(S).CONT
$(P)$(S).DLY1
$(P)$(S).RAT1
$(P)$(S).PREC
$(P)$(S).FREQ
$(P)$(S).RATE
$(P)$(S).DLY
$(P)$(S).COUT
file "scaler_channelN_settings.req", P=$(P), S=$(S), Ch=1
file "scaler_channelN_settings.req", P=$(P), S=$(S), Ch=2
file "scaler_channelN_settings.req", P=$(P), S=$(S), Ch=3
file "scaler_channelN_settings.req", P=$(P), S=$(S), Ch=4

在同一目录下的Makefile中添加一行:DB += scaler4_settings.req

6) 退出到这个IOC的顶层目录,执行make进行程序编译。

7)进入到启动目录iocBoot/iocortec974A,创建两个目录:

root@orangepi4-lts:/usr/local/EPICS/program/ortec974A/iocBoot/iocortec974A# mkdir -p req/ortec974A
root@orangepi4-lts:/usr/local/EPICS/program/ortec974A/iocBoot/iocortec974A# mkdir -p autosave/ortec974A

在req/ortec974A下编写一个用于自动保存的文件auto_settings.req,内容如下:

file scaler4_settings.req  P=$(P) S=$(S)

编写启动脚本:

#!../../bin/linux-aarch64/ortec974A#- You may have to change ortec974A to something else
#- everywhere it appears in this file< envPathscd "${TOP}"## Register all support components
dbLoadDatabase "dbd/ortec974A.dbd"
ortec974A_registerRecordDeviceDriver pdbbasedrvAsynIPPortConfigure("ortec974A", "192.168.3.30:4001", 0, 0 ,1)initScaler974A("tcportec974A","ortec974A",0,10)
dbLoadRecords("${SCALER}/db/scaler.db", "P=Ortec974A:,S=Scaler1,OUT=@asyn(tcportec974A 0 0),DTYP=Asyn Scaler,FREQ=10,TP=1,TP1=0.5,PR1=1,CONT=1")set_requestfile_path("$(TOP)/db")
set_requestfile_path("$(SCALER)/db")
set_requestfile_path("$(TOP)/iocBoot/$(IOC)/req/ortec974A")# 通过调用set_savefile_path函数指定你想要.sav文件被写到哪个目录中。
set_savefile_path("$(TOP)/iocBoot/$(IOC)/autosave/ortec974A")# 使用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)dbLoadRecords("$(ASYN)/db/asynRecord.db","P=Ortec974A:Scaler1:,R=Asyn,PORT=ortec974A,ADDR=0,IMAX=100,OMAX=100")cd "${TOP}/iocBoot/${IOC}"
iocInitcreate_monitor_set("auto_settings.req",5,"P=Ortec974A:,S=Scaler1")

8) 用以上启动脚本启动这个IOC程序:

root@orangepi4-lts:/usr/local/EPICS/program/ortec974A/iocBoot/iocortec974A# ../../bin/linux-aarch64/ortec974A st.cmd

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

epics> dbl
Ortec974A:Scaler1:Asyn
Ortec974A:Scaler1

10) 用CSS编写操作客户端:

11) 在97A的3号输入端口接入一个3MHz的TTL信号,将计数时间设置为1.0秒,点击Count按钮,进行1秒钟计数:

通道3能够读出计数器的正确计数值。 

这篇关于Ortec974A EPICS IOC程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

EMLOG程序单页友链和标签增加美化

单页友联效果图: 标签页面效果图: 源码介绍 EMLOG单页友情链接和TAG标签,友链单页文件代码main{width: 58%;是设置宽度 自己把设置成与您的网站宽度一样,如果自适应就填写100%,TAG文件不用修改 安装方法:把Links.php和tag.php上传到网站根目录即可,访问 域名/Links.php、域名/tag.php 所有模板适用,代码就不粘贴出来,已经打

跨系统环境下LabVIEW程序稳定运行

在LabVIEW开发中,不同电脑的配置和操作系统(如Win11与Win7)可能对程序的稳定运行产生影响。为了确保程序在不同平台上都能正常且稳定运行,需要从兼容性、驱动、以及性能优化等多个方面入手。本文将详细介绍如何在不同系统环境下,使LabVIEW开发的程序保持稳定运行的有效策略。 LabVIEW版本兼容性 LabVIEW各版本对不同操作系统的支持存在差异。因此,在开发程序时,尽量使用

CSP 2023 提高级第一轮 CSP-S 2023初试题 完善程序第二题解析 未完

一、题目阅读 (最大值之和)给定整数序列 a0,⋯,an−1,求该序列所有非空连续子序列的最大值之和。上述参数满足 1≤n≤105 和 1≤ai≤108。 一个序列的非空连续子序列可以用两个下标 ll 和 rr(其中0≤l≤r<n0≤l≤r<n)表示,对应的序列为 al,al+1,⋯,ar​。两个非空连续子序列不同,当且仅当下标不同。 例如,当原序列为 [1,2,1,2] 时,要计算子序列 [

这些心智程序你安装了吗?

原文题目:《为什么聪明人也会做蠢事(四)》 心智程序 大脑有两个特征导致人类不够理性,一个是处理信息方面的缺陷,一个是心智程序出了问题。前者可以称为“认知吝啬鬼”,前几篇文章已经讨论了。本期主要讲心智程序这个方面。 心智程序这一概念由哈佛大学认知科学家大卫•帕金斯提出,指个体可以从记忆中提取出的规则、知识、程序和策略,以辅助我们决策判断和解决问题。如果把人脑比喻成计算机,那心智程序就是人脑的

uniapp设置微信小程序的交互反馈

链接:uni.showToast(OBJECT) | uni-app官网 (dcloud.net.cn) 设置操作成功的弹窗: title是我们弹窗提示的文字 showToast是我们在加载的时候进入就会弹出的提示。 2.设置失败的提示窗口和标签 icon:'error'是设置我们失败的logo 设置的文字上限是7个文字,如果需要设置的提示文字过长就需要设置icon并给

基于SpringBoot的宠物服务系统+uniapp小程序+LW参考示例

系列文章目录 1.基于SSM的洗衣房管理系统+原生微信小程序+LW参考示例 2.基于SpringBoot的宠物摄影网站管理系统+LW参考示例 3.基于SpringBoot+Vue的企业人事管理系统+LW参考示例 4.基于SSM的高校实验室管理系统+LW参考示例 5.基于SpringBoot的二手数码回收系统+原生微信小程序+LW参考示例 6.基于SSM的民宿预订管理系统+LW参考示例 7.基于

Spring Roo 实站( 一 )部署安装 第一个示例程序

转自:http://blog.csdn.net/jun55xiu/article/details/9380213 一:安装 注:可以参与官网spring-roo: static.springsource.org/spring-roo/reference/html/intro.html#intro-exploring-sampleROO_OPTS http://stati

未来工作趋势:零工小程序在共享经济中的作用

经济在不断发展的同时,科技也在飞速发展。零工经济作为一种新兴的工作模式,正在全球范围内迅速崛起。特别是在中国,随着数字经济的蓬勃发展和共享经济模式的深入推广,零工小程序在促进就业、提升资源利用效率方面显示出了巨大的潜力和价值。 一、零工经济的定义及现状 零工经济是指通过临时性、自由职业或项目制的工作形式,利用互联网平台快速匹配供需双方的新型经济模式。这种模式打破了传统全职工作的界限,为劳动

Java程序到CPU上执行 的步骤

相信很多的小伙伴在最初学习编程的时候会容易产生一个疑惑❓,那就是编写的Java代码究竟是怎么一步一步到CPU上去执行的呢?CPU又是如何执行的呢?今天跟随小编的脚步去化解开这个疑惑❓。 在学习这个过程之前,我们需要先讲解一些与本内容相关的知识点 指令 指令是指导CPU运行的命令,主要由操作码+被操作数组成。 其中操作码用来表示要做什么动作,被操作数是本条指令要操作的数据,可能是内存地址,也