ubuntu更新後串口無法正常運作?

ubuntu更新後串口無法正常運作?

我的串口有一個奇怪的問題。 ubuntu 實作並重新啟動後,似乎某些事情發生了變化。

przem@przem:~/Pulpit/bat/scripts$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial("/dev/ttyUSB0", 57600)
>>> ser.read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 475, in read
    raise SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
>>> 

我知道我的設備應該有“ ”(空符號)結果,但我得到的卻是異常:

“設備報告已準備好讀取,但未返回任何數據(設備已斷開連接或端口上有多個訪問?)”

這個問題是對我的問題的介紹:https://stackoverflow.com/questions/32844942/serialport-doenst-work- Correctly-after-ubuntu-update?noredirect=1#comment53527004_32844942

請幫我。

答案1

我遇到同樣的問題。它似乎不限於串口硬體。您可以使用 socat 建立兩個偽終端:

$ socat -d -d pty,raw,echo=0 pty,raw,echo=0
2015/09/30 09:46:18 socat[6296] N PTY is /dev/pts/17
2015/09/30 09:46:18 socat[6296] N PTY is /dev/pts/18
2015/09/30 09:46:18 socat[6296] N starting data transfer loop with FDs [3,3] and [5,5]

您可以連接這兩個設備,例如使用 cu

cu -l /dev/pts/17 -s 115200

cu -l /dev/pts/18 -s 115200

並雙向發送數據,沒問題。

但是與 Python 2.7 連線失敗並出現您提到的錯誤訊息

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial("/dev/pts/17", 230400, timeout=0.2)
>>> ser.read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 460, in read
    raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)

該程式碼在昨天安裝 Ubuntu 14.04 更新之前有效。

有任何想法嗎?

答案2

我不同意這一點,但在進行此更改後我不再看到這些錯誤:

--- serialposix.py.stock    2015-10-03 06:53:45.241261071 -0700 
+++ serialposix.py  2015-10-03 06:55:07.481262475 -0700
@@ -457,7 +457,11 @@
             # Disconnected devices, at least on Linux, show the
             # behavior that they are always ready to read immediately
             # but reading returns nothing.
-                raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
+                # retrying the read seems to get me past this error:
+                # [ERROR] Can't read from printer (disconnected?)     (SerialException): device reports readiness to read but returned no data (device disconnected?)
+
+                #raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
+                pass
         read.extend(buf)
     return bytes(read)

答案3

這可能是個核心錯誤。看這裡:https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/1501240

解決方法似乎是使用 kernel 3.13.0-63-generic

您可以在啟動時按住 Shift 鍵來變更一次性啟動的核心。要使變更持久,您需要編輯/etc/default/grubhttps://askubuntu.com/questions/262965/grub-timeout-set-to-0-cant-access-grub-menu-anymore?rq=1

相關內容