• EPICS -- asynRecord记录使用示例


    这个示例演示了如何使用asynRecord记录

    1、硬件准备工作

    在这里准备了一个型号为NPort 5650-8-DT的Moxa串口服务器,用于一根交叉DB9双母头线缆连接设备上端口2和端口3,使之可以相互通信。

    串口服务器配置如下

    • IP地址:192.168.3.50
    • 端口2对应的本地TCP端口号:4002
    • 端口3对应的本地TCP端口号:4003

    2、安装以下测试EPICS asynRecord的IOC应用程序

    a) 按如下步骤,先建立这个IOC程序的程序框架:

    1. [blctrl@main-machine exer40]$ makeBaseApp.pl -t ioc asynRecordTest
    2. [blctrl@main-machine exer40]$ makeBaseApp.pl -i -t ioc asynRecordTest
    3. Using target architecture linux-x86_64 (only one available)
    4. The following applications are available:
    5. asynRecordTest
    6. What application should the IOC(s) boot?
    7. The default uses the IOC's name, even if not listed above.
    8. Application name?
    9. [blctrl@main-machine exer40]$ ls
    10. asynRecordTestApp configure iocBoot Makefile

    b) 编辑configure/RELEASE文件,添加指向asyn以及ipac模块的环境变量ASYN和IPAC:

    1. SUPPORT=/usr/local/EPICS/synApps/support
    2. IPAC=$(SUPPORT)/ipac
    3. ASYN=$(SUPPORT)/asyn

    c) 编辑asynRecordTestApp/Db/Makefile文件,添加如下一行用于指向asynRecord.db文件

    DB += $(ASYN)/db/asynRecord.db

    d) 编辑asynRecordTestApp/src/Makefile文件,添加以下行,使得这个IOC程序能够找到asyn的动态链接库

    1. # Include dbd files from all support applications:
    2. asynRecordTest_DBD += asyn.dbd
    3. asynRecordTest_DBD += drvAsynSerialPort.dbd
    4. asynRecordTest_DBD += drvAsynIPPort.dbd
    5. #
    6. # Add all the support libraries needed by this IOC
    7. asynRecordTest_LIBS += asyn

    e) 返回这个IOC程序的顶层目录,执行make命令进行编译。

    f) 进入IOC启动目录,编辑st.cmd启动文件:

    1. [blctrl@main-machine exer40]$ cd iocBoot/iocasynRecordTest/
    2. [blctrl@main-machine iocasynRecordTest]$ pwd
    3. /home/blctrl/exer/exer40/iocBoot/iocasynRecordTest
    4. [blctrl@main-machine iocasynRecordTest]$ cat st.cmd
    5. #!../../bin/linux-x86_64/asynRecordTest
    6. #- You may have to change asynRecordTest to something else
    7. #- everywhere it appears in this file
    8. < envPaths
    9. cd "${TOP}"
    10. ## Register all support components
    11. dbLoadDatabase "dbd/asynRecordTest.dbd"
    12. asynRecordTest_registerRecordDeviceDriver pdbbase
    13. drvAsynIPPortConfigure("IP1","192.168.3.50:4002",0,0,1)
    14. drvAsynIPPortConfigure("IP2","192.168.3.50:4003",0,0,1)
    15. ## Load 2 record instances
    16. dbLoadRecords("db/asynRecord.db","P=Test:,R=IPPORT1,PORT=IP1,ADDR=0,IMAX=0,OMAX=0")
    17. dbLoadRecords("db/asynRecord.db","P=Test:,R=IPPORT2,PORT=IP2,ADDR=0,IMAX=0,OMAX=0")
    18. cd "${TOP}/iocBoot/${IOC}"
    19. iocInit

    g) 启动这个IOC程序,并且查看启动后装置的记录实例:

    1. [blctrl@main-machine iocasynRecordTest]$ ../../bin/linux-x86_64/asynRecordTest st.cmd
    2. #!../../bin/linux-x86_64/asynRecordTest
    3. < envPaths
    4. epicsEnvSet("IOC","iocasynRecordTest")
    5. epicsEnvSet("TOP","/home/blctrl/exer/exer40")
    6. epicsEnvSet("SUPPORT","/usr/local/EPICS/synApps/support")
    7. epicsEnvSet("IPAC","/usr/local/EPICS/synApps/support/ipac")
    8. epicsEnvSet("ASYN","/usr/local/EPICS/synApps/support/asyn")
    9. epicsEnvSet("EPICS_BASE","/usr/local/EPICS/base")
    10. cd "/home/blctrl/exer/exer40"
    11. ## Register all support components
    12. dbLoadDatabase "dbd/asynRecordTest.dbd"
    13. asynRecordTest_registerRecordDeviceDriver pdbbase
    14. drvAsynIPPortConfigure("IP1","192.168.3.50:4002",0,0,1)
    15. drvAsynIPPortConfigure("IP2","192.168.3.50:4003",0,0,1)
    16. ## Load record instances
    17. #dbLoadRecords("db/asynRecord.db","P=Test:,R=SPORT")
    18. dbLoadRecords("db/asynRecord.db","P=Test:,R=IPPORT1,PORT=IP1,ADDR=0,IMAX=0,OMAX=0")
    19. dbLoadRecords("db/asynRecord.db","P=Test:,R=IPPORT2,PORT=IP2,ADDR=0,IMAX=0,OMAX=0")
    20. cd "/home/blctrl/exer/exer40/iocBoot/iocasynRecordTest"
    21. iocInit
    22. Starting iocInit
    23. ############################################################################
    24. ## EPICS R7.0.3.1
    25. ## EPICS Base built Sep 8 2022
    26. ############################################################################
    27. iocRun: All initialization complete
    28. ## Start any sequence programs
    29. #seq sncxxx,"user=blctrl"
    30. epics> dbl
    31. Test:IPPORT1
    32. Test:IPPORT2
    33. epics>

    3、对asynRecord记录实例进行测试

    a) 如下所述用medm分别连接上述两个asynRecord记录:

    1. [blctrl@main-machine adls]$ medm -x -macro "P=Test:,R=IPPORT1,PORT=IP1" asynRecord.adl &
    2. [blctrl@main-machine adls]$ medm -x -macro "P=Test:,R=IPPORT2,PORT=IP2" asynRecord.adl &

    连接后成功后,显示了两个窗口 

     b) 以下是一个Python脚本,演示了asyn记录的用法。它用ASCII和二进制格式传输数据。

    这是Python程序,它演示了EPICS asyn记录的用法。这个程序使用2个asyn记录。对应这两个记录的端口连接了所提供的串口服务器的两个TCP端口。

    • 记录1用ASCII发送消息"Hello EPICS"给记录2。
    • 记录2用二进制向记录1发送数组[0,2,3,...,29]消息。
    1. [blctrl@main-machine exer40]$ cat write_read.py
    2. import epics
    3. import time
    4. rec1="Test:IPPORT1"
    5. rec2="Test:IPPORT2"
    6. # 记录1 ASCII输出,二进制输入
    7. t=epics.caput(rec1+'.OFMT', 'ASCII')
    8. t=epics.caput(rec1+'.OEOS','\r')
    9. t=epics.caput(rec1+'.IFMT', 'Binary')
    10. t=epics.caput(rec1+'.IEOS', '')
    11. # 清除记录1的输入垃圾
    12. junk=epics.caget(rec1+'.BINP')
    13. # 记录2 ASCII输入,二进制输出
    14. t=epics.caput(rec2+'.OFMT', 'Binary')
    15. t=epics.caput(rec2+'.OEOS', '')
    16. t=epics.caput(rec2+'.IFMT','ASCII')
    17. t=epics.caput(rec2+'.IEOS','\r')
    18. # 记录2,处于读取模式
    19. t=epics.caput(rec2+'.TMOD', 'Read')
    20. # 清除读取值
    21. junk=epics.caget(rec2+'.AINP')
    22. message="Hello EPICS"
    23. t=epics.caput(rec1+".TMOD", "Write")
    24. epics.caput(rec1+".AOUT", message)
    25. print("Record1 send Record2:", message)
    26. time.sleep(0.1)
    27. epics.caput(rec2+".PROC",1)
    28. recv=epics.caget(rec2+".AINP")
    29. print("Record2 received:",recv)
    30. # 预计30个字节
    31. size=30
    32. # 记录1处于读取模式
    33. t=epics.caput(rec1+".TMOD", "Read")
    34. t=epics.caput(rec1+".NRRD", size)
    35. junk=epics.caget(rec1+".BINP")
    36. # 记录2处于写模式
    37. send_data=[]
    38. for i in range(size):
    39. send_data.append(i)
    40. print("Record2 sends Record1:", send_data)
    41. t=epics.caput(rec2+".TMOD","Write")
    42. t=epics.caput(rec2+".NOWT",size)
    43. t=epics.caput(rec2+".BOUT",send_data)
    44. time.sleep(0.1)
    45. t=epics.caput(rec1+".PROC",1)
    46. time.sleep(0.1)
    47. arr=epics.caget(rec1+".BINP")
    48. print("Record1 received",arr)

    运行以上python脚本,测试结果:

    1. [blctrl@main-machine exer40]$ python3 write_read.py
    2. Record1 send Record2: Hello EPICS
    3. Record2 received: Hello EPICS
    4. Record2 sends Record1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
    5. Record1 received [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    6. 24 25 26 27 28 29]

  • 相关阅读:
    企业为什么要用Linux?为什么要学Linux?
    鲁棒局部均值分解 (RLMD)附Matlab代码
    第8关:使用递归
    Python&C++相互混合调用编程全面实战-31完成扩展库中打开ffmpeg解码器
    如何在 Linux 中删除超大的(100-200GB)文件
    创建对象在Heap堆区中如何分配内存
    vue3 知识点(二)
    为什么百度百科有词条,而维基百科无法创建?
    【摘星星计划】day16-dayxx:react基础
    python中import和from详解区别
  • 原文地址:https://blog.csdn.net/yuyuyuliang00/article/details/127970357