如何重新啟動/釋放rfcomm進行藍牙通訊?

如何重新啟動/釋放rfcomm進行藍牙通訊?

我正在嘗試將樹莓派連接到我的 Galaxy Note,以使用它進行串行通訊。我在這方面已經取得了一定的成功。

首先我將其配對並透過信任bluetoothctl。然後我運行sudo rfcomm watch hci0並打開cat /dev/rfcomm。我能夠使用連接到樹莓派藍牙終端(只有這個應用程序,其他所有應用程式都失敗)並且從 Galaxy 發送的字串將顯示在cat視窗中。

後來我不知何故搞砸了,現在跑步sudo rfcomm watch hci0給了我Can't bind RFCOMM socket: Address already in use。我無法使用sudo rfcomm release hci0or釋放它sudo rfcomm release 0,因為它隨後給了我Can't release device: No such device。現在也同樣cat /dev/rfcomm0給我No such file or directory

我殺死了列出的進程sudo lsof | grep /dev/rfcomm0,這對我使用 RFCOMM 的能力沒有影響。重新加載systemctl daemon-reload並重新啟動service bluetooth restart也沒有效果。

我仍然可以掃描其他藍牙設備,並且可以使用藍牙終端連接到樹莓派,但似乎 rfcomm 消失了。我知道重新啟動可以解決這個問題,但如果可能的話,我希望以程式設計方式執行此操作,而不必求助於電源循環。

感謝您的協助。

答案1

dmesg在樹莓派上檢查指令的輸出。

我得到類似的東西:

[  296.768548] ------------[ cut here ]------------
[  296.768576] WARNING: CPU: 3 PID: 40 at drivers/tty/tty_port.c:257 tty_port_put+0x94/0x98
[  296.768586] Modules linked in: rfcomm cmac bnep hci_uart btbcm serdev bluetooth ecdh_generic 8021q garp stp llc brcmfmac brcmutil bcm2835_codec(C) bcm2835_v4l2(C) v4l2_mem2mem sha256_generic bcm2835_mmal_vchiq(C) v4l2_common videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops cfg80211 videobuf2_v4l2 videobuf2_common videodev media rfkill vc_sm_cma(C) v3d vc4 gpu_sched drm_kms_helper rpivid_mem raspberrypi_hwmon hwmon drm drm_panel_orientation_quirks snd_soc_core snd_bcm2835(C) snd_compress snd_pcm_dmaengine snd_pcm snd_timer syscopyarea sysfillrect sysimgblt fb_sys_fops snd rpi_backlight rpi_ft5406 uio_pdrv_genirq uio evdev joydev ip_tables x_tables ipv6
[  296.768773] CPU: 3 PID: 40 Comm: kworker/3:1 Tainted: G         C        4.19.97-v7l+ #1294
[  296.768781] Hardware name: BCM2835
[  296.768798] Workqueue: events release_one_tty
[  296.768825] [<c0212e04>] (unwind_backtrace) from [<c020d5e0>] (show_stack+0x20/0x24)
[  296.768844] [<c020d5e0>] (show_stack) from [<c09b15c8>] (dump_stack+0xe0/0x124)
[  296.768865] [<c09b15c8>] (dump_stack) from [<c0222544>] (__warn+0x104/0x11c)
[  296.768883] [<c0222544>] (__warn) from [<c0222694>] (warn_slowpath_null+0x50/0x58)
[  296.768899] [<c0222694>] (warn_slowpath_null) from [<c06cab28>] (tty_port_put+0x94/0x98)
[  296.768941] [<c06cab28>] (tty_port_put) from [<bf9dd2a0>] (rfcomm_tty_cleanup+0x5c/0x60 [rfcomm])
[  296.768999] [<bf9dd2a0>] (rfcomm_tty_cleanup [rfcomm]) from [<c06c2a38>] (release_one_tty+0x3c/0xac)
[  296.769019] [<c06c2a38>] (release_one_tty) from [<c023e028>] (process_one_work+0x170/0x458)
[  296.769036] [<c023e028>] (process_one_work) from [<c023e36c>] (worker_thread+0x5c/0x5a4)
[  296.769051] [<c023e36c>] (worker_thread) from [<c02446a0>] (kthread+0x138/0x168)
[  296.769066] [<c02446a0>] (kthread) from [<c02010ac>] (ret_from_fork+0x14/0x28)
[  296.769075] Exception stack(0xefab3fb0 to 0xefab3ff8)
[  296.769086] 3fa0:                                     00000000 00000000 00000000 00000000
[  296.769098] 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  296.769108] 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[  296.769119] ---[ end trace 545b669f95e0d2b5 ]---

這讓我相信內核模組(rfcomm)及其處理線程(krfcomm)在釋放 tty 時掛起/崩潰,並使其處於損壞狀態。

因此,嘗試建立新的裝置會與尚未刪除的裝置發生衝突,而嘗試刪除/釋放現有的裝置會導致一則訊息表示該裝置不存在。

我認為除了重新啟動之外,目前沒有其他解決方案。

我在某處讀到,如果確保連線保持開啟超過 10 秒,則不會發生當機並且可以成功重複使用連接埠。

編輯:以下對同一問題的回答建議刪除該modemmanager軟體包,這可能會造成乾擾。

https://stackoverflow.com/a/46915801/3398351

相關內容