You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.5 KiB
Java
82 lines
2.5 KiB
Java
package com.example.writeepc.base;
|
|
|
|
import android.media.MediaPlayer;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import com.handheld.uhfr.UHFRManager;
|
|
import com.uhf.api.cls.Reader;
|
|
|
|
import cn.pda.serialport.Tools;
|
|
|
|
public class BaseActivity extends AppCompatActivity {
|
|
public UHFRManager uhfrManager;
|
|
public byte[] accesspwd;
|
|
public short timeOut = 2000;
|
|
public MediaPlayer music;
|
|
|
|
@Override
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
}
|
|
|
|
public void initUHFRManager() {
|
|
uhfrManager = UHFRManager.getInstance();
|
|
uhfrManager.setGen2session(false);
|
|
uhfrManager.setPower(22,22);
|
|
accesspwd = Tools.HexString2Bytes("00000000");
|
|
music = MediaPlayer.create(this, com.example.writeepc.R.raw.msg);
|
|
// int[] power = uhfrManager.getPower();
|
|
// Log.e("TAG", "initUHFRManager:" + power[0]);
|
|
// Log.e("TAG", "initUHFRManager:" + power[1]);
|
|
}
|
|
|
|
|
|
// 1- 读取TID
|
|
public void readTid() {
|
|
byte[] rdata = new byte[12];
|
|
Reader.READER_ERR readerErr = uhfrManager.getTagData(2, 0, 6, rdata, accesspwd, timeOut);
|
|
Log.e("TAG", "readTid:" + readerErr.name());
|
|
if (readerErr == Reader.READER_ERR.MT_OK_ERR) {
|
|
music.start();
|
|
readTidReault(true, Tools.Bytes2HexString(rdata, 12),rdata);
|
|
} else {
|
|
Toast.makeText(this, "读取失败", Toast.LENGTH_SHORT).show();
|
|
readTidReault(false, null, null);
|
|
}
|
|
|
|
}
|
|
// 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);
|
|
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) {
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
if (uhfrManager!=null){
|
|
uhfrManager.close();
|
|
uhfrManager=null;
|
|
}
|
|
|
|
}
|
|
}
|