Skip to Content
Technical Articles
Author's profile photo Dominik Tylczynski

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:

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.

Assigned Tags

      26 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Malick Thienpont
      Malick Thienpont

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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.

      Author's profile photo Patrick Rogge
      Patrick Rogge

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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)

       pl.sapusers.mfsplc.sim.Sim

      and

      pl.sapusers.mfsplc.bridge.Bridge

      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.

       

      Author's profile photo Patrick Rogge
      Patrick Rogge

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      Hello Patrick Rogge

      Try replacing ":" with ";" as you are working on Windows, while I'm on Linux:

      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

      Let me know if that works, please.

      Author's profile photo Patrick Rogge
      Patrick Rogge

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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:

      49 = Java 5
      50 = Java 6
      51 = Java 7
      52 = Java 8
      53 = Java 9
      54 = Java 10
      55 = Java 11
      56 = Java 12
      57 = Java 13
      58 = Java 14
      59 = Java 15
      60 = Java 16
      61 = Java 17
      62 = Java 18
      63 = Java 19

      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:

      1. You can clone the source java code of the project and compile it with your Java installation.
      2. You can upgrade your Java to 11 or higher - https://www.oracle.com/java/technologies/downloads/#jdk19-windows
      3. I can downgrade msfplc.jar to Java 8 (class file version 52) but it will take me a couple of days.

      Let me know, which works for you.

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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

      Author's profile photo Patrick Rogge
      Patrick Rogge

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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

      Author's profile photo Patrick Rogge
      Patrick Rogge

      Hi Dominik Tylczynski

      yes, we are running it on Windows. I opened an issue as you requested.

       

      Regards

      Patrick

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      Hello Patrick Rogge

      Thank you. Feel free to add any feature requests as issues too.

      D.

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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

      Author's profile photo Ganesh Navale
      Ganesh Navale

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      Hi Ganesh Navale

      I'm working on that. However I'm an old cat with more inclination to text than video.

      Author's profile photo Ganesh Navale
      Ganesh Navale

      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

       

       

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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.

      Author's profile photo Ganesh Navale
      Ganesh Navale

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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.

      Author's profile photo Nadim Chaouad
      Nadim Chaouad

      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%20communication%20channel

      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

       

       

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      Hello Nadim Chaouad

      Thank you for your interest in the emulator!

      Let's check/clarify the following points:

      1. Check if the telegramStructure=<telegram value> in the properties file corresponds to the telegram structures maintained in SPRO: SCM Extended Warehouse Management -> Extended Warehouse Management -> Material Flow System (MFS) -> Telegram Processing -> Define Telegram Structure. Remember that for now, the emulator supports only one telegram structure for all telegram types. The structure needs to be defined in SE11.
      2. Have you started the Sim class and started the TCP/IP server? You should do that before starting a communication channel in EWM-MFS - the channel needs the TCP/IP server running to communicate to.
      3. Did you get any exceptions while running either Bridge or Sim classes?
      4. Would you please provide entire log from both Bridge and Sim classes? I.e. all the messages displayed while running those two classes.
      5. Once you start the Bridge, go to SMGW, choose Goto -> Logged on Clients menu. Check if Java Connector is registered there. You should see entries where TP Name = java and TP Name = <id>. <Id> is the value of the 1st parameter, with which the Bridge class is executed. You can also post a screenshot for me to check.

      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

      Author's profile photo Nadim Chaouad
      Nadim Chaouad

      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:

      smgw%20-%20logged%20on%20clients

      I think I did not receive any exceptions while running either Bridge or Sim class

      Bridge

      Bridge

      Sim

      Sim

       

       

       

       

       

       

       

       

       

       

       

      Again, thanks for your help! BR

      Nadim

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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:

      1. go to /SCWM/MFS_CCH - assuming you rung Bridge and Sim on the same machine (your laptop or PC) then the host should be localhost and the port 7000
      2. go to SPRO: SCM Extended Warehouse Management -> Extended Warehouse Management -> Material Flow System (MFS) -> Master Data -> Communication Channel -> Define Communication Channel and verify the values in HS Confirmation and HS Request correspond to handshakeConfirmation and handshakeRequest in the properties file. Also check if and what value is specified in Fill Character (typically . <dot> is specified there)

      If indeed you have . <do> in Fill Character, you should put in the properties file:

      handshakeRequest=H.
      
      handshakeConfirmation=C.

      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

      Author's profile photo R R
      R R

      Hi Dominik,

      I am using Windows 11 to run the PLC emulator, but I keep getting the error message for Bridge

      "Error: Could not find or load main class pl.sapusers.mfsplc.bridge.Bridge"

      and for SIM

      "Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager"

       

      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%20-%20Command%20Prompt%20Screen

      ERROR - Command Prompt Screen

      FOLDER%20-%20Emulator%20Files%20are%20available

      FOLDER - Emulator Files are available

      PATH%20-%20System%20Environment%20Variable

      PATH - System Environment Variable

      CLASSPATH%20-%20System%20Environment%20Variable

      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

      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski
      Blog Post Author

      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:

      • not setting CLASSPATH and using -cp switch instead
      • putting all the jars, i.e. sapjco3.jar log4j-api-2.19.0.jar log4j-core-2.19.0.jar mfsplc.jar in a single directory
      • running the app from the directory where the jars are stored with commands:
      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

      and

      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

      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.