2018-06-13 00:30:36 +02:00
|
|
|
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);
|
2018-06-13 22:22:59 +02:00
|
|
|
//String ipAddress = editText1.getText().toString();
|
|
|
|
String ipAddress ="192.168.157.16";
|
2018-06-13 00:30:36 +02:00
|
|
|
|
|
|
|
EditText editText2 = (EditText) findViewById(R.id.port);
|
2018-06-13 22:22:59 +02:00
|
|
|
// int port = Integer.parseInt(editText2.getText().toString());
|
|
|
|
int port = 503;
|
2018-06-13 00:30:36 +02:00
|
|
|
|
|
|
|
EditText editText3 = (EditText) findViewById(R.id.ref);
|
2018-06-13 22:22:59 +02:00
|
|
|
// int ref = Integer.parseInt(editText3.getText().toString());
|
2018-06-13 00:30:36 +02:00
|
|
|
|
|
|
|
EditText editText4 = (EditText) findViewById(R.id.count);
|
2018-06-13 22:22:59 +02:00
|
|
|
// int count = Integer.parseInt(editText4.getText().toString());
|
|
|
|
int ref = 1;
|
|
|
|
int count = 8;
|
2018-06-13 00:30:36 +02:00
|
|
|
|
|
|
|
GlobalState state = (GlobalState) getApplicationContext();
|
|
|
|
state.setIpAddress(ipAddress);
|
|
|
|
state.setPort(port);
|
2018-06-13 22:22:59 +02:00
|
|
|
// 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);
|
2018-06-13 00:30:36 +02:00
|
|
|
|
|
|
|
Intent nextIntent = new Intent(this, DisplayMessageActivity.class);
|
|
|
|
this.startActivity(nextIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|