package com.example.user.myapp; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } /** Called when the user taps the Send button */ public void sendMessage(View view) { EditText editText1 = (EditText) findViewById(R.id.ipAddress); //String ipAddress = editText1.getText().toString(); String ipAddress ="192.168.157.16"; EditText editText2 = (EditText) findViewById(R.id.port); // int port = Integer.parseInt(editText2.getText().toString()); int port = 503; EditText editText3 = (EditText) findViewById(R.id.ref); // int ref = Integer.parseInt(editText3.getText().toString()); EditText editText4 = (EditText) findViewById(R.id.count); // int count = Integer.parseInt(editText4.getText().toString()); int ref = 1; int count = 8; GlobalState state = (GlobalState) getApplicationContext(); state.setIpAddress(ipAddress); state.setPort(port); // state.setCoilRef(ref); // state.setCoilCount(count); Intent coilServiceIntent = new Intent(this, MyIntentService.class); coilServiceIntent.setAction("read.coil"); coilServiceIntent.putExtra("extra.ip.address", ipAddress); coilServiceIntent.putExtra("extra.ip.port", port); coilServiceIntent.putExtra("extra.ref", GlobalState.InputConfig.COIL.getStartReference()); coilServiceIntent.putExtra("extra.count", GlobalState.InputConfig.COIL.getCount()); coilServiceIntent.putExtra("extra.intent.name", "readOnlyCoil"); this.startService(coilServiceIntent); Intent discretInputserviceIntent = new Intent(this, MyIntentService.class); discretInputserviceIntent.setAction("read.discrete.input"); discretInputserviceIntent.putExtra("extra.ip.address", ipAddress); discretInputserviceIntent.putExtra("extra.ip.port", port); discretInputserviceIntent.putExtra("extra.ref", GlobalState.InputConfig.DISCRETE_INPUT.getStartReference()); discretInputserviceIntent.putExtra("extra.count", GlobalState.InputConfig.DISCRETE_INPUT.getCount()); discretInputserviceIntent.putExtra("extra.intent.name", "readOnlyDiscreteInput"); this.startService(discretInputserviceIntent); Intent inputRegisterServiceIntent = new Intent(this, MyIntentService.class); inputRegisterServiceIntent.setAction("read.input.register"); inputRegisterServiceIntent.putExtra("extra.ip.address", ipAddress); inputRegisterServiceIntent.putExtra("extra.ip.port", port); inputRegisterServiceIntent.putExtra("extra.ref", GlobalState.InputConfig.INPUT_REGISTER.getStartReference()); inputRegisterServiceIntent.putExtra("extra.count", GlobalState.InputConfig.INPUT_REGISTER.getCount()); inputRegisterServiceIntent.putExtra("extra.intent.name", "readOnlyInputRegister"); this.startService(inputRegisterServiceIntent); Intent nextIntent = new Intent(this, DisplayMessageActivity.class); this.startActivity(nextIntent); } }