Technical Articles
How to setup and run PLC emulator for SAP EWM MFS
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:
- mfsplc.jar – the main jar file of the emulator
- log4j2.xml – the logging configuration file
- MFS.properties – the emulator configuration file
- sampleSID.jcoDestination – the sample JCo destination definition file
- samplePROGID.jcoServer – the sample JCo server definition file
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.
Hi Dominik, great blog and currently really relevant for our project!
I have some additional questions though:
- How easily can we switch between different telegram types?
- Do we need a seperate PLC in SAP EWM dedicated to the PLC sim? Or can we link all of our/multiple PLC's in SAP EWM with it?
Thank you in advance for your feedback.
Keep up the good work! 🙂
Kr,
Malick
Hello Malick Thienpont
As indicated in the Open source PLC emulator for SAP EWM MFS in action blog, I have used /SCWM/MFS_* BC sets to setup demo processes during the emulator development. Therefore I have used the telegram types as defined in the /SCWM/MFS_TELEGRAM_TYPES BC set:
Actually the only hardcoded telegram type is LIFE that I use to filter out life telegrams from the communication log.
In terms of telegram structures each instance of the Sim class is using a single telegram structure, that is defined in the properties file with the property telegramStructure.
It is on my to-do list to implement configurable telegram types and allow various telegram structures. See the issues list of the PLC sim project. Feel free to add your own feature requests.
You don't really need to customize a dedicated PLC for PLC sim, you can use the existing ones provided the fit the current limitations. The goal of the emulator is to connect with the existing PLC setups. Let me know please how the emulator fits your project.
Hello Dominik,
sorry for bothering you,but when I try to start bridge or sim I always get the error:
Error: Main class pl.sapusers.mfsplc.sim.sim or pl.sapusers.mfsplc.bridge.bridge couldn't be found or loaded.
Any hints for me to get rid of that issue?
Thanks in advance
Patrick
Hello Patrick Rogge
I enjoy being bothered - it shows the project is getting friction.
You have misspelled the class names - it should be (uppercase in the class name)
and
pl.sapusers.mfsplc.sim is a package name whereas Sim is the class name in the package.
As per Java Naming Conventions packages are lower case, whereas classes are CamelCase starting with upper case.
Hello Dominik Tylczynski ,
that was a cut and paste error, I was using the upper cases. Here is the complete command and output, copied from the command line:
C:\PLC-SIM\mfs-plc-sim-master>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
Fehler: Hauptklasse pl.sapusers.mfsplc.sim.Sim konnte nicht gefunden oder geladen werden
Regards
Patrick Rogge
Hello Patrick Rogge
Try replacing ":" with ";" as you are working on Windows, while I'm on Linux:
Let me know if that works, please.
Hello Dominik Tylczynski
thank you, it seems to take the first gate. I now receive a different error:
C:\PLC-SIM\mfs-plc-sim-master>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
Exception in thread "main" java.lang.UnsupportedClassVersionError: pl/sapusers/mfsplc/sim/Sim has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
I checked but I guess I do have already the latest JRE Version:
java version "1.8.0_361"
Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)
What else has to be updated?
Best regards and thanks in advance
Patrick Rogge
Hello Patrick Rogge
That is the "beauty" of jars...
As per https://stackoverflow.com/questions/47457105/class-has-been-compiled-by-a-more-recent-version-of-the-java-environment that's how class file version map to Java versions:
Your Java version is 8 (class file version 52), whereas the mfsplc.jar file is compiled with Java 11 (class file version 55).
I can see the following options now:
Let me know, which works for you.
Hello Patrick Rogge
I've downgraded the project to Java 8. The new jar with class version 52 is available on Github.
Cheers
Dominik Tylczynski
Hello Dominik Tylczynski,
thanks for downgrading. After fixing an issue with 32 and 64 Bit SAP Connector it seems to run.
I noticed that every instance of the sim takes about 30-40% of the CPU. So when I started two SIMs based on the BC Set example, our server was running nearby 80% CPU only for the Sims. Did anybody else noticed this issue?
Regards
Patrick
Hello Patrick Rogge
Thank you for pointing the performance issue. I'm running the emulator on my desktop Linux machine, which is quite old already. I've not noticed any performance problems. Nevertheless I'll try to find the culprit.
I'm glad you are running the emulator. Please report any issues or feature requests in the GitHub repository of the project https://github.com/dominik-tylczynski/mfs-plc-sim/issues
You are running Windows, right?
Best regards
Dominik Tylczynski
Hi Dominik Tylczynski
yes, we are running it on Windows. I opened an issue as you requested.
Regards
Patrick
Hello Patrick Rogge
Thank you. Feel free to add any feature requests as issues too.
D.
Hello Patrick Rogge
I have redesigned concurrency of the emulator and reduced greatly CPU usage. The new jar is provided in the GitHub repository - mfsplc.jar
Let me know how it works for you.
Regards
Dominik Tylczynski
Hi Dominik,
Is it possible for you to make some demo video on your youtube channel for us? As I do not have any MFS implementation experience. Also never setup emulator for MFS.
Regards,
Ganesh
Hi Ganesh Navale
I'm working on that. However I'm an old cat with more inclination to text than video.
Hi Dominik,
I had found below link and they have provided single executable to run PLC emulator.
Can you provide similar executable?
Link:- http://www.venetica.net/Sites/PLC_Emulator/PLC_Emulator.html
Also I'm getting below error while connecting to emulator.
Connection refused by server (ICM_HTTP_CONNECTION_REFUSED)
Message no. SCLNT_HTTP411
I also referred to Note 2343224. Did you faced similar error?
Regards?
Ganesh N
Hello Ganesh Navale
Unfortunately I cannot provide a self contained executables as Venetica did. The first reason is that the emulator is written in Java. So it needs to be run with Java virtual machine. I have chosen Java for several reasons: ease of implementation, platform independence, personal preference.
Second, the emulator consists of two components, two classes Bridge and Sim. The Bridge class implements "SAP Communication Layer" for a PLC - transaction /SCWM/MFS_PLC:
This way you don't need to communicate with ABAP Push Channel and TCP/IP directly. Instead RFC communication can be used.
The Bridge class uses SAP Java Connector library. Its license terms forbit redistribution. So I must not include it in the jar file.
Regarding, the "Connection refused by server (ICM_HTTP_CONNECTION_REFUSED)" error message. I think that your SAP application server is not able to establish direct TCP/IP connection with ABAP Push Channel to the simulator. The reasons might be numerous e.g. network settings or firewall rules.
My test systems sits in the cloud behind a firewall. I was not able to set up the network for direct TCP/IP connection to the simulator. Therefore I'm using the RFC-TCP/IP bridge (the Bridge class) and "SAP Communication Layer". I find it much easier to deploy.
Hi,
After switching to SAP Communication Layer getting below error.
Data transfer to communication layer of PLC CONSYS1 failed (Function module "RFC_EXECUTE_COMMAND" not found.)
Message no. /SCWM/MFS072
Regards,
Ganesh
Hello Ganesh Navale
The emulator consists of two main classes Bridge and Sim. The Bridge class implements an RFC server and provides RFC_EXECUTE_COMMAND. The class translates RFC calls to TCP/IP telegrams and communicates with TCP/IP server. The TCP/IP server is implemented with the Sim class.
Therefore you first need to run the Bridge class and keep it running while using the Sim class. Make sure that the RFC server (the Bridge class) connects correctly to your SAP system. You can verify that in the SMGW transaction, menu Goto -> Logged on Clients.
Hi Dominik,
thanks for your great work. I managed to connect the Bridge with our SAP System as I can see in transaction SMGW. But when I want to start the communication channel I am receiving the following error:
error communication channel
And I can see in the cmd that SAP tries to communicate with the Bridge Class:
Do you maybe have any idea where I made a mistake in the configuration?
Best regards
Nadim
Hello Nadim Chaouad
Thank you for your interest in the emulator!
Let's check/clarify the following points:
The DEBUG message from your screenshot is ok, it is not an error. It just indicates that SAP EWM called RFC_EXECUTE_COMMAND provided by the Bridge class.
Let's keep the conversation going till we get it right. I'm here to help you!
Cheers
Dominik Tylczynski
Hi Dominik,
thanks for your help! Alright, let's check:
1.Telegram structure maintained in the properties:
compared to those, i defined in Customizing:
and it is defined in se11:
2 - 5: Yes, I started also the Sim class and the TCP/IP Server. Screenshot SMGW:
I think I did not receive any exceptions while running either Bridge or Sim class
Bridge
Sim
Again, thanks for your help! BR
Nadim
Hi Nadim Chaouad
So far, so good - from what I see both Bridge and Sim start correctly and they register in SMGW.
Now let's check your communication channels:
If indeed you have . <do> in Fill Character, you should put in the properties file:
The simulator will get those values in a telegram as SAP will fill any blanks with . <dot>
After that try to start the communication channel with /SCWM/MON. If everything works fine, the background of the port field in Sim will turn green. You should also see messages in the Bridge log about RFC_EXECUTE_COMMAND and channel starting. Please share those messages if still having problems.
If still in doubts, please share the screenshots of point 1 and 2.
We could also set up a call, so you can share the screen and I can help you to get it running.
Best regards
Dominik Tylczynski
Hi Dominik,
I am using Windows 11 to run the PLC emulator, but I keep getting the error message for Bridge
and for SIM
System Details:
Installed JAVA 8 update 361 32 Bit
Downloaded MFS-PLC Emulator from GitHub into a folder "MFS_PLC" as in the screenshot
Downloaded Log4J2 (apache-log4j-2.20.0-bin) into a sub folder
Downloaded SAPJCO into a sub folder and kept both folders with in the emulator Folder "MFS_PLC" as in the screenshot.
Added PATH and CLASSPATH under Environment Variables for both Log4J2 and SAPJCO
ERROR - Command Prompt Screen
FOLDER - Emulator Files are available
PATH - System Environment Variable
CLASSPATH - System Environment Variable
I am new to MFS and not expert in JAVA related configurations, please help me to configure the emulator.
Thank you,
RR
Hello R R
I have not played with CLASSPATH variable because as per Oracle documentation on PATH and CLASSPATH the preferred way is to use -cp switch.
Also notice, that setting the CLASSPATH variable overwrites it is default "." (dot for the current directory). As far as I can understand your setup, you have not provided "." in the CLASSPATH.
What works for me is:
and
Jar files in -cp switch should be separated by ; (semicolon) on Windows and by : (colon) on Linux.
I would have provided a self-contained, ready to run jar application with all the dependencies included, if SAP had allowed me to include JCo in the jar - see Open source PLC emulator: why ready to run application cannot be provided?
Thank you for your interest in the emulator. Make sure to watch the Github repository as the project is actively being developed.