sps-modbus-app/app/src/main/java/com/example/user/myapp/MainActivity.java
2018-06-15 00:11:04 +02:00

64 lines
2.9 KiB
Java

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 = "10.0.0.60";
int port = 502;
EditText editText2 = (EditText) findViewById(R.id.port);
// int port = Integer.parseInt(editText2.getText().toString());
GlobalState state = (GlobalState) getApplicationContext();
state.setIpAddress(ipAddress);
state.setPort(port);
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);
}
}