Modbus-Droid / MobileModbus

Modbus-Droid (or as it is called on the Blackberry app world market – Mobile Modbus) was designed to be a simple Modbus TCP client / scanner. I wanted to have something similar to Modscan32, a program I use a lot at my work, but on my phone. My goal was to provide the simplicity of Modscan32, so I put the information I change the most – the register type, the register offset, and the quantity of registers to read – all right up front. The other stuff, like IP address, poll time and what-not are on a settings screen.

Download the app here: market://search?q=pname:com.bencatlin.modbusdroid
or scan this QR code:

Modbus-Droid is also open source, and built on an open source library – Modbus4J (that I had to modify a little for my needs).

The source code is available on GitHub here:
https://github.com/bigcat/ModbusDroid
and and archive that stops at version 1.0 is still available on launchpad here:
https://launchpad.net/modbusdroid
Both of these project hosting sites include my modified version of the Modbus4J.

Features

  • Intuitive Interface (if you are familiar with modbus)
  • Time-based polling
  • Write single holding registers and holding coils just by touching the value
  • Ability to view data in multipe formats, including binary for registers for people who like to use the register space for combined boolean data (like I do at work).
  • Write dialogs allow you to write data in the format you are displaying (i.e. a register displayed as binary allows you to set individual bits true and false inside the register)

Known Issues/bugs on 1.0

  • No way to handle byte-swapped data sources. I have found a place in the Modbus4J library I think I could handle this, but it was more surgery than I was comfortable with. I might tackle this somewhere down the road.
  • Some of the error messaging (like the connection lost error) results in a pretty cryptic or ‘programmer’ type of message. Hopefully I’ll get to putting in some human-readable text in a future version if I have time.
  • And I’m sure there a few others I haven’t found yet, if you find some please report the bugs on GitHub
  • This isn’t exactly a bug or issue, but there have been a lot of people contacting me about some compiler errors, or how to get this started in eclipse. Here is a the thing – please make sure you have the SDK installed correctly and can compile a sample project. I really want to help with questions and issues, but I can’t remotely debug your compiler or computer setup issues. This is my hobby project right now (hopefully android development will someday become my day job), and I don’t currently have the time or resources to write a bunch of documentation about it. But fortunately google already did, so reference the android SDK documentation before emailing me. Also, if you are still experiencing problems after getting a sample project to compile in eclipse and install in the emulator or your device, please refer to the GitHub site for the project to report bugs, or post questions, not the comments here.

Screenshots

43 Comments

  1. This sounds like a useful app, but I’m having a couple problems on DroidX:
    1. How do you specify the slave ID for the MODBUS device?
    2. I get a force close every time I attempt to “connect”. I know the phone can connect, because I’ve used the “Superview Mobile” app successfully with the same MODBUS device.

    I would be happy to do some beta testing for you. We have various types of MODBUS devices we can try this with.

    1. Thanks.
      1) I updated the APK file at the launchpad site (https://launchpad.net/modbusdroid), and I updated the android market, so you should see an update if you downloaded it from there. And that will have the ability to set the slave ID.
      2) That is a bummer! Does it give you an option to report the problem to me when the app closes? If it does could you do that, so I can see the error log it sends in the android developers console for the app, and I will see if I can track down the issue when I have some spare time.

      Thanks for the feedback!

    1. I haven’t looked at that in a long time, so I’m pretty fuzzy on what I did. I think I made a class to make it easier for me to handle modbusTCP connections in Android, and I seem to remember making a few other changes for something (but I can’t remember what I did now).

      I can extract out the library w/ the changes and put them somewhere convenient for you if you like.

    1. Right now they are all included w/ the source code for the project at http://www.launchpad.net/modbusdroid. I think I added a a locator class that was for getting a range of registers in order to avoid using the built-in functionality that packs requests together and initiates a ‘batch’. I needed more of a simple polling.

      Unfortunately I haven’t separated them out, and didn’t really do a good job of keeping the changes in some form that is easy to track (which is a bummer and not smart on my part because now I would love to re-sync w/ the main svn of modbus4J and it is a PITA for me to remember what I did). I have a few ideas to work on this project to improve it a bit, and one thing I might do is separate out just my modifications to the library as its own deal – as well as android 3.0+ tablet and phone support.

  2. Hello BigCat,
    I want to use your modbus code.But your code some errors when i want to connect my device. What is this error source?
    11-25 11:49:49.600: E/AndroidRuntime(348): FATAL EXCEPTION: Modbus4JTcpMaster
    11-25 11:49:49.600: E/AndroidRuntime(348): java.lang.NullPointerException
    11-25 11:49:49.600: E/AndroidRuntime(348): at com.bencatlin.modbusdroid.MbDroidMsgExceptionHandler.receivedException(MbDroidMsgExceptionHandler.java:23)
    11-25 11:49:49.600: E/AndroidRuntime(348): at com.serotonin.messaging.MessageControl.data(MessageControl.java:156)
    11-25 11:49:49.600: E/AndroidRuntime(348): at com.serotonin.messaging.InputStreamListener.run(InputStreamListener.java:76)
    11-25 11:49:49.600: E/AndroidRuntime(348): at java.lang.Thread.run(Thread.java:1019)

    1. 1) I’d really like any issues or questions posted at launchpad.net/modbusdroid

      2) I’m going to need a lot more information about what is going on here. Are you compiling this yourself and running it from eclipse? If so, is this the first time you’ve tried getting an app to run on your device from eclipse. What are you doing when this error occurs? What IP address are you trying to connect to, and what are all the values in your settings page? And what addresses are you trying to write to?

  3. Hello Bigcat,
    My device address is 85.107.41.190 and port 502. My device response is a little delaying about 100 -200 ms.
    I disabled m message lines at com.bencatlin.modbusdroid.MbDroidMsgExceptionHandler.receivedException.Your code is no error above.

    Thanks for the feedback.

  4. Please,Read 10000 address and two byte packet modbus RTU type for my device. Other address are password protected.My device return error code.

  5. I am trying to read the addresss 30256 but the apk shows the address 30256 doesnt allowme to have the complete address. Any idea how to get the complete address??

    1. Frank, I imagine that you are trying to read an input register based on the 30000 offset. I suggest trying to read address 256 with the type set to input register. Let me know if that works, and if not, what error message you are getting that prevents you from inputting the entire register offset you want to. And if you would, post any of your other questions or bugs at the launchpad site mentioned in the main post. Thanks and best of luck with your getting your device to work with the app!

  6. Hello, I think you developed a really usefull ap, my question is:

    When I poll my PLC using a Modbus TCP OPC server I query address 410300, in Modbus-Droid which address should I input?

    Thanks for your help.

    1. You should reference this document for more details on how ModBus works and common conventions for registers and stuff like that. It is a really great document on the protocol IMO. If that doesn’t work, the official modbus spec is readily available online and free (just google it – I think it is the first hit).

      http://www.lammertbies.nl/comm/info/modbus.html

  7. I am a student and I am trying to build an application for Monitoring PLC on android as an exercise for android programming. However, I do not know anything about PLC programming and how to use the modbus4j library ,Is it an open source library or some important files are closed.
    Where can i find the entire modbus4j library. Please reply soon. Need help.

  8. You can find more information about the modbus 4j library here: http://sourceforge.net/projects/modbus4j/

    I’m not sure what you are asking about PLC programming – that is a field that is pretty diverse. But if it speaks modbus over an ethernet connection you should be able to talk to it w/ the modbus4j library in java. I didn’t make any massive changes to the library for my app – mostly just removed the serial port portions since the standard libraries to support that aren’t in android, so I would start there doing something similar for your class project.

  9. Hi BigCat,
    I’m try to use your source code but i get problem at
    mbTCPMaster = mbFactory.createModbusTCPMaster(ipParameters, true);

    application come to Force Close at this command.
    Please help me to solve that. Thank you so much.

  10. Hi BigCat,

    I have installed your app in my phone and it works very well – great app. Now i’m trying use your source code… but not good news yet 🙁

    Best regards,
    Marco

  11. Hi BIgcat,
    Thanks a lot for sharing such a nice application. it would be very helpful to me. I just downloaded the project source from github and Modbus4J library from sourceforge.net. but is it modfied version of Modbus4J? it will be great if you put Modbus4J libray at some place. so,we can get it very easily
    Thanks & Regards
    Juned Khan

    1. The source from the version of modbus4j is included in my source code – under the com.serotonin.modbus4j package folder. The serioutils.jar is not currently included for several reasons, but it is available on the modbus4j sourceforge page. I can’t remember when I last got a copy of their library to verify against, so no promises it will compile with the latest version, but if you need to sourceforge should let you go back to early 2011 and grab the copy from then and it should work.

      1. I could be wrong, but I don’t think Modbus has an explicit way to do strings. Instead, you would have to write the ASCII or Unicode numeric equivalent to a register, one character at a time. As it stands, I don’t think (it has been a while) I put in a way to write a string in the app, and then have it translate one-character-per-register for you.

  12. Hi BigCat, i have problem with your app. I have got PLC Mitsubishi FX3U with ENET Module. It is configured correctly i think (I can send ladder program to PLC by Ethernet without problems) but i can’t connect to PLC using your app… When I trying, i see “connected to 192.168.1.50” (PLC ip) and then i see error like that:
    http://naforum.zapodaj.net/3b2837784c12.png.html
    I will be greatful if You try to help me. Greetings

    1. Sorry man I don’t have an exact solution. The only advice I have is try port 502 – 5551 isn’t a normal port for modbus, so unless the manufacturer specifically says port 5551 is the right port for Modbus TCP, I would think that is the problem.

      Otherwise the error generically means it can’t find a modbus server at the IP address and port – so you might make sure everything is all connected to the same network, and that your phone can ping the ethernet address of the PLC.

      1. Hi BigCat
        I managed to upload your application on the emulator, but when I press the icon the app wont start and on emulator I get the message “Unfortunately, ModBus -Droid has stopped” and in the LogCat in Eclipse I got listed many errors. What could be the problem,
        thank you in advance.
        Tadej

        1. Sorry, but I’m not putting a ton of effort (or really any) into this code base anymore. Instead I’m working on a re-write from the ground up in order to work w/ newer phones/devices/etc with the latest 4.x android versions.

          On top of that, I would have no idea how to point you towards what might be going wrong unless I had more details about what is going on in logcat.

          Did you build this from source off of GitHub? Or did you just download the APK file?

          1. I downloaded the zip file from GitHub, then I imported the “Existing project into workspace”, then I right clicked the project (in the Package Explorer) -> Properties -> chose Android and in the “Project Build Target” checked Android 4.4.2 -> clicked Apply and OK -> then I did a clean and run the project (upload to the emulator).

          2. Try setting the project target to Android 2.3 or there-abouts. I think some time a year ago I tried to get it to compile against 4.x-something and I couldn’t, and didn’t want to put effort into fixing it. But 2.x (probably 2.2+) will likely work better. Give that a try and see if it helps.

          1. @Ben Catlin
            I did set the project target first to Android 2.3 and second to 2.2, but then when the project is buld I get 8 errors in the “Errorrs” section on the bottom, and the project won’t run untill I fix these errors.

            for the 2.3
            the first error is:
            ActionBar cannot be resolved to a type
            ModbusDroidActivity.java —
            /ModbusDroid-master/src/com/bencatlin/modbusdroid/activities
            line 21
            Java Problem

            the second error is:
            ActionBar cannot be resolved to a type
            ModbusDroidActivity.java
            /ModbusDroid-master/src/com/bencatlin/modbusdroid/activities
            line 33
            Java Problem

            ..and so on..

            @Krystian: I have listed in src folder the serotonin content..

          2. I found the cause: Under properties -> Java Build Path -> under “Order and Exoprt” tab -> I had to check the seroUtils.jar. and now I can lounch the app on the emulator.

            But the default Slave ID of my PLC is 255, and if I change the Slave ID on the emulator the app chrashes.

            How can I set the Slave ID to 255?

          3. Cool, I’m glad you got it compiling and running.

            I threw in the setting (if memory serves) on the setting page to set the slave ID, but it was completely experimental since everything I had to test either used 1, or ignored that parameter.

            Good luck w/ that, let me know if you get the Slave ID working with your device.

          4. Hi, (last week I was not at home..), but now

            In com.serotonin.modbus4j.base ModbusUtils.java on the line #72 I changed the condition to the slaveId > 256

            and

            In com.serotonin.modbus4j.msg ModbusMessage.java on the line #32 I changed to the slaveId > 255

            and now I can set the slave ID in the application to 255 and I can via emulator set the coil on the PLC.

            Now I would like to add to the layout some push buttons to switch on/off the different coils on the PLC i.e. making it more user friendly. Do you maybe have some more tutorial how to add and configure buttons or maybe give me an advice where to start..

            thank you in advance
            tadej

  13. I think the app would be great, but I can not get it to work. It installs, but comes up to the Screen asking for address and length, and pint type, also shows the message that it is Not Connected! Of cours it is not, I can not get to the screen to configure the PLC that I want to connect to, is there a patch?

    1. Sorry, I’m not really updating this app anymore – the existing version in the store I’ve actually even lost the signing keys for, so I can’t update it even if I had the time.

      But, all the source is available on Github, you are welcome to compile and run it yourself. I guess I’m not sure what you are asking for as all the IP address settings are in the app settings in the “more” menu.

  14. error occured while connecting: the error show like ::::jave.net.sockettimeoutexception.failed to connect to ip (port)after 15000ms..what is the error..i know how to solve?

  15. Hi Ben,
    Please, help me with android application using ModbusForJava (Modbus4j).

    I’m trying to run from my AS your application I got here : https://github.com/bigcat/Mobile-Modbus. To use the library Modbus4J I downloaded and copied it (from here https://github.com/infiniteautomation/modbus4j/tree/master/Modbus4J) into the top-level “Libraries/Modbus4J” folder.
    There the string in the build.gradle file:
    compile files (‘lib/seroUtils.jar’, ‘lib/commons-lang3-3.0.jar’, ‘lib/commons-logging-1.0.4.jar’, ‘lib/RXTXcomm.jar’, ‘lib/serotonin-timer.jar’)

    I downloaded jar files seroUtils.jar, commons-lang3-3.0.jar, commons-logging-1.0.4.jar and RXTXcomm.jar and copied into the lib folder, but where should I get the jar file serotonin-timer.jar? I can’t find it anywhere!

    My project now has been builded succesfully, but when I try to run it, there are two errors “Error:com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)”.

    Plesase, help me, where should I find files for “Libraries/Modbus4J” folder?

    Thank you in advance!

    1. Man, I haven’t worked on that in a while. It probably needs serious updating to the latest version of the library using maven or something.

      Besides that the app is a super-early work in progress I haven’t had time to dig into over the last year (or more now). So my memory is pretty weak about where I left off on that app.

Leave a Reply to Hasip TUNA Cancel reply

Your email address will not be published.
Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.