我希望在Windows 10上使用Python 3.9中的套接字(socket)连接到Arduino上的HC-05模块并发送/读取一些字符。然而,当我使用以下代码时,会出现错误:
import socket
adapter_addr = '00:21:11:01:FA:1C'
port = 1 # Normal port for rfcomm?
buf_size = 1024
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM,
socket.BTPROTO_RFCOMM)
s.bind((adapter_addr, port))
s.listen(1)
try:
print('Listening for connection...')
client, address = s.accept()
print(f'Connected to {address}')
while True:
data = client.recv(buf_size)
if data:
print(data)
except Exception as e:
print(f'Something went wrong: {e}')
client.close()
s.close()
line 30, in <module>
s.bind((adapter_addr, port))
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
我也尝试使用了PyBluez库,但是它给出了类似的错误信息。 感谢任何帮助。