Android – exchange data with Siemens PLC

ic_launcher At first you need download and install the Android development tools:

The following link allows to download a archive file which includes all required tools for Android development. http://developer.android.com/sdk/index.html

  • JDK version 5-6 : Java Development Kit and Java Runtime Environment (JRE is included with the JDK). Contains files and small programs (tools) that you need to write Java code, process and execute.
  • Eclipse IDE: Eclipse Integrated Development Environment. Contains the necessary tools to create, compile and package Android application and also provides an Android device emulator, so that Android applications can be tested without a real Android phone.
  • Android SDK: Android Software Development Kit includes a comprehensive set of development tools.
  • ADT: Google provides the Android Development Tools (ADT) to develop Android applications with Eclipse. ADT is a set of components (plug-ins) which extend the Eclipse IDE with Android development capabilities.

MyFirstApp

ic_launcher The next step is developing a Android application and communication with PLC. For this purpose you can use Wifi and Libnodave free library:

  • For Wi-Fi is a 3G/UMTS router SCALANCE M875 with HSPA and VPN functionality for industrial applications.
  • For connection your Android application with PLC you need also download LibNoDave library from site http://libnodave.sourceforge.net/ and modify it.

ic_launcher Create a Android application:

We will create test application as simple as possible.

Select File → New → Other… → Android → Android Application Project to create a new Android project with the following data.

  • Application Name – S7 NoDaveTest
  • Project Name – S7NoDaveTest
  • Package name – com.example.s7libnodavetest
  • Target SDK – API 17: Android 4.2 (Jelly Bean)
  • Template – BlankActivity
  • Activity – MainActivity
  • Layout – activity_main

S7NoDaveTest

ic_launcherAdd views and attributes:

Create the layout for your Android application. Select the res/layout/activity_main.xml and create the layout via drag and drop or via the XML source code.

  • Plain Text for IP address
  • Plain Text for entries variable type “test”
  • Plain Text for entries variable type “value”
  • Widgets button – connection with PLC
  • Widgets button – read values
  • Widgets button – write values

Select the res/values/string.xml file and create static attributes.

  • ipaddress – IP address
  • connection – Connect
  • read – Read
  • write – Write

Edit view properties. Select each user interface component (an instance of View) and change its properties via the Eclipse Properties view.

S7NoDaveTest2

ic_launcherImport LibNoDave library:

  • – In the package explorer, right click your new project and select
    import
  • then select the “File system” option. Here you should be
    presented with a dialog that allows you to browse for a directory.
  • Select the base directory that contains you source files, and then
    check the files/directories you would like to import.

S7NoDaveImport S7NoDaveImport2

Downloaded library is test library that why you need modify it. Switch off all debug functions, delete all not used variables, leave only needed functions and delete function for another type communications. You also need to create bridge class. This class use for connecting LibNoDave library and UI of the android application, as connection with PLC, read and write variables and so on.

ic_launcherStart example:

test_nodave2 test_nodave4 Java_source

 

 

ic_launcherThe VARIABLE TABLE S7:

The intention create an android application working the same as the variable table S7.

VarTab_NoDave_Project Java_source

Example of allowed addresses and type variables for the variable table.

S7dataTypes

Tested with the Android emulator and a ‘real’ network interface. Forwarding a TCP port to the emulator with Telnet and ADB:

  • adb forward tcp:sourceport tcp:destport
  • Telnet localhost 5554
  • redir add udp:sourceport:destport

VarTab_NoDave_Run VarTab_NoDave_Connection

Structure of the Variable Table:

Advertisements

21 Responses to “Android – exchange data with Siemens PLC”

  1. Flemming Astrup Says:

    Hallo Alex I’m making an app to communicate with S7 PLC, I can with buttons read and write to PLC, but after about 20 read / write communication becomes slow and I only get 0 values ​​back. I have tried several solutions but not quite. So I thought if it’s possible to get source code for your android project. I hope you can help me :-).Thank you for a fine website.

  2. IncioDev Says:

    Hi Alex tnks for your blog, very interesting. I want to read and write memory of a Logo 0BA7 with java libnodave (android app). Are there some Logo specific parameters?? Or S7 parameters work well??

  3. santhoshbhaskar Says:

    i would like to know how PLC communicate with android mobile for data transfer and programming without any additional hardware interface.can internet required in mobile.without net mobile should communicate

  4. Nazar Says:

    Hello, Alex! Thanck you for your great job! But i can’t connect to PLC in first project. Help me, please. My log file:
    10-31 11:37:48.378: E/SensorManager(31926): thread start
    10-31 11:38:20.953: E/AndroidRuntime(31926): FATAL EXCEPTION: main
    10-31 11:38:20.953: E/AndroidRuntime(31926): java.lang.IllegalStateException: Could not execute method of the activity
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.view.View$1.onClick(View.java:3704)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.view.View.performClick(View.java:4232)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.view.View$PerformClick.run(View.java:17298)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.os.Handler.handleCallback(Handler.java:615)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.os.Handler.dispatchMessage(Handler.java:92)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.os.Looper.loop(Looper.java:137)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.app.ActivityThread.main(ActivityThread.java:4921)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.lang.reflect.Method.invokeNative(Native Method)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.lang.reflect.Method.invoke(Method.java:511)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at dalvik.system.NativeStart.main(Native Method)
    10-31 11:38:20.953: E/AndroidRuntime(31926): Caused by: java.lang.reflect.InvocationTargetException
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.lang.reflect.Method.invokeNative(Native Method)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.lang.reflect.Method.invoke(Method.java:511)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.view.View$1.onClick(View.java:3699)
    10-31 11:38:20.953: E/AndroidRuntime(31926): … 11 more
    10-31 11:38:20.953: E/AndroidRuntime(31926): Caused by: android.os.NetworkOnMainThreadException
    10-31 11:38:20.953: E/AndroidRuntime(31926): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at libcore.io.IoBridge.connect(IoBridge.java:112)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.net.Socket.startupSocket(Socket.java:566)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.net.Socket.tryAllAddresses(Socket.java:127)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.net.Socket.(Socket.java:177)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at java.net.Socket.(Socket.java:149)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at nodave.DataIsoTCP.(DataIsoTCP.java:29)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at nodave.DataIsoTCP.ConnectIsoTcp(DataIsoTCP.java:90)
    10-31 11:38:20.953: E/AndroidRuntime(31926): at com.example.s7nodavetest.MainActivity.makeConnection(MainActivity.java:45)

  5. Johan Nieuwoudt Says:

    Very helpful article, thank you, but I cannot import the Libnodave Android library. I downloaded Libnodave and extracted it, but there is no Android sub directory available.
    Can you please assist.

  6. Nippon_1 Says:

    We have download your project. But an error of “negative time” is appearing, Do you know how to solve it?

  7. jose Says:

    Muy bien.

  8. cfur_88 Says:

    hi alex, I would like to make a connection between android and plc s7 1200 is possible using Libnodave. I see that only use to s7 300/400. thanks you give me an example.

  9. William Says:

    Hi Alex, i try to communicate your project with eclpse emulator and plcsim over nettoplcsim (all in the same pc), but it doesn,t works. Can you help me?

  10. Francesco Says:

    Hi Alex,
    I’m trying to communicate with a plc siemens logo 0BA7 via Android smartphone with a few apps that I have found … and also through the app you described … I saw some videos on youtube where these apps work well … I am able to connect with the plc but I can not read and set inputs and outputs. this is the first time that I try to work with a plc, and I have not found much information on this plc … there is something that I have to configure on plc for the app to work?
    I cordially greet and thank you in advance

  11. Alane Rostand Says:

    i have some question .i have to write a Apps ,those conect some android fone or tablet to a Sps S300.between the conection i have to write a 1 to a precisious adress.
    for example i have 2button ,one do start the engime and another one ,who stop.those adress was been save in datebblock.

    could you people help me?

    i already write one program but i don´t schure if it´s correct.

  12. Nivas Devarapalli Says:

    Hi,
    My Name is Nivas Working as an Android Developer.
    How Write String on ModBus ?

    Any Idea Share with me.

  13. Braham Lawas Lawu Says:

    Hi, my name is Braham and i’m a student.. I want to ask, what kind of android ADT did you use ?. I’ve already installed android ADT and the SDK before with eclipse kepler but it wouldn’t work. So i want to make it same as you did.

    Thanks before

  14. Braham Says:

    Hi, my name is braham. I’m a student of university. I would like to ask about the version of android ADT and SDK. What kind of version ADT and SDK did you use ?

    Thanks

  15. fs Says:

    could someone make a tasker plug in of libnodave? It would be great

  16. cirilo capriel Says:

    please tell me how to use the libnodave library, please help me

  17. canoniac Says:

    Hi,
    I’m working on a Android App just like yours only difference- I use delphi xe6. I hope someone can help me because, it’s not that easy as i thought it would be.:
    How can i use libnodave.dll on a Android based Smartphone or Tablet? or how do I use the .dll in delphi?

  18. cirilo capriel Says:

    how about allen bradley PLC, can you do a tutorial please, I hope you can make it, I need it, please help me super dear friend

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: