Installing the modbus RTU library for Android is straightforward. Once you decided which version to use (release or debug), follow these steps:
BiemmeModbus.jar
into \libs
folder of your Android project\libs\armeabi
(eventually create it if it does not exist)import com.biemme.modbus.*;
That's it! Use the library as your needs. For instance, you can add the following statements for reading the first 10 registers from node 1.
protected void onResume() { super.onResume(); int slave_id = 1; //slave id device number int fid = 0; //file handler serial port int start_ad = 0; int regs = 10; //number of registers to read int [] hr = new int[20]; //serial opening with baudrate 38400 bps and 40000ns as timeout fid = ModbusLib.openCom(38400, 40000, 40000); //Logs the fid, use adb logcat Log.d("FID=",String.valueOf(fid)); ModbusLib.ReadHoldingRegisters(fid, slave_id, start_ad, regs, hr); for (int i = 0; i <= (regs-1); i++){ Log.d("Reg Value =",String.valueOf(hr[i])); } ModbusLib.closeCom(fid); }