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

master
wanghao 1 week ago
parent 079422842c
commit 3d0e41f5b9

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

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -40,22 +39,22 @@
</LinearLayout> </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 <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="45dp" android:layout_height="45dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginTop="18dp" android:layout_marginTop="8dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
style="@style/text_title_style"
android:layout_width="90dp"
android:layout_height="match_parent"
android:text="输入编号:" />
<EditText <EditText
android:id="@+id/editTextNumber" android:id="@+id/editTextNumber"
@ -63,17 +62,21 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:hint="输入4位数字" android:hint="输入/读取数据"
android:inputType="number"
android:maxLength="4"
/>
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> </LinearLayout>
<Button <Button
android:id="@+id/button_epc_write" android:id="@+id/button_epc_write"
style="@style/button_submit" style="@style/button_submit"
@ -106,6 +109,7 @@
</LinearLayout> </LinearLayout>
<Button <Button
android:id="@+id/button_epc_san" android:id="@+id/button_epc_san"
style="@style/button_submit" style="@style/button_submit"

Loading…
Cancel
Save