Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

3.1 Configure an IOC for TCP communication

Create an IOC that sends a string to a TCP device and stores its reply. The next lessons provide an echo simulator and verify the complete path.

Complete Chapter 2 first and activate your matching EPICS-env 1.5.0 tree.

Generate the application

From the directory containing tools/, generate the application:

bash tools/generate_ioc_structure.bash -l B46_182 -p jeonglee_Demo
cd jeonglee_Demo

Enter y for the unlisted training location. The executable is jeonglee_Demo; its startup directory is iocBoot/iocB46_182-jeonglee_Demo/. Keep the exact name jeonglee_Demo rather than substituting your own username so the directory paths and build files in Chapters 3 through 6 match as shown.

Select the device support

In configure/RELEASE, enable these three module definitions:

ASYN = $(MODULES)/asyn
CALC = $(MODULES)/calc
STREAM = $(MODULES)/StreamDevice

Keep the generated Base and default-module definitions. The application Makefile selects each module’s DBD and libraries when its variable is defined. StreamDevice in this distribution uses asyn and calc. Paths must not contain trailing whitespace.

Create the protocol and records

  1. Save this protocol as jeonglee_DemoApp/Db/training.proto:

    # Read the command reply into the record passed as argument 1.
    sendRawQuery {
        ExtraInput = Ignore;
        out "%s";
        in "%(\$1)40c";
    }
    

    out "%s" sends the stringout record’s value. in "%(\$1)40c" stores up to 40 input characters in the record field named by argument 1. The asyn end-of-string settings delimit each reply.

  2. Save these records as jeonglee_DemoApp/Db/training.db:

    record(stringout, "$(P)$(R)Cmd") {
        field(DESC, "Raw query")
        field(DTYP, "stream")
        field(OUT, "@training.proto sendRawQuery($(P)$(R)Cmd-RB.VAL) $(PORT)")
    }
    
    record(stringin, "$(P)$(R)Cmd-RB") {
        field(DESC, "Raw query readback")
        field(DTYP, "Soft Channel")
    }
    

    Writing Cmd runs the protocol. Its reply goes to Cmd-RB.VAL. P, R, and PORT are supplied when the startup loads the database.

  3. From the application’s top-level directory, build:

    make
    

    The generated Db/Makefile installs the database and protocol in db/.

Configure the startup

In iocBoot/iocB46_182-jeonglee_Demo/, save this as st.cmd:

#!../../bin/linux-x86_64/jeonglee_Demo
on error break
< envPaths

epicsEnvSet("DB_TOP", "$(TOP)/db")
epicsEnvSet("STREAM_PROTOCOL_PATH", "$(DB_TOP)")
epicsEnvSet("IOC", "iocB46_182-jeonglee_Demo")
dbLoadDatabase("$(TOP)/dbd/jeonglee_Demo.dbd")
jeonglee_Demo_registerRecordDeviceDriver(pdbbase)

drvAsynIPPortConfigure("LocalTCPServer", "127.0.0.1:9399", 0, 0, 0)
asynOctetSetInputEos("LocalTCPServer", 0, "\n")
asynOctetSetOutputEos("LocalTCPServer", 0, "\n")
dbLoadRecords("$(DB_TOP)/training.db", "P=jeonglee:,R=myoffice:,PORT=LocalTCPServer")
iocInit()
dbl

The application DBD and registration function provide record and device support. Configure the TCP port and load the records before iocInit(). Keep the exact macro values P=jeonglee:,R=myoffice: rather than substituting your own username so the jeonglee:myoffice: client commands in Chapters 3 and 4 match as shown.

Verification

From the application root, check the installed files and libraries:

ls db/training.db db/training.proto dbd/jeonglee_Demo.dbd
ldd bin/linux-x86_64/jeonglee_Demo

The library list must include libasyn.so, libcalc.so, and libstream.so, with no not found entries.

Continue with Run a TCP echo simulator, then Test IOC communication with the simulator.