sudo apt-get install build-essential perl tcl tk
git clone --recursive -b 7.0 https://git.launchpad.net/epics-base base-7.0
mv base-7.0 epics-base
cd epics-base
make
在/Home/USERNAME
下按Ctrl+H,打开隐藏文件.bachrc
,添加内容
export EPICS_BASE=/home/ye/Documents/epics-base
export EPICS_HOST_ARCH=$(${EPICS_BASE}/startup/EpicsHostArch)
export PATH=${EPICS_BASE}/bin/${EPICS_HOST_ARCH}:${PATH}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${EPICS_BASE}/lib/linux-x86_64
其中第一行的路径修改为你安装EPICS的路径
在任意处打开终端,输入
softIoc
若出现
>epics
则说明安装成功,在epics>
下输入exit
退出
在${EPICS_BASE}
下新建support文件夹,安装Asyn
cd ${EPICS_BASE}
mkdir support
cd support
git clone https://github.com/epics-modules/asyn.git
cd asyn/configure
打开目录下文件RELEASE
,参考下面进行修改
# RELEASE Location of external products
# Define the following Required or Optional
# either in this file, or in a RELEASE.local
HOME=/home/ye
SUPPORT=/home/ye/Documents/epics-base-7.0/support
-include $(TOP)/../configure/SUPPORT.$(EPICS_HOST_ARCH)
# Optional
# IPAC is only necessary if support for Greensprings IP488 is required
# IPAC release V2-7 or later is required.
# It can be obtained here: https://github.com/epics-modules/ipac
#IPAC=$(SUPPORT)/ipac-2-16
# Optional
# SEQ is required for testIPServer
# It can be obtained here: https://www-csr.bessy.de/control/SoftDist/sequencer/Manual.html
#SNCSEQ=$(SUPPORT)/seq-2-2-5
# Optional
# For sCalcout support in asynOctet - applications include asynCalc.dbd
# It can be obtained here: https://github.com/epics-modules/calc
#CALC=$(SUPPORT)/calc-3-7-4
# Optional
# If CALC was built with SSCAN support then SSCAN must be defined for testEpicsApp
# It can be obtained here: https://github.com/epics-modules/sscan
#SSCAN=$(SUPPORT)/sscan-2-11-5
# Required
# EPICS_BASE 3.14.6 or later is required
# It can be obtained here: https://github.com/epics-base/epics-base
EPICS_BASE=/home/ye/Documents/epics-base-7.0
-include $(TOP)/../configure/EPICS_BASE.$(EPICS_HOST)
主要将${EPICS_BASE}
修改为你安装EPICS的路径,将${HOME}
修改为你的Home路径,将${SUPPORT}
修改为${EPICS_BASE}/support
最后在asyn文件夹下make
cd ${EPICS_BASE}/support/asyn
make
安装流程和安装Asyn大同小异
cd ${EPICS_BASE}/support
git clone https://github.com/paulscherrerinstitute/StreamDevice.git
cd StreamDevice/configure
打开目录下文件RELEASE
,参考下面进行修改
#RELEASE Location of external products
# Run "gnumake clean uninstall install" in the application
# top directory each time this file is changed.
#
# NOTE: The build does not check dependencies on files
# external to this application. Thus you should run
# "gnumake clean uninstall install" in the top directory
# each time EPICS_BASE, SNCSEQ, or any other external
# module defined in the RELEASE file is rebuilt.
TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
# If you don't want to install into $(TOP) then
# define INSTALL_LOCATION_APP here
#INSTALL_LOCATION_APP=<fullpathname>
SUPPORT=/home/ye/Documents/epics-base-7.0/support
-include $(TOP)/../configure/SUPPORT.$(EPICS_HOST_ARCH)
ASYN=$(SUPPORT)/asyn
#CALC=$(SUPPORT)/calc-3-7
#PCRE=$(SUPPORT)/pcre-7-2
# EPICS_BASE usually appears last so other apps can override stuff:
EPICS_BASE=/home/ye/Documents/epics-base-7.0
# 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
主要将${EPICS_BASE}
修改为你安装EPICS的路径,将${SUPPORT}
修改为${EPICS_BASE}/support
,将${ASYN}
修改为${SUPPORT}/asny
最后
cd ${EPICS_BASE}/support/StreamDevice
make
这里作为例子,在任意位置创建一个test.db文件,添加内容:
record(ai, "temperature:water")
{
field(DESC, "Water temperature in the fish tank")
}
然后在该目录下
softIoc -d test.db
另外开一个终端,尝试
caget temperature:water
caget temperature:water.DESC
在任意目录下新建一个项目文件夹,按你的需求命名,如firstIoc
,请将下面所有的firstIoc
替换为你的项目名,之后将项目文件夹路径称为${TOP}
mkdir firstIoc
cd firstIoc
makeBaseApp.pl -t ioc firstIoc
makeBaseApp.pl -t ioc -i firstIoc
在${TOP}/firstIocApp/src
下新建文件support.dbd,
cd firstIocApp/src
touch support.dbd
添加内容为
registrar(drvAsynIPPortRegisterCommands)
registrar(drvAsynSerialPortRegisterCommands)
registrar(vxi11RegisterCommands)
修改${TOP}/firstIocApp/src/Makefile
,添加内容
firstIoc_DBD += base.dbd
firstIoc_DBD += stream.dbd
firstIoc_DBD += asyn.dbd
firstIoc_DBD += drvAsynSerialPort.dbd
firstIoc_DBD += support.dbd
firstIoc_LIBS += stream
firstIoc_LIBS += asyn
修改${TOP}/configure/RELEASE
,添加内容
ASYN = ${EPICS_BASE}/support/asyn
STREAM = ${EPICS_BASE}/support/StreamDevice
在${TOP}/firstIocApp/Db
下添加db文件,这里作为例子新建ttyS1.db
,添加内容,实际的db应该按照你的需求添加
record(ao,"current")
{
field(SCAN,"1 second")
field(DTYP,"stream")
field(OUT,"@ttyS1.proto getCurrent PS0")
}
record(ao,"voltage")
{
field(SCAN,"1 second")
field(DTYP,"stream")
field(OUT,"@ttyS1.proto getVoltage PS0")
}
record(ao,"temperature")
{
field(SCAN,"1 second")
field(DTYP,"stream")
field(OUT,"@ttyS1.proto getTemperature PS0")
}
修改${TOP}/firstIocApp/Db/Makefile
,增加
DB += ttyS1.db
在${TOP}/firstIocApp/Db
下执行make指令
cd ${TOP}/firstIocApp/Db
make
可以在任何地方新建.proto文件,让st.cmd能找到即可,这里的.proto文件创建作为参考:
在${TOP}
下新建文件夹protocols
cd ${TOP}
mkdir protocols
cd protocols
touch ttys1.proto
ttys1.proto的内容为(仅做参考)
terminator = CR LF;
getCurrent {
out "CURRENT?";
in "CURRENT %f A";
}
getVoltage {
out "VOLTAGE?";
in "VOLTAGE %f V";
}
getTemperature {
out "TEMPERATURE?";
in "TEMPERATURE %f Degree";
}
最后修改st.cmd,该文件位于${TOP}/IocBoot/iocfirstIOC
下
st.cmd参考:
#!../../bin/linux-x86_64/test
#- You may have to change test to something else
#- everywhere it appears in this file
< envPaths
epicsEnvSet ("STREAM_PROTOCOL_PATH","../../protocols")
cd "${TOP}"
## Register all support components
dbLoadDatabase "dbd/test.dbd"
test_registerRecordDeviceDriver pdbbase
############ Serial #################
drvAsynSerialPortConfigure("PS0","/dev/ttyS1")
asynSetOption("PS0",0,"baud","115200")
asynSetOption("PS0",0,"bits","8")
asynSetOption("PS0",0,"parity","none")
asynSetOption("PS0",0,"stop","1")
asynSetOption("PS0",0,"clocal","Y")
asynSetOption("PS0",0,"crtscts","N")
############ Serial #################
## Load record instances
dbLoadRecords("db/test.db")
dbLoadRecords("db/ttyS1.db","PORT=PS0,ADDR=0,TIMEOUT=1")
cd "${TOP}/iocBoot/${IOC}"
iocInit
你要修改的地方:添加环境变量STREAM_PROTOCOL_PATH
使能够找到.proto文件,中间Serial
部分为对StreamDevice所需的串口设置,注意第一行中的/dev/ttyS1
需要安装你实际的串口进行修改,如果是USB转串口一般修改为/dev/ttyUSB0
,最后要添加db文件,即dbLoadRecords()
最后为st.cmd添加执行权限,并执行st.cmd
cd ${TOP}/IocBoot/iocfirstIOC
chmod a+x st.cmd
./st.cmd
这里的例子演示还需要一个串口,即上文提到的ttyS1
是使用虚拟串口模拟的,也可以用单片机连接电脑使用USB转串口,这样即为ttyUSB0
,然后.proto文件解析串口发送的数据,使用户可以读到数据
上面都完成后,另外开一个终端,尝试以下指令,将读到串口发送的信息
caget current
caget voltage
caget temperature
camonitor current
本文章使用limfx的vscode插件快速发布