后台拼接字符
parent
073acc35c2
commit
079422842c
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<litepal>
|
<litepal>
|
||||||
<dbname value="write_tag_info" />
|
<dbname value="write_tag_info" />
|
||||||
<version value="1" />
|
<version value="2" />
|
||||||
<list>
|
<list>
|
||||||
<mapping class="com.example.xiebiaoqian.entity.WriteInfo"></mapping>
|
<mapping class="com.example.xiebiaoqian.entity.WriteInfo"></mapping>
|
||||||
</list>
|
</list>
|
||||||
|
|||||||
@ -0,0 +1,136 @@
|
|||||||
|
package com.example.xiebiaoqian;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.xiebiaoqian.base.BaseActivity;
|
||||||
|
import com.example.xiebiaoqian.utils.ASCIIUtil;
|
||||||
|
import com.pda.rfid.EPCModel;
|
||||||
|
import com.pda.rfid.IAsynchronousMessage;
|
||||||
|
import com.pda.rfid.uhf.UHFReader;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
public class MainActivity2 extends BaseActivity implements IAsynchronousMessage{
|
||||||
|
|
||||||
|
@BindView(R.id.san_redly_tag)
|
||||||
|
TextView sanRedlyTag;
|
||||||
|
@BindView(R.id.editTextNumber)
|
||||||
|
EditText editTextNumber;
|
||||||
|
@BindView(R.id.san_epc_code)
|
||||||
|
TextView sanEpcCode;
|
||||||
|
private long exitTime;//退出记时
|
||||||
|
private boolean readType;
|
||||||
|
private String targetTid = null;
|
||||||
|
@SuppressLint("HandlerLeak")
|
||||||
|
private Handler handler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
playSound();
|
||||||
|
if (readType) {//扫描到要写入的标签
|
||||||
|
EPCModel epcModel = (EPCModel) msg.obj;
|
||||||
|
targetTid = epcModel._TID;
|
||||||
|
sanRedlyTag.setText(targetTid);
|
||||||
|
Log.e("TAG", "TID读取成功" + targetTid);
|
||||||
|
} else {
|
||||||
|
EPCModel epcModel = (EPCModel) msg.obj;
|
||||||
|
String newCode = ASCIIUtil.hex2Str(epcModel._EPC);
|
||||||
|
Log.e("TAG", "EPC读取成功" + epcModel._EPC);
|
||||||
|
sanEpcCode.setText(newCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main2);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.button_san_tag, 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;
|
||||||
|
UHFReader._Tag6C.GetEPC_TID(1, 1);
|
||||||
|
break;
|
||||||
|
case R.id.button_epc_write:
|
||||||
|
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);
|
||||||
|
int writeResult = UHFReader._Tag6C.WriteEPC_MatchTID(1, asciiData, targetTid, 0);
|
||||||
|
Toast.makeText(this, writeResult == 0 ? "写入成功,点击下方扫描进行验证" : "写入失败", Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
case R.id.button_clera_view:
|
||||||
|
editTextNumber.setText(null);
|
||||||
|
sanRedlyTag.setText(null);
|
||||||
|
sanEpcCode.setText(null);
|
||||||
|
break;
|
||||||
|
case R.id.button_epc_san:
|
||||||
|
readType = false;
|
||||||
|
UHFReader._Tag6C.GetEPC_TID(1, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化驱动
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
UHFReader._Config.OpenConnect(false, this);
|
||||||
|
UHFReader._Config.SetANTPowerParam(2, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭驱动
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
UHFReader._Config.Stop();
|
||||||
|
UHFReader._Config.CloseConnect();
|
||||||
|
handler = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//读取到标签
|
||||||
|
@Override
|
||||||
|
public void OutPutEPC(EPCModel epcModel) {
|
||||||
|
UHFReader._Config.Stop();
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.obj = epcModel;
|
||||||
|
handler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == 4) {
|
||||||
|
|
||||||
|
if ((System.currentTimeMillis() - exitTime) > 2000) {
|
||||||
|
//弹出提示,可以有多种方式
|
||||||
|
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
|
||||||
|
exitTime = System.currentTimeMillis();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
<?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"
|
||||||
|
tools:context=".MainActivity2">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/title_style"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="55dp"
|
||||||
|
android:text="标签写入" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="45dp"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/san_redly_tag"
|
||||||
|
style="@style/text_info_style"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/white"
|
||||||
|
android:hint="读取目标标签"
|
||||||
|
android:singleLine="true" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_san_tag"
|
||||||
|
style="@style/button_submit"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="读取" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="45dp"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginTop="18dp"
|
||||||
|
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"
|
||||||
|
style="@style/text_info_style"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:hint="输入4位数字"
|
||||||
|
android:inputType="number"
|
||||||
|
android:maxLength="4"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_epc_write"
|
||||||
|
style="@style/button_submit"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="18dp"
|
||||||
|
android:text="写入" />
|
||||||
|
|
||||||
|
<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_marginRight="5dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/san_epc_code"
|
||||||
|
style="@style/text_info_style"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/white" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_epc_san"
|
||||||
|
style="@style/button_submit"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="18dp"
|
||||||
|
android:text="扫描" />
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_clera_view"
|
||||||
|
style="@style/button_submit_yellow"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="45dp"
|
||||||
|
android:layout_margin="20dp"
|
||||||
|
android:text="清空" />
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Reference in New Issue