we did things
This commit is contained in:
parent
57e43ecd18
commit
222de3533c
@ -10,6 +10,7 @@ import android.support.v7.app.AppCompatActivity;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ public class DisplayMessageActivity extends AppCompatActivity {
|
|||||||
serviceIntent.putExtra("extra.intent.name", "readOnlyCoil");
|
serviceIntent.putExtra("extra.intent.name", "readOnlyCoil");
|
||||||
getApplicationContext().startService(serviceIntent);
|
getApplicationContext().startService(serviceIntent);
|
||||||
|
|
||||||
handlerCoil.postDelayed(this, 2000);
|
handlerCoil.postDelayed(this, 10000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ public class DisplayMessageActivity extends AppCompatActivity {
|
|||||||
TextView textView = findViewById(R.id.textView1);
|
TextView textView = findViewById(R.id.textView1);
|
||||||
Date currentTime = Calendar.getInstance().getTime();
|
Date currentTime = Calendar.getInstance().getTime();
|
||||||
textView.setText(new Double(Math.random()).toString());
|
textView.setText(new Double(Math.random()).toString());
|
||||||
handlerCoil.postDelayed(this, 1000);
|
handlerCoil.postDelayed(this, 2000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ public class DisplayMessageActivity extends AppCompatActivity {
|
|||||||
TextView textView4 = findViewById(R.id.textView4);
|
TextView textView4 = findViewById(R.id.textView4);
|
||||||
textView4.setText(new Boolean(booleanArray[3]).toString());
|
textView4.setText(new Boolean(booleanArray[3]).toString());
|
||||||
|
|
||||||
TextView textView5 = findViewById(R.id.textView5);
|
/* TextView textView5 = findViewById(R.id.textView5);
|
||||||
textView5.setText(new Boolean(booleanArray[4]).toString());
|
textView5.setText(new Boolean(booleanArray[4]).toString());
|
||||||
|
|
||||||
TextView textView6 = findViewById(R.id.textView6);
|
TextView textView6 = findViewById(R.id.textView6);
|
||||||
@ -109,14 +110,19 @@ public class DisplayMessageActivity extends AppCompatActivity {
|
|||||||
textView7.setText(new Boolean(booleanArray[6]).toString());
|
textView7.setText(new Boolean(booleanArray[6]).toString());
|
||||||
|
|
||||||
TextView textView8 = findViewById(R.id.textView8);
|
TextView textView8 = findViewById(R.id.textView8);
|
||||||
textView8.setText(new Boolean(booleanArray[7]).toString());
|
textView8.setText(new Boolean(booleanArray[7]).toString()); */
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private BroadcastReceiver inputRegisterMessageReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver inputRegisterMessageReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
Bundle bundle = intent.getExtras();
|
||||||
|
ArrayList<Integer> integers = bundle.getIntegerArrayList("irValues");
|
||||||
|
|
||||||
|
TextView textView9 = findViewById(R.id.textView9);
|
||||||
|
textView9.setText(integers.get(0).toString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ public class GlobalState extends Application {
|
|||||||
|
|
||||||
//
|
//
|
||||||
public enum InputConfig {
|
public enum InputConfig {
|
||||||
COIL (8192, 8),
|
COIL (8192, 80),
|
||||||
INPUT_REGISTER (1, 1),
|
INPUT_REGISTER (0, 2),
|
||||||
DISCRETE_INPUT(1, 12);
|
DISCRETE_INPUT(0, 12);
|
||||||
|
|
||||||
private int startReference;
|
private int startReference;
|
||||||
private int count;
|
private int count;
|
||||||
|
@ -18,16 +18,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
/** Called when the user taps the Send button */
|
/** Called when the user taps the Send button */
|
||||||
public void sendMessage(View view) {
|
public void sendMessage(View view) {
|
||||||
EditText editText1 = (EditText) findViewById(R.id.ipAddress);
|
EditText editText1 = (EditText) findViewById(R.id.ipAddress);
|
||||||
String ipAddress = editText1.getText().toString();
|
// String ipAddress = editText1.getText().toString();
|
||||||
|
String ipAddress = "10.0.0.60";
|
||||||
|
int port = 502;
|
||||||
|
|
||||||
EditText editText2 = (EditText) findViewById(R.id.port);
|
EditText editText2 = (EditText) findViewById(R.id.port);
|
||||||
int port = Integer.parseInt(editText2.getText().toString());
|
// 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();
|
GlobalState state = (GlobalState) getApplicationContext();
|
||||||
state.setIpAddress(ipAddress);
|
state.setIpAddress(ipAddress);
|
||||||
@ -44,7 +40,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
coilServiceIntent.putExtra("extra.intent.name", "readOnlyCoil");
|
coilServiceIntent.putExtra("extra.intent.name", "readOnlyCoil");
|
||||||
this.startService(coilServiceIntent);
|
this.startService(coilServiceIntent);
|
||||||
|
|
||||||
Intent discretInputserviceIntent = new Intent(this, MyIntentService.class);
|
/* Intent discretInputserviceIntent = new Intent(this, MyIntentService.class);
|
||||||
discretInputserviceIntent.setAction("read.discrete.input");
|
discretInputserviceIntent.setAction("read.discrete.input");
|
||||||
discretInputserviceIntent.putExtra("extra.ip.address", ipAddress);
|
discretInputserviceIntent.putExtra("extra.ip.address", ipAddress);
|
||||||
discretInputserviceIntent.putExtra("extra.ip.port", port);
|
discretInputserviceIntent.putExtra("extra.ip.port", port);
|
||||||
@ -60,7 +56,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
inputRegisterServiceIntent.putExtra("extra.ref", GlobalState.InputConfig.INPUT_REGISTER.getStartReference());
|
inputRegisterServiceIntent.putExtra("extra.ref", GlobalState.InputConfig.INPUT_REGISTER.getStartReference());
|
||||||
inputRegisterServiceIntent.putExtra("extra.count", GlobalState.InputConfig.INPUT_REGISTER.getCount());
|
inputRegisterServiceIntent.putExtra("extra.count", GlobalState.InputConfig.INPUT_REGISTER.getCount());
|
||||||
inputRegisterServiceIntent.putExtra("extra.intent.name", "readOnlyInputRegister");
|
inputRegisterServiceIntent.putExtra("extra.intent.name", "readOnlyInputRegister");
|
||||||
this.startService(inputRegisterServiceIntent);
|
this.startService(inputRegisterServiceIntent); */
|
||||||
|
|
||||||
Intent nextIntent = new Intent(this, DisplayMessageActivity.class);
|
Intent nextIntent = new Intent(this, DisplayMessageActivity.class);
|
||||||
this.startActivity(nextIntent);
|
this.startActivity(nextIntent);
|
||||||
|
@ -71,6 +71,7 @@ public class MyIntentService extends IntentService {
|
|||||||
List<Boolean> listBooleanBit = new ArrayList<>();
|
List<Boolean> listBooleanBit = new ArrayList<>();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
listBooleanBit.add(bv.getBit(i));
|
listBooleanBit.add(bv.getBit(i));
|
||||||
|
System.out.println("input discrete values : "+i+" - "+bv.getBit(i));
|
||||||
}
|
}
|
||||||
sendBooleanListToActivity(listBooleanBit, intentReceiveName);
|
sendBooleanListToActivity(listBooleanBit, intentReceiveName);
|
||||||
master.disconnect();
|
master.disconnect();
|
||||||
@ -87,6 +88,7 @@ public class MyIntentService extends IntentService {
|
|||||||
BitVector bv = master.readCoils(ref,count);
|
BitVector bv = master.readCoils(ref,count);
|
||||||
List<Boolean> listBooleanBit = new ArrayList<>();
|
List<Boolean> listBooleanBit = new ArrayList<>();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
System.out.println("coil values : "+i+" - "+bv.getBit(i));
|
||||||
listBooleanBit.add(bv.getBit(i));
|
listBooleanBit.add(bv.getBit(i));
|
||||||
}
|
}
|
||||||
sendBooleanListToActivity(listBooleanBit, intentReceiveName);
|
sendBooleanListToActivity(listBooleanBit, intentReceiveName);
|
||||||
@ -104,9 +106,11 @@ public class MyIntentService extends IntentService {
|
|||||||
InputRegister [] inputRegisters = master.readInputRegisters(ref, count);
|
InputRegister [] inputRegisters = master.readInputRegisters(ref, count);
|
||||||
ArrayList<Integer> listIntegerInputRegister = new ArrayList<>();
|
ArrayList<Integer> listIntegerInputRegister = new ArrayList<>();
|
||||||
for (InputRegister ir : inputRegisters) {
|
for (InputRegister ir : inputRegisters) {
|
||||||
|
System.out.println("ir values : "+Math.random()+" - "+ir.getValue());
|
||||||
listIntegerInputRegister.add(ir.getValue());
|
listIntegerInputRegister.add(ir.getValue());
|
||||||
}
|
}
|
||||||
sendIntegerListToActivity (listIntegerInputRegister, intentReceiveName);
|
sendIntegerListToActivity (listIntegerInputRegister, intentReceiveName);
|
||||||
|
master.disconnect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Exception in reading input register " + e);
|
System.out.println("Exception in reading input register " + e);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,18 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".DisplayMessageActivity">
|
tools:context=".DisplayMessageActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView9"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="TextView"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textView8" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView1"
|
android:id="@+id/textView1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user