Note that there are some explanatory texts on larger screens.

plurals
  1. POModbus protocol escapes the thread (Android,Jamod)
    primarykey
    data
    text
    <p>I'm trying to connect to PLC using ModBus protocol. I'm calling ModBus connect method from thread and I'm getting exception that I'm running communications on the main thread... I wonder where it escapes...</p> <p>Exception:</p> <pre><code> 08-02 10:48:44.461: W/System.err(4395): android.os.NetworkOnMainThreadException 08-02 10:48:44.471: W/System.err(4395): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 08-02 10:48:44.471: W/System.err(4395): at </code></pre> <p>Code:</p> <pre><code> package com.kikudjiro.android.echo; import net.wimpi.modbus.facade.ModbusTCPMaster; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class settings extends Activity implements Runnable { Button connect_b, disconnect_b; Thread comm = new Thread(this); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings); addListenerOnButton(); } public void addListenerOnButton() { connect_b = (Button) findViewById(R.id.button1); disconnect_b = (Button) findViewById(R.id.button2); connect_b.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { comm.run(); } }); disconnect_b.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { comm.interrupt(); } }); } // @Override public void run() { try { ModbusTCPMaster MB = new ModbusTCPMaster("192.168.107.29", 502); //while (!comm.interrupted()) { Log.i("!!!!!!!", "try!"); MB.connect(); MB.writeCoil(1, 1, true); MB.disconnect(); //} } catch (Exception ex) { ex.printStackTrace(); Log.i("hhh", "exceptionas!!!"); } finally { Log.i("!!!!!!!", "finally!"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload