Introduction
The open source PLC emulator is available as the copyleft GitHub repository
mfs-plc-sim for everyone to clone, build and run. Still building the emulator might get challenging. The intention of this article is to help with the process. Unfortunately due to redistribution restrictions of SAP Java Connector license terms, I must not provide self contained, ready to run, single jar file.
Prerequisites
The emulator relies on SAP Java Connector and Apache log4j2 libraries. They need to be installed before running the PLC emulator:
Downloading the PLC emulator
Download the following files from the the GitHub repository
mfs-plc-sim:
For convenience put all the files in a single directory.
Setting it all up
Logging configuration
Refer to
Log4j Configuration for the detailed documentation on how to setup the logging options. Provided log4j2.xml sets
debug level logging with a rich patter and directs the messages to the console. It can be left as it is.
JCo configuration
Java Connector configuration is composed of two files:
- SID.jcoDestination - the file defines your SAP system destination and how to log to it
- PROGID.jcoServer - the file defines the RFC destination to be used with EMW-MFS
Rename and modify the content of the files. For instance, let's say we are connecting to a single SAP sandbox installation running on 192.168.1.1 address, system number 01, client 100, system id DEV - so we need
DEV.jcoDestination file:
jco.client.user=JDOE
jco.client.passwd=password
jco.client.lang=EN
jco.client.client=100
jco.client.ashost=192.168.1.1
jco.client.sysnr=01
jco.client.r3name=DEV
jco.destination.pool_capacity=3
Next, let's say that our RFC destination is defined with MFSPLC program id. So we need
MFSPLC.jcoServer file:
jco.server.gwhost=192.168.1.1
jco.server.gwserv=3301
jco.server.progid=MFSPLC
jco.server.connection_count=1
jco.server.repository_destination=DEV
Refer to
JCo documentation on the details of the configuration.
The PLC emulator configuration
The emulator is customized with Java properties file. A sample
MFS.properties file is provided. The most important entries are:
telegramStructure=ZMFS_TELESHORT
handshakeRequest=R.
handshakeConfirmation=A.
switchSenderReceiver=false
Additionally telegram styling can be customized:
Style.LIFE-R.=255,0,0,B
Style.LIFE-A.=255,0,0,I
The value of each key is interpreted as:
- R,G,B font color specification
- BIUS - characters specifying font options:
- B - bold
- I - italic
- U - underlined
- S - strikethrough
For instance
255,255,0,BI yields yellow, bold, italic styling.
Running the emulator
Run the RFC-TCP/IP bridge with the command:
java -Dlog4j.configurationFile=log4j2.xml -cp sapjco3.jar:log4j-api-2.19.0.jar:log4j-core-2.19.0.jar:mfsplc.jar pl.sapusers.mfsplc.bridge.Bridge MFSPLC MFS.properties
Run the emulator application with the command:
java -Dlog4j.configurationFile=log4j2.xml -cp sapjco3.jar:log4j-api-2.19.0.jar:log4j-core-2.19.0.jar:mfsplc.jar pl.sapusers.mfsplc.sim.Sim DEV MFS.properties
The commands may need to be modified if your jar files do not reside in the working directory.