0

我想在带有蓝牙加密狗和 Windows 7 的笔记本电脑和我的树莓派 3 之间进行蓝牙通信。

我在互联网上找到了一些使用 Pybluez 库的教程,但这对我不起作用。

在下面找到服务器部分的代码:

import bluetooth

Host = ""
port = 12

HostAddr = (Host, port)

def setupServer():
    server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
    print("Socket Created.")
    server_socket.bind(HostAddr)
    server_socket.listen(1)
    print("Socket bind complete")

    client_sock, client_info = server_socket.accept()
    print("Accepted connection from " , client_info)

    try:
        while True:
            data = client_sock.recv(1024)
            if len(data) == 0: break
            print("received [%s]" %data)
    except IOError:
        pass

    print("Disconnected")

client_sock.close()
server_socket.close()
print("all done")

设置服务器()

这是输出:

Socket Created.
Traceback (most recent call last):
  File "path_to_file\Server.py", line 33, in <module>
setupServer()
  File "path_to_file\Server.py", line 12, in setupServer
server_socket.bind(HostAddr)
  File "C:\Python34\lib\site-packages\bluetooth\msbt.py", line 60, in bind
bt.bind (self._sockfd, addr, port)
OSError

你知道为什么我有这个错误吗?

4

0 回答 0