写入字段也能读取别的标签

master
wanghao 1 week ago
parent 079422842c
commit 3d0e41f5b9

@ -30,7 +30,7 @@ public class MainActivity2 extends BaseActivity implements IAsynchronousMessage
@BindView(R.id.san_epc_code)
TextView sanEpcCode;
private long exitTime;//退出记时
private boolean readType;
private String readType = "1";
private String targetTid = null;
@SuppressLint("HandlerLeak")
private Handler handler = new Handler() {
@ -38,16 +38,23 @@ public class MainActivity2 extends BaseActivity implements IAsynchronousMessage
public void handleMessage(Message msg) {
super.handleMessage(msg);
playSound();
if (readType) {//扫描到要写入的标签
EPCModel epcModel = (EPCModel) msg.obj;
String newCode = ASCIIUtil.hex2Str(epcModel._EPC);
switch (readType) {
case "1":
targetTid = epcModel._TID;
sanRedlyTag.setText(targetTid);
Log.e("TAG", "TID读取成功" + targetTid);
} else {
EPCModel epcModel = (EPCModel) msg.obj;
String newCode = ASCIIUtil.hex2Str(epcModel._EPC);
break;
case "2":
editTextNumber.setText(newCode.trim());
break;
case "3":
Log.e("TAG", "EPC读取成功" + epcModel._EPC);
sanEpcCode.setText(newCode);
break;
}
@ -61,20 +68,32 @@ public class MainActivity2 extends BaseActivity implements IAsynchronousMessage
ButterKnife.bind(this);
}
@OnClick({R.id.button_san_tag, R.id.button_epc_write, R.id.button_epc_san, R.id.button_clera_view})
@OnClick({R.id.button_san_tag, R.id.button_san_tag2, R.id.button_epc_write, R.id.button_epc_san, R.id.button_clera_view})
public void onClick(View view) {
switch (view.getId()) {
case R.id.button_san_tag:
readType = true;
readType = "1";
UHFReader._Tag6C.GetEPC_TID(1, 1);
break;
case R.id.button_san_tag2:
readType = "2";
if (targetTid == null) {
Toast.makeText(this, "先读取待写入标签", Toast.LENGTH_SHORT).show();
return;
}
UHFReader._Tag6C.GetEPC_MatchTID(1, 1,targetTid);
break;
case R.id.button_epc_write:
if (targetTid == null) {
Toast.makeText(this, "先读取待写入标签", Toast.LENGTH_SHORT).show();
return;
}
String tag = editTextNumber.getText().toString();
if (tag.isEmpty()) return;
if (tag.length() != 4) {
Toast.makeText(this, "输入长度限制位4位", Toast.LENGTH_SHORT).show();
}
String asciiData = "2020202020202054" + ASCIIUtil.str2Hex(tag);
String asciiData = "20202020202020" + ASCIIUtil.str2Hex(tag);
int writeResult = UHFReader._Tag6C.WriteEPC_MatchTID(1, asciiData, targetTid, 0);
Toast.makeText(this, writeResult == 0 ? "写入成功,点击下方扫描进行验证" : "写入失败", Toast.LENGTH_SHORT).show();
break;
@ -84,7 +103,7 @@ public class MainActivity2 extends BaseActivity implements IAsynchronousMessage
sanEpcCode.setText(null);
break;
case R.id.button_epc_san:
readType = false;
readType = "3";
UHFReader._Tag6C.GetEPC_TID(1, 1);
break;
}

@ -1,6 +1,5 @@
<?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"
@ -40,22 +39,22 @@
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="18dp"
android:text="待写入信息"
android:textColor="@color/blue" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="18dp"
android:layout_marginTop="8dp"
android:layout_marginRight="5dp"
android:orientation="horizontal">
<TextView
style="@style/text_title_style"
android:layout_width="90dp"
android:layout_height="match_parent"
android:text="输入编号:" />
<EditText
android:id="@+id/editTextNumber"
@ -63,17 +62,21 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:hint="输入4位数字"
android:inputType="number"
android:maxLength="4"
/>
android:hint="输入/读取数据"
android:maxLength="6" />
<Button
android:id="@+id/button_san_tag2"
style="@style/button_submit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="读取" />
</LinearLayout>
<Button
android:id="@+id/button_epc_write"
style="@style/button_submit"
@ -106,6 +109,7 @@
</LinearLayout>
<Button
android:id="@+id/button_epc_san"
style="@style/button_submit"

Loading…
Cancel
Save