Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

  • I am using modbus4j in Android application. Before I tested it in java, and works fine. But in Android I have problems with the master.init(), it does not work. In the manifest I add permissions for Internet and Access network state. I have a code more or less like this:

    // Perform action on click
                // Read IP from layout***
                EditText edittext_IP = (EditText) findViewById(;
                TextView MWReaded = (TextView) findViewById(;
                // **********************
                String slaveIP;
                slaveIP = edittext_IP.getText().toString();
                ModbusFactory factory = new ModbusFactory();
                IpParameters params = new IpParameters();
                ModbusMaster master = factory.createTcpMaster(params, true);
                try {
                } catch (ModbusInitException e) {
                    // TODO Auto-generated catch block
                            "Error: " + e.getMessage(), 10).show();
                ModbusLocator locator = new ModbusLocator(1,
                        RegisterRange.HOLDING_REGISTER, 0,
                Object xx = null;
                try {
                    xx = master.getValue(locator);
                } catch (ModbusTransportException e) {
                    // TODO Auto-generated catch block
                } catch (ErrorResponseException e) {
                    // TODO Auto-generated catch block
                int Register = 0;
                if (xx != null){
                Register = Integer.parseInt(xx.toString());
                } else{
                    Register = 6969;
                TextView txttest_n = (TextView) findViewById(;
                txttest_n.setText("n=" + n);
                n = n + 1;

    But the master is never initialized. I can see a exception. "android.os.NetworkOnMainThreadException"
    Do you know how can I solve this problem?**

  • I would suppose it's pretty much what the exception says: you're running network operations on the main thread, which Android frowns upon. Try running init in a service thread or something.

  • Hello.
    Thanks for the information.
    I have created and asynctask and I use the master.ini() in this new thread. Works fine.

    Best regards.