Ошибка при создании RFID-считывателя Honeywell IH45Android

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Гость
 Ошибка при создании RFID-считывателя Honeywell IH45

Сообщение Гость »

В настоящее время я разрабатываю приложение для Android, которое позволяет подключаться к RFID-меткам и считывать их.
На данный момент соединение установлено успешно, но я столкнулся с проблемой при создании считывателя. вызвав метод CreateReader, предоставленный Honeywell.
В приложении вы найдете журналы, которые я получил, когда нажал кнопку для создания средства чтения, а также код моего приложения:

Код: Выделить всё

package com.example.projetrfid;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.honeywell.rfidservice.EventListener;
import com.honeywell.rfidservice.RfidManager;
import com.honeywell.rfidservice.TriggerMode;
import com.honeywell.rfidservice.rfid.Gen2;
import com.honeywell.rfidservice.rfid.RfidReader;
import com.honeywell.rfidservice.rfid.RfidReaderException;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
private static final String LOG = "[IH45]";
private final String READER_STATUS = "READER_STATUS";
private final String TRIGGER_STATUS = "TRIGGER_STATUS";
private final String WRITE_TAG_STATUS = "WRITE_TAG_STATUS";
private final String BATTERY_STATUS = "BATTERY_STATUS";
private final String TAG = "TAG";
private final String TAGS = "TAGS";
private static RfidManager mRfidMgr;
private static RfidReader mRfidReader;
private static BluetoothDevice mDevice;
private static final ArrayList cacheTags = new ArrayList();
private static boolean isSingleRead = false;
private static boolean isReading = false;
private static final ArrayList mDevices = new ArrayList();
private static BluetoothLeScanner scanner;
private static Handler handler;
private static final int BLUETOOTH_SCAN = 111;
private static final int BLUETOOTH_CONNECT = 112;
private static final int REQUEST_CODE_LOCATION_1 = 123; // Valeur arbitraire, peut être n'importe quel entier
private static final int REQUEST_CODE_LOCATION_2 = 124; // Valeur arbitraire, peut être n'importe quel entier
private static final int REQUEST_CODE_LOCATION_3 = 125; // Valeur arbitraire, peut être n'importe quel entier
private static final int REQUEST_CODE_LOCATION_4 = 126; // Valeur arbitraire, peut être n'importe quel entier
private static final int REQUEST_CODE_BLUETOOTH_CONNECT = 127;  // Valeur arbitraire, peut être n'importe quel entier
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
private RFIDConnectionManager mMyApplication;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button BTN_CONNECT_ = findViewById(R.id.BTN_CONNECT);
Button BTN_CREARE_READER_ = findViewById(R.id.CREATE_READER);
Context tmpContext = getApplicationContext();
handler = new Handler(Looper.getMainLooper());
// Vérification de la permission ACCESS_FINE_LOCATION
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// Demande de permission ACCESS_FINE_LOCATION à l'utilisateur
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_LOCATION_1);
}
// Vérification de la permission BLUETOOTH_ADMIN
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED) {
// Demande de permission BLUETOOTH_ADMIN à l'utilisateur
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH_ADMIN}, REQUEST_CODE_LOCATION_2);
}
// Vérification de la permission BLUETOOTH
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
// Demande de permission BLUETOOTH à l'utilisateur
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH}, REQUEST_CODE_LOCATION_3);
}
// Vérification de la permission WRITE_EXTERNAL_STORAGE
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Demande de permission WRITE_EXTERNAL_STORAGE à l'utilisateur
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_LOCATION_4);
}
// Vérification de la permission WRITE_EXTERNAL_STORAGE
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
// Demande de permission WRITE_EXTERNAL_STORAGE à l'utilisateur
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH_CONNECT}, REQUEST_CODE_BLUETOOTH_CONNECT);
}

//        if (mRfidMgr==null){Toast.makeText(getApplicationContext(), "avant mRfidMgr==null", Toast.LENGTH_SHORT).show();}else{Toast.makeText(getApplicationContext(), "avant mRfidMgr!=null", Toast.LENGTH_SHORT).show();}
init();
mRfidMgr = RfidManager.getInstance(this);
//        if (mRfidMgr==null){Toast.makeText(getApplicationContext(), "apres mRfidMgr==null", Toast.LENGTH_SHORT).show();}else{Toast.makeText(getApplicationContext(), "apres mRfidMgr!=null", Toast.LENGTH_SHORT).show();}
BTN_CONNECT_.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

// Vérification des autorisations avant de tenter la connexion
checkPermissions();
}
});
BTN_CREARE_READER_.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mRfidMgr==null){Toast.makeText(getApplicationContext(), "apres mRfidMgr==null", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "apres mRfidMgr!=null", Toast.LENGTH_SHORT).show();
mRfidMgr.createReader();
}

}
});

}

private void checkPermissions() {
// Vérification de toutes les autorisations nécessaires
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this,  Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
// Demande de toutes les autorisations nécessaires
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.BLUETOOTH_CONNECT
},
BLUETOOTH_CONNECT); // Utilisez une constante pour le code de demande de permission
} else {
// Toutes les autorisations sont accordées, connectez-vous
//            Toast.makeText(getApplicationContext(), "connect", Toast.LENGTH_SHORT).show();
connect("BLE");
}
}

public void connect(final String name) {
//        Toast.makeText(getApplicationContext(), "je suis dans connect", Toast.LENGTH_SHORT).show();
try {
//            Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
mDevices.clear();

if (mRfidMgr != null && mRfidMgr.isConnected()) {
doDisconnect();
}

scanner = mBluetoothAdapter.getBluetoothLeScanner();
if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.BLUETOOTH_SCAN}, BLUETOOTH_SCAN);
Log.d("MainActivity", "PAS DE PERMISSION BLUETOOTH_CONNECT");
} else {
//                Toast.makeText(getApplicationContext(), "startScan", Toast.LENGTH_SHORT).show();
scanner.startScan(scanCallback);
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.BLUETOOTH_SCAN}, BLUETOOTH_SCAN);
Log.d("MainActivity", "PAS DE PERMISSION BLUETOOTH_CONNECT");
} else {
scanner.stopScan(scanCallback);
}
Toast.makeText(getApplicationContext(), "Failed to connect reader...Please make sure your reader is power on.", Toast.LENGTH_SHORT).show();

}
}, 8 * 1000);
}
} catch (Exception err) {
Toast.makeText(getApplicationContext(), "Exception err: "+err, Toast.LENGTH_SHORT).show();
}
}

private void doConnect() {
//        Toast.makeText(getApplicationContext(), "7", Toast.LENGTH_SHORT).show();
if (mRfidMgr != null &&  mRfidMgr.isConnected()) {
doDisconnect();
}

if (mRfidMgr == null) {
//            Toast.makeText(getApplicationContext(), "8", Toast.LENGTH_SHORT).show();
init();
}

if (mDevice != null) {

handler.postDelayed(new Runnable() {
@Override
public void run() {
//                    Toast.makeText(getApplicationContext(), "connect"+mDevice.getAddress(), Toast.LENGTH_SHORT).show();
mRfidMgr.connect(mDevice.getAddress());
}
}, 3 * 1000);
}
}

private void doDisconnect() {
if (mRfidMgr != null) {
mRfidMgr.removeEventListener(mEventListener);
mRfidMgr.disconnect();

mRfidMgr = null;
}

if (mRfidReader != null) {
//            mRfidReader.removeOnTagReadListener(dataListener);

mRfidReader = null;
}
}

private final ScanCallback scanCallback = new ScanCallback() {

@Override
public void onScanResult(int callbackType, ScanResult result) {
//            Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_SHORT).show();
BluetoothDevice device = result.getDevice();

if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.BLUETOOTH_SCAN}, BLUETOOTH_CONNECT);
//                Toast.makeText(getApplicationContext(), "PAS DE PERMISSION BLUETOOTH_CONNECT", Toast.LENGTH_SHORT).show();
Log.d("MainActivity", "PAS DE PERMISSION BLUETOOTH_CONNECT");
} else {
if (device.getName() != null && !device.getName().isEmpty()) {
//                    Toast.makeText(getApplicationContext(), "5: "+device.getName(), Toast.LENGTH_SHORT).show();
boolean newDevice = true;

for (BluetoothDevice info : mDevices) {
if (device.getAddress().equals(info.getAddress())) {
newDevice = false;
}
}

if (newDevice &&  device.getName().equals("IH45")) {
//                        Toast.makeText(getApplicationContext(), "6: "+device.getAddress(), Toast.LENGTH_SHORT).show();
mDevices.add(device);

mDevice = device;

scanner.stopScan(scanCallback);

handler.removeCallbacksAndMessages(null);
//                        Toast.makeText(getApplicationContext(), "j'arrete le scan: "+device.getName(), Toast.LENGTH_SHORT).show();
doConnect();
}
}
}

}
};
private void init() {

mMyApplication = RFIDConnectionManager.getInstance();
RfidManager.create(this, new RfidManager.CreatedCallback() {
@Override
public void onCreated(RfidManager rfidManager) {
Log.d("MainActivity", "RfidManager created successfully.");
mRfidMgr = rfidManager;
if (mMyApplication != null) {
Log.e("MainActivity", "mMyApplication n'est pas null");
mMyApplication.setRfidMgr(rfidManager);
//                    Toast.makeText(getApplicationContext(), "setRfidManager(rfidManager)", Toast.LENGTH_SHORT).show();
//                    setRfidManager(rfidManager);
} else {
//                    Toast.makeText(getApplicationContext(), "mMyApplication = null dans onCreated dans init", Toast.LENGTH_SHORT).show();
// Gérer le cas où rfidConnectionManager est null
Log.e("MainActivity", "mMyApplication est null");
}
// mMyApplication.setRfidMgr(mRfidMgr);
mRfidMgr.addEventListener(mEventListener);

runOnUiThread(new Runnable() {
@Override
public void run() {
}
});

}
});
}
private final EventListener mEventListener = new EventListener() {
@Override
public void onDeviceConnected(Object o) {
mRfidMgr.createReader();
//            Toast.makeText(getApplicationContext(), "Failed to connect reader...Please make sure your reader is power on.", Toast.LENGTH_SHORT).show();
}

@Override
public void onDeviceDisconnected(Object o) {
mRfidReader = null;
}

@Override
public void onReaderCreated(boolean b, RfidReader rfidReader) {
if (rfidReader != null) {
Toast.makeText(getApplicationContext(), "onReaderCreated rfidReader != null", Toast.LENGTH_SHORT).show();
mRfidReader = rfidReader;
try {
mRfidReader.setSession(Gen2.Session.Session1);
} catch (RfidReaderException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "onReaderCreated err: "+e.getMessage(), Toast.LENGTH_SHORT).show();
}

}
}

@Override
public void onRfidTriggered(boolean state) {
}

@Override
public void onTriggerModeSwitched(TriggerMode triggerMode) {
}
};

public void setRfidManager(RfidManager rFidMng) {
mRfidMgr = rFidMng;
}

}
Когда я пытаюсь создать устройство чтения, я получаю объект RfidReader со значением null в методе onReaderCreated, и ниже приведены полученные мной журналы.
регистрирует ошибки:
honRfid onServicesDiscovered Статус службы: 0
BluetoothGatt setCharacteristicNotification() - uuid: e093f3b5-00a3-a9e5-9eca-40046e0edc24 Enable: true
BluetoothGatt setCharacteristicNotification() - uuid: e093f3b5-00a3-a9e5-9eca-40026e0edc24 включить: true
BluetoothGatt setCharacteristicNotification() - uuid: e093f3b5-00a3-a9e5-9eca-40036e0edc24 включить: true
Доступ к скрытому полю Landroid/bluetooth/BluetoothGatt;->mDeviceBusy:Ljava/lang/Boolean; (max-target-r, отражение, отказ)
Доступ к скрытому полю Landroid/bluetooth/BluetoothGatt;->mDeviceBusy:Ljava/lang/Boolean; (max-target-r, отражение, отказ)
java.lang.NoSuchFieldException: нет поля mDeviceBusy в классе Landroid/bluetooth/BluetoothGatt; (объявление «android.bluetooth.BluetoothGatt» появляется в /system/framework/framework.jar)
RfidService не удалось определить тип модуля.
RfidService com.example.projetrfid
I onReaderCreated() succ=false reader=null

Источник: https://stackoverflow.com/questions/781 ... ywell-ih45
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Чтение NFC и запись с помощью считывателя RFID
    Anonymous » » в форуме Android
    0 Ответы
    12 Просмотры
    Последнее сообщение Anonymous
  • Извлечение данных из RFID-считывателя
    Anonymous » » в форуме C#
    0 Ответы
    21 Просмотры
    Последнее сообщение Anonymous
  • Ошибка интеграции Zebra RFID: com.zebra.rfid.api3.OperationFailureException
    Anonymous » » в форуме Android
    0 Ответы
    17 Просмотры
    Последнее сообщение Anonymous
  • Подключенное устройство не поддерживает RFID, ฺ и штрих -код или Zebra RFID SDK не инициализирован в Android 14
    Anonymous » » в форуме Android
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous
  • Приложение Honeywell EDA56 для отслеживания запасов
    Anonymous » » в форуме Android
    0 Ответы
    8 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Android»