增加 读取user

master
wanghao 2 weeks ago
parent 6142ac0114
commit a8a3b5da1a

@ -17,19 +17,25 @@
android:theme="@style/Theme.WriteEpc"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".WriteUserActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings" />
<activity
<activity
android:name=".SettingsActivity2"
android:exported="false"/>
android:exported="false" />
<activity
android:name=".IntentSelectActivity"
android:exported="false"
android:theme="@style/traceActivityStyle" />
<activity
android:name=".ShuangqianActivity2"
android:exported="false"
@ -39,6 +45,7 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@ -46,16 +53,11 @@
android:name=".HomeActivity2"
android:exported="true"
android:label="轮胎信息追溯">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShuangqianActivity"
android:exported="true"></activity>
android:exported="true" />
<receiver
android:name=".broadcast.MyScannerReceiver"
@ -89,11 +91,13 @@
<activity
android:name=".MainActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.MAIN" /> -->
<!-- <category android:name="android.intent.category.LAUNCHER" /> -->
<!-- </intent-filter> -->
</activity>
</application>

@ -12,6 +12,36 @@ public class InfoData extends BaseObservable {
private String readTId;
private byte[] tidBytes;
private String writeUser;
private String readUser;
private int readLenth=4;
public int getReadLenth() {
return readLenth;
}
public void setReadLenth(int readLenth) {
this.readLenth = readLenth;
}
public String getWriteUser() {
return writeUser;
}
public void setWriteUser(String writeUser) {
this.writeUser = writeUser;
notifyChange();
}
public String getReadUser() {
return readUser;
}
public void setReadUser(String readUser) {
this.readUser = readUser;
notifyChange();
}
public byte[] getTidBytes() {
return tidBytes;
}

@ -0,0 +1,62 @@
package com.example.writeepc;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.databinding.DataBindingUtil;
import com.example.writeepc.base.BaseActivity;
import com.example.writeepc.databinding.ActivityWriteUserBinding;
public class WriteUserActivity extends BaseActivity {
private ActivityWriteUserBinding binding;
private InfoData infoData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user);
infoData=new InfoData();
binding.setData(infoData);
initUHFRManager(5);
}
@Override
protected void readTidReault(boolean readState, String result, byte[] rdata) {
Log.e("TAG", "readTidReault:" + result);
infoData.setReadUser(ASCIIUtil.hex2Str(result));
}
public void writeUser(View view) {
}
public void readUser(View view) {
int lenth = Integer.parseInt(binding.userReadLenth.getSelectedItem().toString());
readUser(lenth);
}
public void userClearView(View view) {
infoData.setWriteUser(null);
infoData.setReadUser(null);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (uhfrManager != null) {
uhfrManager.close();
uhfrManager = null;
}
}
}

@ -51,7 +51,14 @@ public class BaseActivity extends AppCompatActivity {
uhfrManager.setPower(30, 30);
accesspwd = Tools.HexString2Bytes("00000000");
music = MediaPlayer.create(this, com.example.writeepc.R.raw.msg);
}
public void initUHFRManager(int power) {
uhfrManager = UHFRManager.getInstance();
uhfrManager.setGen2session(false);
uhfrManager.setPower(power, power);
accesspwd = Tools.HexString2Bytes("00000000");
music = MediaPlayer.create(this, com.example.writeepc.R.raw.msg);
}
public void initUHFRManager1() {
@ -82,7 +89,8 @@ public class BaseActivity extends AppCompatActivity {
// 1- 读取EPC
public void readEPC(int lenth) {
byte[] rdata = new byte[lenth];
Reader.READER_ERR readerErr = uhfrManager.getTagData(1, 2, lenth / 2, rdata, accesspwd, timeOut);
Reader.READER_ERR readerErr =
uhfrManager.getTagData(1, 2, lenth / 2, rdata, accesspwd, timeOut);
Log.e("TAG", "readTid:" + readerErr.name());
if (readerErr == Reader.READER_ERR.MT_OK_ERR) {
music.start();
@ -94,6 +102,23 @@ public class BaseActivity extends AppCompatActivity {
}
// 3- 读取User
public void readUser(int lenth) {
byte[] rdata = new byte[lenth];
Reader.READER_ERR readerErr =
uhfrManager.getTagData(3, 0, lenth / 2, rdata, accesspwd, timeOut);
Log.e("TAG", "readTid:" + readerErr.name());
if (readerErr == Reader.READER_ERR.MT_OK_ERR) {
music.start();
readTidReault(true, Tools.Bytes2HexString(rdata, lenth), rdata);
} else {
Toast.makeText(this, "读取失败", Toast.LENGTH_SHORT).show();
readTidReault(false, null, null);
}
}
protected void readTidReault(boolean readState, String result, byte[] rdata) {
}

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="data"
type="com.example.writeepc.InfoData" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".WriteUserActivity">
<TextView
style="@style/info_text"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="center"
android:background="#6750A4"
android:letterSpacing="0.2"
android:text="User区读写"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="30dp"
android:orientation="horizontal">
<TextView
style="@style/info_text"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="读取长度:" />
<Spinner
android:id="@+id/user_read_lenth"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="center"
android:entries="@array/read_lenth"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="30dp"
android:orientation="horizontal">
<TextView
style="@style/info_text"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="写入数据:" />
<EditText
android:id="@+id/epc_view"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="center"
android:text="@={data.writeUser}" />
</LinearLayout>
<Button
style="@style/button_style"
android:layout_width="match_parent"
android:layout_height="55dp"
android:onClick="writeUser"
android:layout_marginTop="12dp"
android:text="写入数据" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
style="@style/info_text"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="user:" />
<TextView
style="@style/san_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dp"
android:minHeight="55dp"
android:text="@={data.readUser}" />
</LinearLayout>
<Button
style="@style/button_style"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="12dp"
android:onClick="readUser"
android:text="扫描验证" />
<Button
style="@style/button_style"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="12dp"
android:onClick="userClearView"
android:backgroundTint="#FFD600"
android:text="清空操作" />
</LinearLayout>
</layout>

@ -32,6 +32,23 @@
<item>33</item>
</string-array>
<string-array name="read_lenth">
<item>4</item>
<item>8</item>
<item>12</item>
<item>16</item>
<item>20</item>
<item>24</item>
<item>28</item>
<item>32</item>
<item>36</item>
<item>40</item>
<item>44</item>
<item>48</item>
<item>52</item>
<item>56</item>
<item>60</item>
</string-array>
<!-- Reply Preference -->
<string-array name="reply_entries">
<item>Reply</item>

@ -53,6 +53,7 @@
<item name="android:layout_marginEnd">20dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="button_style1">
<item name="android:textColor">@color/white</item>

Loading…
Cancel
Save