Browse Source

料仓

master
NXX 1 year ago
parent
commit
b5af85f66e
8 changed files with 171 additions and 96 deletions
  1. +7
    -2
      app/src/main/AndroidManifest.xml
  2. +50
    -86
      app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java
  3. +34
    -0
      app/src/main/java/com/example/bpa/view/fragment/setting/Fragment_lcparameter.java
  4. +16
    -0
      app/src/main/java/com/example/bpa/view/fragment/setting/systemparameter.java
  5. +1
    -7
      app/src/main/res/drawable/settingbutton.xml
  6. +4
    -1
      app/src/main/res/layout/datatab/values/strings.xml
  7. +11
    -0
      app/src/main/res/layout/from/layout/activity_systemparameter.xml
  8. +48
    -0
      app/src/main/res/layout/from/layout/fragment_lcparameter.xml

+ 7
- 2
app/src/main/AndroidManifest.xml View File

@@ -8,16 +8,21 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


<application
android:name=".app.ICSApp"
android:allowBackup="true"
android:icon="@mipmap/ncd"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
tools:targetApi="31">
<activity
android:name=".view.fragment.setting.Fragment_lcparameter"
android:exported="false" />
<activity
android:name=".view.fragment.setting.systemparameter"
android:exported="false" />
<activity
android:name=".view.from.add_pf_activity"
android:exported="false" />


+ 50
- 86
app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java View File

@@ -2,7 +2,11 @@ package com.example.bpa.view.fragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.util.Log;
@@ -12,35 +16,38 @@ import android.view.ViewGroup;
import android.widget.Button;

import com.example.bpa.Model.IMessageLogNotify;
import com.example.bpa.Model.IReadCallBack;
import com.example.bpa.Model.IThread;
import com.example.bpa.R;
import com.example.bpa.app.ModbusTcpServer;
import com.example.bpa.helper.MessageLog;
import com.example.bpa.helper.ThreadManager;
import com.example.bpa.view.fragment.setting.Fragment_lcparameter;

/**
* 系统设置界面
*/
public class SystemSetFragment extends Fragment {
public class SystemSetFragment extends Fragment implements View.OnClickListener {

private Button ConBut;
private Button ReadBut;
private Button WriteBut;

View view;
private Button btn_system_set;

private Button btn_lc_set;

private Fragment lcparameter;
private Fragment SelectFragment;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_system_set, container, false);
Init(view);
view = inflater.inflate(R.layout.fragment_system_set, container,false);
Init();
initEvent();
return view;
}

private void Init(View tempView) {
ConBut = tempView.findViewById(R.id.ConnectDevice);
ReadBut = tempView.findViewById(R.id.ReadData);
WriteBut = tempView.findViewById(R.id.WriteData);
}

private void Init() {
lcparameter = new Fragment_lcparameter();
btn_system_set = view.findViewById(R.id.stparameter);
btn_lc_set = view.findViewById(R.id.lcparameter);
MessageLog.MsgNotify = new IMessageLogNotify() {
@Override
public void ErrorMsg(String msg) {
@@ -58,83 +65,40 @@ public class SystemSetFragment extends Fragment {
}
};

ConBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
ModbusTcpServer.get().Connect("192.168.1.9", 502);
}
}).start();
}
});

ReadBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

ThreadManager.Get().StartLong("数据读取监听", true, new IThread() {
@Override
public void Run() throws InterruptedException {
ModbusTcpServer.get().ReadShort("0", 3, new IReadCallBack<short[]>() {
@Override
public void onSuccess(short[] shorts) {
for (int i = 0; i < shorts.length; i++) {
MessageLog.ShowInfo("Shorts[" + i + "]=" + shorts[i]);
}
}
});

ModbusTcpServer.get().ReadFloat("10", 3, new IReadCallBack<float[]>() {
@Override
public void onSuccess(float[] floats) {
for (int i = 0; i < floats.length; i++) {
MessageLog.ShowInfo("Floats[" + i + "]=" + floats[i]);
}
}
});

ModbusTcpServer.get().ReadBool("0", 3, new IReadCallBack<boolean[]>() {
@Override
public void onSuccess(boolean[] booleans) {
for (int i = 0; i < booleans.length; i++) {
MessageLog.ShowInfo("Booleans[" + i + "]=" + booleans[i]);
}
}
});
Thread.sleep(3000);
}

@Override
public void RunComplete() throws InterruptedException {
MessageLog.ShowInfo("线程执行完成");
}
});
}

private void initEvent(){
btn_system_set.setOnClickListener(this);
btn_lc_set.setOnClickListener(this);
}

}
});

WriteBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ThreadManager.Get().Stop("数据读取监听");
ModbusTcpServer.get().WriteBool("0", true);
ModbusTcpServer.get().WriteBool("1", true);
ModbusTcpServer.get().WriteBool("2", true);

ModbusTcpServer.get().WriteShort("0", (short) 10);
ModbusTcpServer.get().WriteShort("1", (short) 20);
ModbusTcpServer.get().WriteShort("2", (short) 30);

ModbusTcpServer.get().WriteFloat("10", 10.10f);
ModbusTcpServer.get().WriteFloat("12", 20.20f);
ModbusTcpServer.get().WriteFloat("14", 30.30f);
}
});
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.stparameter://返回按钮
Log.d("页面", "onClick: ");
break;
case R.id.lcparameter://返回按钮
ShowFragment(lcparameter);
break;


}
}


public void ShowFragment(Fragment fragment)
{
FragmentManager manager = getChildFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
if(SelectFragment!=null)
{
transaction.remove(SelectFragment);
}
transaction.add(R.id.fragment_container, fragment);
transaction.commit();
SelectFragment=fragment;
}
}

+ 34
- 0
app/src/main/java/com/example/bpa/view/fragment/setting/Fragment_lcparameter.java View File

@@ -0,0 +1,34 @@
package com.example.bpa.view.fragment.setting;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.bpa.R;

public class Fragment_lcparameter extends Fragment {

private View view;
LinearLayout mylayout;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_system_capabilities, container,false);
Init();
return view;

}

private void Init(){
mylayout = view.findViewById(R.id.lcparameter_layout);
mylayout.setBackgroundColor(Color.TRANSPARENT);
}
}

+ 16
- 0
app/src/main/java/com/example/bpa/view/fragment/setting/systemparameter.java View File

@@ -0,0 +1,16 @@
package com.example.bpa.view.fragment.setting;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.example.bpa.R;

public class systemparameter extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_systemparameter);
}
}

+ 1
- 7
app/src/main/res/drawable/settingbutton.xml View File

@@ -18,7 +18,6 @@
android:width="2dp"
android:color="#FF4081" />
</shape>
<color android:color="#CCCCCC"/>
</item>

<!-- Button 正常状态下的样式 -->
@@ -44,12 +43,7 @@
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<shadow
android:radius="5dp"
android:dx="0"
android:dy="2"
android:color="#800000000" />
</shape>
<color android:color="@color/white"/>
</item>
</selector>

+ 4
- 1
app/src/main/res/layout/datatab/values/strings.xml View File

@@ -1 +1,4 @@
<resources></resources>
<resources>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

+ 11
- 0
app/src/main/res/layout/from/layout/activity_systemparameter.xml View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@mipmap/dpbj"
tools:context=".view.from.add_pf_activity">

</LinearLayout>

+ 48
- 0
app/src/main/res/layout/from/layout/fragment_lcparameter.xml View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/lcparameter_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"

tools:context=".view.from.add_pf_activity">
<TableLayout
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp">
<TextView
android:layout_marginRight="5dp"
android:text="通道一校准"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:hint="校准值"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="校准"
android:layout_marginRight="40dp"/>

<TextView
android:layout_marginRight="5dp"
android:text="通道二校准"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:hint="校准值"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="校准开关"/>
</TableRow>
</TableLayout>
</LinearLayout>

Loading…
Cancel
Save