网络继电器的EPICS IOC搭建
http://www.corxnet.com/product/showproduct.php?id=36
https://item.taobao.com/item.htm?spm=a1z10.5-c-s.w4002-21473915904.22.6e3c5ed08NWExp&id=520395007720
推荐这款可网络控制的继电器,16路继电器,16路IN,折腾了好几天在几位同事的帮助下终于把IOC调通了。基本的通过PV控制继电器的开关都调试成功,点控还没做,以后有空再做吧,如果看到的愿意做的可以继续做下去,不过labview程序把点控做好了,欢迎去下载:
https://gitee.com/lup9304/tuning-tools/blob/master/netio1.0.llb
这东西用起来很方便,比plc、西门子模块等方式搭建IO控制省事多了,一般的使用足够了,如果大电流大功率使用,可以自己外加继电器,用这个网络继电器控制外加的继电器即可。
具体怎么编译IOC,可以参看下面链接:
https://epics.anl.gov/modules/soft/asyn/R4-24/HowToDoSerial/HowToDoSerial_StreamDevice.html
需要socket通信,在上面链接里加dbd这一步时:HPE3631Atest_DBD += drvAsynSerialPort.dbd,换成:drvAsynIPPort.dbd就好了。
之后就是编写db、proto、st.cmd文件了。附上相关的文件,写的很不专业,欢迎大家下载使用并请修改的更简洁:
[ioc@localhost iocJDQ016]$ cat st.cmd
#!../../bin/linux-x86_64/JDQ016
#- You may have to change JDQ016 to something else
#- everywhere it appears in this file
< envPaths
epicsEnvSet "P" "HALF:BD:"
epicsEnvSet "R" "IO:"
epicsEnvSet("ETHER","192.168.1.18:50000")
cd "${TOP}"
## Register all support components
dbLoadDatabase "dbd/JDQ016.dbd"
JDQ016_registerRecordDeviceDriver pdbbase
epicsEnvSet "STREAM_PROTOCOL_PATH" "$(TOP)/db"
# Set up ASYN ports
#vxi11Configure("L0", "$(ETHER)", 0, 0.0, "inst0", 0)
drvAsynIPPortConfigure("L0", "$(ETHER)", 0, 0, 0)
## Load record instances
#dbLoadRecords("db/xxx.db","user=ioc")
dbLoadTemplate "db/bo.substitutions"
#dbLoadRecords("db/devJDQ016.db","P=$(P),R=$(R),PORT=L0,A=0")
cd "${TOP}/iocBoot/${IOC}"
iocInit
#var streamDebug 1
## Start any sequence programs
#seq sncxxx,"user=ioc"
[ioc@localhost iocJDQ016]$
[ioc@localhost db]$ cat bo.substitutions
# Example substitutions file
file "db/devJDQ016.db" {
pattern { P, R, PORT, A }
{ "HALF:", "BD:NetIO:", "L0", 0 }
}
file db/devJDQ016-bo.db {
pattern { P, R, Chan, Next, PORT, A }
{ "HALF:", "BD:NetIO:", 0, 1, "L0", 0 }
{ "HALF:", "BD:NetIO:", 1, 2, "L0", 0 }
{ "HALF:", "BD:NetIO:", 2, 3, "L0", 0 }
{ "HALF:", "BD:NetIO:", 3, 4, "L0", 0 }
{ "HALF:", "BD:NetIO:", 4, 5, "L0", 0 }
{ "HALF:", "BD:NetIO:", 5, 6, "L0", 0 }
{ "HALF:", "BD:NetIO:", 6, 7, "L0", 0 }
{ "HALF:", "BD:NetIO:", 7, 8, "L0", 0 }
{ "HALF:", "BD:NetIO:", 8, 9, "L0", 0 }
{ "HALF:", "BD:NetIO:", 9, A, "L0", 0 }
{ "HALF:", "BD:NetIO:", A, B, "L0", 0 }
{ "HALF:", "BD:NetIO:", B, C, "L0", 0 }
{ "HALF:", "BD:NetIO:", C, D, "L0", 0 }
{ "HALF:", "BD:NetIO:", D, E, "L0", 0 }
{ "HALF:", "BD:NetIO:", E, F, "L0", 0 }
{ "HALF:", "BD:NetIO:", F, 0, "L0", 0 }
}
[ioc@localhost db]$
[ioc@localhost db]$ cat devJDQ016.db
#
# Simple database and stream protocol file for basic SCPI (IEEE488.2) commands
#
#
# Short and long form of identification string
#
record(mbbiDirect, "$(P)$(R)Relay:mbbiD")
{
field(SCAN, "2 second")
field(DESC, "Relay open or close state")
field(DTYP, "stream")
field(INP, "@devJDQ016.proto readRelayState $(PORT)")
field(FLNK, "$(P)$(R)R1:bi")
}
record(mbbiDirect, "$(P)$(R)IN:mbbiD")
{
field(SCAN, "2 second")
field(DESC, "Input open or close state")
field(DTYP, "stream")
field(INP, "@devJDQ016.proto readInState $(PORT)")
field(FLNK, "$(P)$(R)IN0:bi")
}
record(bo, "$(P)$(R)Relay:SetAll")
{
field(DESC, "Control Relay open all")
field(DTYP, "stream")
field(OUT, "@devJDQ016.proto setAll $(PORT)")
field(ZNAM,"closeAll")
field(ONAM,"openAll")
field(FLNK, "$(P)$(R)Relay:mbbiD")
}
[ioc@localhost db]$
[ioc@localhost db]$ cat devJDQ016-bo.db
## Simple database and stream protocol file for basic SCPI (IEEE488.2) commands
#
#
# Short and long form of identification string
#
record(bi, "$(P)$(R)R$(Chan):bi")
{
field(DESC, "lost phase state")
field(INP, "$(P)$(R)Relay:mbbiD.B$(Chan) NPP")
field(ZNAM,"off")
field(ONAM,"on")
field(FLNK, "$(P)$(R)R$(Next):bi")
}
record(bi, "$(P)$(R)IN$(Chan):bi")
{
field(DESC, "lost phase state")
field(INP, "$(P)$(R)IN:mbbiD.B$(Chan) NPP")
field(ZNAM,"off")
field(ONAM,"on")
field(FLNK, "$(P)$(R)IN$(Next):bi")
}
record(bo, "$(P)$(R)R$(Chan):bo")
{
field(DESC, "Set Relay Chan$(Chan)")
field(DTYP, "stream")
field(ZNAM,"close")
field(ONAM,"open")
field(OUT, "@devJDQ016.proto setRelay$(Chan) $(PORT) $(A)")
field(FLNK, "$(P)$(R)Relay:mbbiD")
}
[ioc@localhost db]$
[ioc@localhost db]$ cat devJDQ016.proto
InTerminator = "";
OutTerminator = "";
setRelay0 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x01|\x00\x01\x00\x01}%2<sum>%2<sum>";
in "%s";
}
setRelay1 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x02|\x00\x02\x00\x02}%2<sum>%2<sum>";
in "%s";
}
setRelay2 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x04|\x00\x04\x00\x04}%2<sum>%2<sum>";
in "%s";
}
setRelay3 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x08|\x00\x08\x00\x08}%2<sum>%2<sum>";
in "%s";
}
setRelay4 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x10|\x00\x10\x00\x10}%2<sum>%2<sum>";
in "%s";
}
setRelay5 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x20|\x00\x20\x00\x20}%2<sum>%2<sum>";
in "%s";
}
setRelay6 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x40|\x00\x40\x00\x40}%2<sum>%2<sum>";
in "%s";
}
setRelay7 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x00\x80|\x00\x80\x00\x80}%2<sum>%2<sum>";
in "%s";
}
setRelay8 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x01\x00|\x01\x00\x01\x00}%2<sum>%2<sum>";
in "%s";
}
setRelay9 {
out "\xCC\xDD\xA1\x01%{\x00\x00\x02\x00|\x02\x00\x02\x00}%2<sum>%2<sum>";
in "%s";
}
setRelayA {
out "\xCC\xDD\xA1\x01%{\x00\x00\x04\x00|\x04\x00\x04\x00}%2<sum>%2<sum>";
in "%s";
}
setRelayB {
out "\xCC\xDD\xA1\x01%{\x00\x00\x08\x00|\x08\x00\x08\x00}%2<sum>%2<sum>";
in "%s";
}
setRelayC {
out "\xCC\xDD\xA1\x01%{\x00\x00\x10\x00|\x10\x00\x10\x00}%2<sum>%2<sum>";
in "%s";
}
setRelayD {
out "\xCC\xDD\xA1\x01%{\x00\x00\x20\x00|\x20\x00\x20\x00}%2<sum>%2<sum>";
in "%s";
}
setRelayE {
out "\xCC\xDD\xA1\x01%{\x00\x00\x40\x00|\x40\x00\x40\x00}%2<sum>%2<sum>";
in "%s";
}
setRelayF {
out "\xCC\xDD\xA1\x01%{\x00\x00\x80\x00|\x80\x00\x80\x00}%2<sum>%2<sum>";
in "%s";
}
set {
out "\xCC\xDD\xA1\x01\$1%2<sum>%2<sum>";
in "%s";
}
setAll {
out "\xCC\xDD\xA1\x01%{\x00\x00\xFF\xFF|\xFF\xFF\xFF\xFF}%2<sum>%2<sum>";
in "%s";
}
readRelayState {
wait 50;
out "\xCC\xDD\xB0\x01\x00\x00\x0D\xBE\x7C";
in "%*4c%2r[^\x0D]";
# in "\xAA\xBB\xB0\x01%2r\x0D%2<sum>%2<sum>";
}
readInState {
wait 50;
out "\xCC\xDD\xC0\x01\x00\x00\x0D\xCE\x9C";
# in "\xAA\xBB\xC0\x01%2x\x0D%2<sum>%2<sum>";
in "%*4c%2r[^\x0D]";
}
[ioc@localhost db]$