steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
267 stars 111 forks source link

Getting j2mod/jSerialComm to work on Android #54

Closed Play3r21 closed 7 years ago

Play3r21 commented 7 years ago

Has anyone been able to successfully get j2mod and its dependency jSerialComm to work on Android? I'm facing the same issue that the users in jSerialComm's issues thread 45 were facing. I've been searching for an answer for more than a week and have gotten nowhere.

I've tried the following (plus many others, all of which did not help):

I'm working with a device running Android 5.1.1 (API 22) on an ARM Cortex-A9 SoC with 5 physical serial ports, labelled ttyAMA0 through ttyAMA4 in /dev/. SELinux is set to Disabled.

I know that this question is better suited for the jSerialComm issues threads, but it's already been asked there and no one has provided a viable solution.

Thank you very much for the help.

steveohara commented 7 years ago

You are correct, this question isn't suitable for this forum, howerver...

The serial comms is abstracted in j2mod (AbstractSerialConnection) so if you can't find a workaround, you could always implement your own serial connection using an Android compatible library. Take a look at the ModbusSerialMaster to see how to use your own comms connection.

orensharon commented 6 years ago

This is the correct answer to make it work on android device: https://github.com/Fazecast/jSerialComm/issues/36


To inject jSerialComm to j2mod remove jSerialComm depenedency from j2mod's pom.xml file and import jSerialComm.jar from the resource folder

Make sure maven doesn't import the source from .m2 library. I had to delete jSerialComm from .m2 folder to make it work. You also need to copy all the files from jSerialComm.jar/Android to jniLibs folder in your androids project.

For build jSerialComm lib I used eclipse (it didn't work with intelij) with:

One more thing is to give root access to the serial port in the Android device (you can take a look at this :https://github.com/chrisdew/android-serialport-api/blob/10cb9c4d6dd7e4357473d1438530dd5639eb5e12/android-sercd/project/src/gnu/sercd/Sercd.java#L69)