OPC Device Support

Author: Kuner 

Overview and Features

The OPC device driver provides direct access for EPICS records to items located on an OPC server.


• Data conversion for all integer and float data types - array support is not yet implemented.

• Out-records become bidirectional In/Out-records. The EPICS Out-record will be updated if the OPC item is written by another device (e.g. PLC).

• Support for the following record types:

  - ai, ao
  - bi, bo 
  - mbbi, mbbo
  - mbbiDirect, mbboDirect
  - longin, longout
  - stringin, stringout
 (- waveform record is in the works)

The data conversion capabilities of the binary records (bi, bo, mbbi, mbbo, mbbiDirect, mbboDirect) are supported with two dtypes "opc" and "opcRaw" as described in the Record Reference Manual for the "Soft Channel" and "Raw Soft Channel" types.

• Timestamp is generated by OPC server or EPICS (source is determined by the record's TSE field).

• OPC quality is mapped to record's STAT/SEVR fields.

• Available console commands, to be used in st.cmd or for debugging purposes:

  - Set name of the OPC server - only one server can be connected to a single
  - Set Group name and its poll time - only one Group is supported.
  - Map Item names from (long) names used by the OPC server to EPICS record
    names (29 characters) in the input link.
  - Browse server.
  - Set level for debug output.

    Support for connections to multiple servers and several groups per server
    is being worked on.

• Error logging using the iocLogClient.

Directory structure

../opcApp/srciocShell and device support
../opcApp/Dba test and demonstration: opcTest.db and opcTest.adl
../opcApp/testOpcAppa console client for opc for opc access without epics

Compile and Install

Prerequisites :

Bring up your working environment:

• Set environment variables:

  set PATH=%PATH%;\Softing\OPCToolbox\bin\vc6

• Adapt src/Makefile:

  USR_INCLUDES = -I "\Softing\OPCToolbox\include" \
                 -I ""\Softing\OPCToolbox\opc"
  USR_LDFLAGS += /libpath:"\Softing\OPCToolbox\lib\vc6"

Microsoft Visual Studio may be used. Be sure to set all paths for includes and libraries according to your local installation of EPICS base and the Softing Toolbox.

You need to run make before you can use MS Visual Studio. The make run creates the file iocShell_registerRecordDeviceDriver.cpp

• Known Problem:

First run of make causes error:

  iocShell_registerRecordDeviceDriver.obj : error LNK2001: unresolved
  external symbol ....

iocShell Console Commands

opcSetServer: Set the OPC server

Used from st.cmd to set the server to connect to.


  opcSetServer  hostName serverName


  * hostName:    where the server is hosted
  * serverName:  name of the server

opcSetGroup: Define a group for the OPC items

Used from st.cmd to define a group for the OPC items. According to the OPC "Data Access" specification it is mandatory to define at least one group.


  opcSetGroup  groupName n_scanRate


  * groupName:   find a reasonable or a fancy name for it	
  * n_scanRate:  update rate (in milliseconds) of the OPC items (> 0 ms)

opcBrowse: Browse items of the connected OPC server

Used from the command line for debugging purposes to see if the connection to the server works and which items are served.


  opcBrowse n


  * n: maximum depth in the item hierarchy of the server to be browsed.
       Its value depends on the hierarchical structure of the server. Try
       different values to see what's reasonable for your OPC server.

opcSetNames: Item name mapping

Used from st.cmd to set the file for name mapping.

The problem is that the record's INP or OUT fields have a limited length for the name of the OPC item. On the other hand, OPC servers can have huge name lengths for those items. So a map file may be defined to map the long OPC server names to short names suited for the record's link field.

The map file format is:

  # allowed are comments and lines like this with leading spaces:


  opcSetNames  fileName


  * fileName:  yes, you guess right, but don't forget the path to your file.

opcDbg: Set debug level

Used to control the output of debugging information. The default is 0 to be completely quiet. Try a higher number and be amazed.


  opcDbg  n_debugLevel


  * n_debugLevel: number > 0, 0 = quiet

opcIor: IO report

Create a report of all records that use OPC device support. Format:

epicsName, Record Type, Dtype, opcName, opcFullName

Set up an st.cmd for the ioc shell

This example shows how to set up an IOC

  # Make sure that the dbd contains the lines for "opc" and "opcRaw"
  # This is the softing demo server on the local host
  # The group with an update rate of 1 second
  # Name mapping is not required here - comment out to set the file name
  # opcSetNames("../names.txt")
  opcIor > opcReport.txt

Record related issues

Record scanning

• In-records

The device support accepts all but "Passive". Due to the update facilities of the OPC group it is not reasonable to define a scan rate faster than the update rate of the group. To get the same scan rate for the record set SCAN="I/O Intr". To allow a slower than the update rate (for whatever reason) the fixed scan rates are supported: SCAN=".1 second" to SCAN="10 second".

• Out-records

As mentioned before out-records are now bidirectional in/out-records. They will be updated to the new value if it is changed on the OPC server by any other way (e.g. the PLC or another OPC client).

For out-records the SCAN field is ignored by the device support and should be set to "Passive". Nevertheless, if the OPC server gets a new value for the OPC item the record will be processed to update the value, send monitors, check for limits, set severities and process forward links.

Writing to the hardware from two sides (EPICS and the hardware covered by the OPC server) at the same time can cause problems.

For values that are frequently written by the PLC a write by the EPICS record will be overwritten in the opc-server by the PLC before it is sent to the PLC from the opc-server. In this case a caput will not be recognized by the PLC!

This is a behaviour is due to the opc-server and PLC, no bug in the EPICS device support.

Also an EPICS write that follows immediately after a PLC write (very short time), may be discarded by the device support.

Device types and data conversion

There are two types available: DTYP="opc" for all records and the DTYP="opcRaw" for the binary records: bi, mbbo, mbbi, mbboDirect and mbbiDirect. The behaviour of the record is listed below and is according to the desccription of the raw data types in the Record Reference Manual.

For the analog records ai and ao the LINR field determines the data conversion.

aiopcno conversion: LINR="NO CONVERSION" (record default)
aoopcno conversion: LINR="NO CONVERSION" (record default)
biopcno conversion, VAL may be any value
biopcRawconversion: RVAL=0 -> VAL=0, RVAL>0 -> VAL=1
boopcconversion: VAL=0 -> RVAL=0, VAL>0 -> RVAL=1 send RVAL to the hardware
mbbiopcfor VAL=0..15 record is set to the according state. NOBT, SHFT ignored
mbbiopcRawif RVAL=xxVL record is set to state xxST. NOBT, SHFT processed
mbboopcRaw? further experimets will give new and exciting information,
mbbiDirectopc? what this records do! See next version.
longinopcno conversion
longoutopcno conversion
stringinopcno conversion
stringoutopcno conversion
waveformopcno conversion

The multibit records (mbbo, mbbi, mbboDirect and mbbiDirect) have the fields NOBT and SHFT to select a special part of the 16 bit data input. This is also supported by the device support.


It is possible to choose the timestamp source. Default is the EPICS timestamp, but if the field TSE="-2" the timestamp of the OPC item will be used.

Known Problems

iocLog and EPICS 3.14.2

Due to problems with the Windows Socket Library there are two patched files for the EPICS base to make it work:


This patch is neither neccessary if IOC-Logging is not used nor for versions newer than EPICS 3.14.2

Running many process variables in one iocShell

If there are more than ca. 1800 PVs running on a iocShell following occures:

  • the CPU load is near 100%
  • Error message: callback buffer overflow - means there are PVs lost.

It seams to be a problem of the Windows task priorities. We solved it to run our 6000 PVs in two iocShells on two PCs. This works fine.