Java Bluecove Bluetooth-соединениеJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Java Bluecove Bluetooth-соединение

Сообщение Anonymous »

Я пытаюсь установить соединение Bluetooth между моим приложением JavaFX и устройством Bluetooth. Для этого я воспользовался примером bluetooth-java-client.
Здесь информация об устройстве Bluetooth:
Изображение

Проблема в том, что соединение устанавливается, но сразу же обрывается.< /p>
Сканирование работает хорошо и практически идентично примеру.
Я пытался открыть соединение двумя разными способами:
  • StreamConnection scConnection = (StreamConnection) Connector.open("btspp://" + strAddress + ":1");
  • L2CAPConnection scConnection = (L2CAPConnection) Connector.open("btl2cap://" + strAddress + ":1");
Как только соединение установлено, я открываю потоки, запускаю поток чтения и отправляю первый пакет:
  • RemoteDevice rdRemoteDevice = RemoteDevice.getRemoteDevice(scConnection);
    this.strDeviceName = rdRemoteDevice.getFriendlyName(false);
    this.isInputStream = new BufferedInputStream(scConnection.openInputStream());
    this.osOutputStream = scConnection.openOutputStream();
  • // I've implemented a sort of queue, one thread fill it and the other empties it
    Thread tReceiverThread = new Thread(new Runnable() {
    @Override
    public void run() {
    receiveBluetoothData();
    }
    });
    tReceiverThread.start();
    Thread tReaderThread = new Thread(new Runnable() {
    @Override
    public void run() {
    readMessagePoolData();
    }
    });
    tReaderThread.start();
  • try {
    sWriterSemaphore.acquire();

    bytLastSentPacket = createPacketToSend(eDataType, strPayload);
    Logger.getAnonymousLogger().log(Level.INFO, TAGS.BLUETOOTH + "Created packet " + ((char) eDataType.value) + " with payload '" + strPayload + "'");

    osOutputStream.write(bytLastSentPacket);
    osOutputStream.flush();

    /*
    Sometimes I see the following line in the logs but most of the time
    the connection drops before.
    */
    Logger.getAnonymousLogger().log(Level.INFO, TAGS.BLUETOOTH + "The packet " + Arrays.toString(bytLastSentPacket) + " has been sent to " + strDeviceName);
    } catch (IOException | InterruptedException e) {
    Logger.getAnonymousLogger().log(Level.SEVERE, TAGS.BLUETOOTH + "Error writing to " + strDeviceName + " output stream", e);
    }
Вот логи:
2024-10-08 09:18:53.337 [INFO ] [BLUETOOTH ] Starting device discovery...
2024-10-08 09:19:04.037 [INFO ] [BLUETOOTH ] New device discovered: [3481F4326C73 - HK_Star_175-005]
2024-10-08 09:19:04.346 [INFO ] [BLUETOOTH ] New device discovered: [3481F4326CB0 - HK_Star_2013001]
2024-10-08 09:19:04.448 [INFO ] [BLUETOOTH ] Device discovery completed
2024-10-08 09:19:53.421 [INFO ] [BLUETOOTH ] Ready to read messages from HK_Star_2013001
2024-10-08 09:19:53.466 [INFO ] [BLUETOOTH ] Created packet Y with payload ''
2024-10-08 09:19:53.480 [SEVERE ] [BLUETOOTH ] Error writing to HK_Star_2013001 output stream
java.io.IOException: Failed to write. [ 1 0 7 ] T r a n s p o r t e n d p o i n t i s n o t c o n n e c t e d < b r / > a t b l u e c o v e @ 2 . 1 . 1 / c o m . i n t e l . b l u e t o o t h . B l u e t o o t h S t a c k B l u e Z . c o n n e c t i o n R f W r i t e ( N a t i v e M e t h o d ) < b r / > a t b l u e c o v e @ 2 . 1 . 1 / c o m . i n t e l . b l u e t o o t h . B l u e t o o t h R F C o m m O u t p u t S t r e a m . w r i t e ( B l u e t o o t h R F C o m m O u t p u t S t r e a m . j a v a : 8 4 ) < b r / > a t j a v a . b a s e / j a v a . i o . O u t p u t S t r e a m . w r i t e ( O u t p u t S t r e a m . j a v a : 1 2 2 ) < b r / > a t c o m . m y c o m p a n y . m y p r o j e c t / c o m . m y c o m p a n y . m y p r o j e c t . u t i l s . b l u e t o o t h . B l u e t o o t h D e v i c e . s e n d B l u e t o o t h D a t a ( B l u e t o o t h D e v i c e . j a v a : 1 4 4 ) < b r / > a t c o m . m y c o m p a n y . m y p r o j e c t / c o m . m y c o m p a n y . m y p r o j e c t . u t i l s . b l u e t o o t h . B l u e t o o t h D e v i c e . & l t ; i n i t & g t ; ( B l u e t o o t h D e v i c e . j a v a : 9 4 ) < b r / > a t c o m . m y c o m p a n y . m y p r o j e c t / c o m . m y c o m p a n y . m y p r o j e c t . u t i l s . b l u e t o o t h . B l u e t o o t h H e l p e r . o p e n C o n n e c t i o n ( B l u e t o o t h H e l p e r . j a v a : 6 6 ) < b r / > a t c o m . m y c o m p a n y . m y p r o j e c t / c o m . m y c o m p a n y . m y p r o j e c t . c o n trollers.users.Login$2.handle(Login.java:107)
at com.mycompany.myproject/com.mycompany.myproject.controllers.users.Login$2.handle(Login.java:98)
at javafx.base@19/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base@19/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base@19/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base@19/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base@19/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base@19/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base@19/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base@19/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base@19/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base@19/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base@19/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base@19/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base@19/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics@19/javafx.scene.Node.fireEvent(Node.java:8923)
at javafx.controls@19/javafx.scene.control.Button.fire(Button.java:203)
at javafx.controls@19/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:207)
at javafx.controls@19/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at javafx.base@19/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at javafx.base@19/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base@19/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base@19/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base@19/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base@19/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base@19/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base@19/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base@19/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base@19/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base@19/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base@19/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base@19/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base@19/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics@19/javafx.scene.Scene$MouseHandler.process(Scene.java:3894)
at javafx.graphics@19/javafx.scene.Scene.processMouseEvent(Scene.java:1887)
at javafx.graphics@19/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2620)
at javafx.graphics@19/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
at javafx.graphics@19/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics@19/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
at javafx.graphics@19/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
at javafx.graphics@19/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
at javafx.graphics@19/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
at javafx.graphics@19/com.sun.glass.ui.View.notifyMouse(View.java:937)
at javafx.graphics@19/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics@19/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:316)
at java.base/java.lang.Thread.run(Thread.java:829)


Подробнее здесь: https://stackoverflow.com/questions/790 ... connection
Реклама
Ответить Пред. темаСлед. тема

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

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

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

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

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

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