На ПК — имя устройства Bluetooth (протокол RFCOMM TDI), а также идентификатор службы RFCOMM предполагает, что USB-ключ является устройством последовательной связи, как и модуль HC-05, который я использую.
Я могу выполнить сопряжение и подключить свой мобильный телефон Android к ПК с его собственными настройками, передавать файлы, и т. д. То же самое и с наушниками Bluetooth. USB-ключ Bluetooth 5.0 отлично подходит для этого.
На Android у меня тот же код для подключения к Bluetooth, который работает с HC-05:
Код: Выделить всё
private static final UUID CONNECTION_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
static boolean connect(BluetoothDevice device) {
try{
if(btAdapter == null) {
//AlertMessage.show("Alert!", "Bluetooth Adapter not found...", true);
Toast.makeText(CurrentContext.get(), "Bluetooth Adapter not found...", Toast.LENGTH_LONG).show();
return false;
}
else if(!btAdapter.isEnabled()) {
//AlertMessage.show("Alert!", "Bluetooth Adapter is not enabled...", true);
Toast.makeText(CurrentContext.get(), "Bluetooth Adapter is not enabled...", Toast.LENGTH_LONG).show();
return false;
}
if(btSocket != null && btSocket.isConnected()) {
if(btDevice == null) {
//AlertMessage.show("Alert!", "Bluetooth Device could not be found...", true);
Toast.makeText(CurrentContext.get(), "Bluetooth Device could not be found...", Toast.LENGTH_LONG).show();
return false;
}
else {
//AlertMessage.show("Alert!", "Already connected to: " + btDevice.getName(), true);
Toast.makeText(CurrentContext.get(), "Already connected to: " + btDevice.getName(), Toast.LENGTH_LONG).show();
return false;
}
}
Toast.makeText(CurrentContext.get(), "Connecting. Please wait...", Toast.LENGTH_LONG);
btDevice = device;
if(btDevice == null) {
//AlertMessage.show("Alert!", "Bluetooth Device could not be found...", true);
Toast.makeText(CurrentContext.get(), "Bluetooth Device could not be found...", Toast.LENGTH_LONG).show();
return false;
}
btSocket = btDevice.createRfcommSocketToServiceRecord(CONNECTION_UUID);
if(btSocket == null) {
//AlertMessage.show("Alert!", "Bluetooth Socket could not be found...", true);
Toast.makeText(CurrentContext.get(), "Bluetooth Socket could not be found...", Toast.LENGTH_LONG).show();
return false;
}
btAdapter.cancelDiscovery();
btSocket.connect();
mmInputStream = new DataInputStream(btSocket.getInputStream());
beginInputStreamListener();
}catch(Exception e){
e.printStackTrace();
//AlertMessage.show("Alert!", "There was an unresolved problem...", true);
Toast.makeText(CurrentContext.get(), "Could not connect to: " + device.getName(), Toast.LENGTH_LONG).show();
reset();
return false;
}
Toast.makeText(CurrentContext.get(), "Connected to: " + btDevice.getName(), Toast.LENGTH_LONG).show();
return true;
}
Мне предложили изменить UUID на соответствующий ключ Bluetooth, но я не могу найти UUID . Я попробовал использовать команду PowerShell Get-PnpDeviceProperty -InstanceId "YOUR_DEVICE_INSTANCE_ID" | Where-Object { $_.KeyName -match 'Service' , но он возвращает RFCOMM, как упоминалось ранее, предполагая, что это тот же протокол, что и HC-05. Тем не менее, это просто не работает. UUID должен быть одинаковым.
Цель состоит в том, чтобы отправлять данные туда и обратно с помощью моей собственной программы на ПК через последовательную связь, чтобы имитировать последовательную связь модуля HC-05 на Arduino. .
Подробнее здесь: https://stackoverflow.com/questions/791 ... -bluetooth