sps-modbus-app/app/src/main/java/com/example/user/myapp/MainActivity.java

53 lines
1.8 KiB
Java
Raw Normal View History

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);
String ipAddress = editText1.getText().toString();
EditText editText2 = (EditText) findViewById(R.id.port);
int port = Integer.parseInt(editText2.getText().toString());
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());
GlobalState state = (GlobalState) getApplicationContext();
state.setIpAddress(ipAddress);
state.setPort(port);
state.setCoilRef(ref);
state.setCoilCount(count);
Intent serviceIntent = new Intent(this, MyIntentService.class);
serviceIntent.setAction("read.coil");
serviceIntent.putExtra("extra.ip.address", ipAddress);
serviceIntent.putExtra("extra.ip.port", port);
serviceIntent.putExtra("extra.ref", ref);
serviceIntent.putExtra("extra.count", count);
serviceIntent.putExtra("extra.intent.name", "readCoil8192");
this.startService(serviceIntent);
Intent nextIntent = new Intent(this, DisplayMessageActivity.class);
this.startActivity(nextIntent);
}
}