黑莓蓝牙开发帮助

发布于 2024-09-17 20:22:04 字数 537 浏览 5 评论 0原文

我的蓝牙应用程序已经被困了好几天了。 它的作用是接收来自蓝牙设备的数据,使用串口协议... 该应用程序在手机和设备的后台运行,当它们需要发送信息时,打开蓝牙并尝试发送数据帧。

问题是可以使用此应用程序连接多个设备。而且我没有设法将手机作为服务器,以便它可以接收连续的数据。 这意味着我可以用 AcceptAndOpen() 创建一个 Connector.open("btspp: localhost :...."),但是这个函数只启动一次,我不能无休止地重新启动。


解决方案是启动 AcceptAndOpen () 当蓝牙通话结束时...重新启动该功能,但我不能(我只是重新创建打开端口的对象)


我尝试使用但没有成功: - PushRegistry(“btspp”不兼容) - Connector.open () 与客户端的 mac 地址(但这不是自阻止)

如果有人可以帮助我解决这个问题。因为我已经在黑莓论坛上彻底搜索过了......

谢谢你,Fabrice

PS:如果你需要源代码,我可以给你......但我不确定这可以帮助你回答我。

I've been stuck since several days on my bluetooth application.
Its role is to receive data from Bluetooth devices, using Serial Port Protocol ...
The application runs in the background of the phone and devices, when they need to send an information, turns on the bluetooth and try to send a data frame.

The problem is that several devices can connect using this application. And I don't manage to put the phone as a server so it could receive continuous data.
This means that I can create a Connector.open ("btspp: localhost :....") with AcceptAndOpen (), but this function starts only once and I can not relaunch endlessly.


The solution would be to launch a AcceptAndOpen ()
When a bluetooth call is over ... restart the function, but I can not (I simply recreates the object that made the port opening)


I try to use without success:
- PushRegistry ("btspp" is not compatible)
- Connector.open () with the mac address of clients (but this is not self-blocking)

If someone could help me on how to solve this issue. Because I have searched thoroughly on the blackberry forums...

Thank you, Fabrice

PS: If you need source code, I can give you ... But I'm not sure this can help you to answer me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初雪 2024-09-24 20:22:04

确保从acceptAndOpen 获得连接后,将该连接传递到新线程中。这允许当前的“服务器”线程返回并接受另一个连接(假设它在循环中)。

Make sure after you get a connection from acceptAndOpen, you pass that connection into a new thread. This allows the current "server" thread to go back and accept another connection (assuming it's in a loop).

凉月流沐 2024-09-24 20:22:04

抱歉我的回答迟了。

我创建了一个类:BluetoothReceiver,她在后台启动(链接文本)。
我的源代码的一部分可以尝试帮助您:

public void start() {
    try {
    _connector = (StreamConnectionNotifier) Connector.open("btspp://localhost:" + MY_UUID, Connector.READ);
    Runnable r = new Runnable() {
        public void run() {
            while(true) {
                try {
                    StreamConnection connection = _connector.acceptAndOpen();
                    onConnectionOpen(connection);
                }
                catch (IOException e) {
                    // Connection failed
                    break;
                }
            }
        }
    };
    Thread t = new Thread(r);
    t.start();
}
catch (IOException e) {
    // e.getMessage()
}

private void onConnectionOpen(StreamConnection connection) {
    RemoteDevice device = null;
    try {
        device = RemoteDevice.getRemoteDevice(connection);
    } catch (IOException e) {
        // e.getMessage()
    }
    if(device != null) {
        // Make your own process: read, write, pair, ...
    }
}

问候,Fabrice

Sorry for my late answer.

I've create a class: BluetoothReceiver that's she is launch in background (link text).
There is a part of my sourcecode for try to help you:

public void start() {
    try {
    _connector = (StreamConnectionNotifier) Connector.open("btspp://localhost:" + MY_UUID, Connector.READ);
    Runnable r = new Runnable() {
        public void run() {
            while(true) {
                try {
                    StreamConnection connection = _connector.acceptAndOpen();
                    onConnectionOpen(connection);
                }
                catch (IOException e) {
                    // Connection failed
                    break;
                }
            }
        }
    };
    Thread t = new Thread(r);
    t.start();
}
catch (IOException e) {
    // e.getMessage()
}

private void onConnectionOpen(StreamConnection connection) {
    RemoteDevice device = null;
    try {
        device = RemoteDevice.getRemoteDevice(connection);
    } catch (IOException e) {
        // e.getMessage()
    }
    if(device != null) {
        // Make your own process: read, write, pair, ...
    }
}

Regards, Fabrice

[旋木] 2024-09-24 20:22:04

我刚刚放置了 acceptAndOpen()

while(true) {
    ...
}

现在可以了。

I've just put around acceptAndOpen():

while(true) {
    ...
}

Now it's okay.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文