Development Environment for IOC Software

IOC Application
Development / Debugging
EPICS Seminar @Hefei
2004/03/02
J.Odagiri
Before Getting Started…

如果有付公不明白的地方、請別客気。
Contents

This lecture includes how to:





Build EPICS base
Create a directory for application
development
Develop applications
Start-up applications
Debug applications
OSI Libraries
EPICS iocCore
OSI Libraries
VxWorks, Linux, …
IOC on Linux


Now that Operating System
Independent (OSI) libraries provided,
an IOC program can run on many
different operating systems.
Linux as a platform for IOCs



Free
Self development
Quick start-up
How to build base (1)





Create /usr/local/epics to put “base”
Get “base” in the form of a tar file from
host:
Un-tar the file
Execute a command to get your host
architecture type:
base/tools/startup/EpicsHostArch
Setenv EPICS_HOST_ARCH to the value
How to build base (2)


Type “make”
Get a cup of coffee to break…
How to create app. dir. (1)




Create /usr/local/epics/epicsApp as the top
directory for application development
Move to epicsApp
Execute a perl script:
base/bin/linux-x86/makeBaseApp.pl
Try the spcript without arguments to print the
usage first
How to create app. dir. (2)

Need to type it twice with different sets of
arguments
makeBaseApp.pl –t example example
makeBaseApp.pl –i –t example example



Check if EPICS_HOST_ARCH is properly set
Type “make”
No time to enjoy coffee since it gets done in a
few seconds
Getting familiar with epicsApp
bin/linux-x86/example
configure
db/myApp.db
dbd/example.dbd
exampleApp/Db/myApp.db
/src/exampleInclude.dbd
iocBoot/iocexample/st.cmd
iocsh and registry (1)

The executable, “example”, comprises of the
“main” in exampleApp/src/exampleMain.c
and lots of objects from “base”
int main(int argc, char argv[ ])
{
if (argc >= 2) {
iocsh(argv[1]);
epicsThreadSleep(.2);
}
iocsh( NULL );
return ( 0 );
}
iocsh and registry (2)

The command (function) to be typed in
must be registered into a registry in
advance by using iocshRegister( )
registrar


Make a function get called in the initialization
process of the IOC core program during its
start-up
Used to:




Register record/device/driver support
Invoke user-defined initialization routines of
subroutine records
Register new commands into the registry of iocsh
…
How to start-up IOC (1)

Have a look at:
iocBoot/iocexample/st.cmd
#!../../bin/linux-x86/example
< envPaths
cd ${TOP}
dbLoadDtatabase(“dbd/example.dbd”)
dbLoadRecords(“db/dbExample1.db”,…)
…
iocInit
How to start-up IOC (2)





Append base/lib/linux-x86 to the current value
of LD_LIBRARY_PATH
Move to:
iocBoot/iocexample/
To start-up IOC, just type:
./st.cmd
You’ll see a prompt like:
epics>
Now, you are talking to “iocsh”
Commands for debugging
Try first:
epics> help
 Then, try some of the other commands:
epics> thread
epics> dbl
epics> dbpr “record_name”
epics> …

How to create .db files






Move to:
exampleApp/Db/
Create your own application ( myApp.db )
Edit Makefile in the directory:
DB += myApp.db
Check if EPICS_HOST_ARCH is appropriately
set
Type “make”
Edit: /iocBoot/iocexample/st.cmd
How to build sources





Put your source codes under
exampleApp/src/
Edit Makefile in src
example_SRCS += hogehoge.c
Check if EPICS_HOST_ARCH is appropriately
set
Type “make”
Check what you’ve got
Adding new record support (1)



Place the sources of a record support module
under
exampleApp/src
The sources of a record support module are
hogehogeRecord.dbd and hogehogeRecord.c
hogehogeRecord.h will be created in the
course of “make” by adding a line to Makefile
DBDINC += hogehogeRecord
Adding new record support (2)
Need to add
example_SRCS += hogehogeRecord.c
to include the module to the executable
 Need to modify exampleInclude.dbd to
include the hogehogeRecord.dbd
 exampleInclude.dbd will be used during
the make in order to create
dbd/example.dbd referred by st.cmd

Adding new device support
Place the sources of a device support under
exampleApp/src
 Need to modify Makefile to include your device
support module into the executive
example_SRCS += devMyDevice.c
 Need to modify exampleInclude.dbd to include a
line something like:
device(ai,INST_IO,devMyDevice,“My Dev”)

Adding new driver Support



Place the sources of a driver support under
exampleApp/src
Need to modify the Makefile to include your
driver support module into the executive
example_SRCS += drvMyDevice.c
Need to modify exampleInclude.dbd to
include a line something like:
driver(drvMyDevice)
Exercise

We are going to talk to a PLC, FA-M3,
made by Yokogawa Electric Corporation


I do NOT get paid even a penny by the
company
Need to install a set of device/driver
support modules

I can provide the software for nothing
Architecture of software
Record Support
FA-M3
MELSEC
CVM1
…
Asynchronous I/O Library
Network I/O Driver
Devices supported
Type
Make
Protocol
User
FA-M3 PLC
Yokogawa
TCP / UDP
J-PARC
MELSEC-Q PLC
Mitsubishi
TCP / UDP
RIKEN
CVM1 / CS1 PLC
Omron
TCP / UDP
RIKEN
EMB-LAN100
Custom
UDP
J-PARC
N-DIM
Custom
TCP / UDP
RIKEN
BPMC
Custom
TCP
J-PARC
Related source files
arrayoutRecord.dbd
arrayoutRecord.c
devYewPlc.c
yew/devAiYewPlc.c
/devAoYewPlc.c
…
devNetDev.c (.h)
drvNetMpf.c (.h)
netdev.dbd
fam3.db
Installing / building sources



Get netdev.tar from:
host
Install relevant sources into:
exampleApp/src
/Db
Edit:
src/Makefile
/exampleInclude


(Copy some relevant lines from netdev.dbd)
Type “make”
Creating database records

Modify fam3.db so that:




DTYP field has a value of “Yew Plc”
INP / OUT field has a value:
“@192.168.210.18#D40xx”
(where xx stands for the ID on your PC)
SCAN field has a value of “Passive” in both records
Create a forward link from the longout toward the
longin to read back the data written
Testing database




Type “make” to install the database
Edit st.cmd to load the database, and then
start-up IOC
Try some commands to see what’s going on
Put any value into the longout record in order
to write the value into the PLC’s memory
epics> dbpf “output_record_name”, 2004

Print fields of the longin record for read-back
epics> dbpr “input_record_name”
Debug commands of the driver
There are some driver-specific commands
for debugging
 Try:
epics> peerShowAll
epics> peerShow 0
epics> showMsg 0
 Check how these commands are
implemented in the source
