View: 13785|Reply: 6

[solved] cannot use serial port

[Copy link]

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
Published in 2017-2-22 19:02:56 | Show all floors |Read mode
Edited by wwwlu at 2017-2-24 17:51

I can't read the serial port of my OPI pc plus with Armbian
My python script (which works fine on lubuntu)
  1. #!/usr/bin/env python
  2. # -*- coding: latin-1 -*-

  3. import serial
  4. import os

  5. ser = serial.Serial('/dev/ttyS0', 9600)

  6. while True :
  7.         data = ser.readline()
  8.         print (data)
  9.         if "stop" in data:
  10.                 os.system('sudo shutdown -h now')
Copy code
returns :
  1. Traceback (most recent call last):
  2.   File "off.py", line 10, in <module>
  3.     data = ser.readline()
  4.   File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 453, in read
  5.     buf = os.read(self.fd, size-len(read))
  6. OSError: [Errno 11] Resource temporarily unavailable
Copy code

I tried :
  1. sudo minicom -D /dev/ttyS0
Copy code
result:
  1. Device /dev/ttyS0 is locked.
Copy code

and with:
  1. dmesg | grep tty
Copy code
i get :
  1. [    0.000000] Kernel command line: console=tty1 root=/dev/mmcblk0p1 rootwait rootfstype=ext4 cgroup_enable=memory swapaccount=1 panic=10 consoleblank=0 enforcing=0 loglevel=7
  2. [    0.000000] console [tty1] enabled
  3. [    0.460131] uart0: ttyS0 at MMIO 0x1c28000 (irq = 32) is a SUNXI
  4. [    6.252629] systemd[1]: Expecting device dev-ttyS0.device...
  5. [    6.488254] systemd[1]: Starting system-getty.slice.
  6. [    6.497739] systemd[1]: Created slice system-getty.slice.
  7. [    6.502287] systemd[1]: Starting system-serial\x2dgetty.slice.
  8. [    6.511686] systemd[1]: Created slice system-serial\x2dgetty.slice.
Copy code

What can I do ?
Thanks!

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
 Author| Published in 2017-2-22 23:15:53 | Show all floors
I changed the serial config using minicom and now I get :
  1. Traceback (most recent call last):
  2.   File "off.py", line 11, in <module>
  3.     data = ser.readline()
  4.   File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 495, in read
  5.     raise SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)')
  6. serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
Copy code

ps -ef | grep tty:
  1. root       787   780  0 13:44 tty7     00:00:50 /usr/lib/xorg/Xorg :0 -nolisten tcp vt7
  2. root      1260     1  0 13:44 tty1     00:00:00 /sbin/agetty --noclear tty1 linux
  3. root      5347     1  0 15:09 ttyS0    00:00:00 /bin/login --
  4. lu        5360  1572  0 15:09 pts/0    00:00:00 grep --color=auto tty
Copy code


Does this mean ttyS0 is already used by root ? what should I do ?
Thanks

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
 Author| Published in 2017-2-22 23:40:42 | Show all floors
Thanks JRios,

Yes I used Sudo to execute the python script.
ser.read() does not change anything
I modified script.bin but I cannot boot anymore:
stucked on "Hit any key to stop autoboot: 0"
(does not change if I hit a key)
I will burn the image again

9

threads

634

posts

4400

credits

Moderator

Rank: 7Rank: 7Rank: 7

credits
4400
Published in 2017-2-23 00:28:47 | Show all floors
You can't use ttyS0 since it's in use / enabled by default for serial console. On all our builds.

Use ttyS1 or other.

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
 Author| Published in 2017-2-23 17:50:41 | Show all floors
It works fine with ttyS1 !!!  

Thanks a lot Igor and JRios for your great help!

2

threads

12

posts

71

credits

Registered member

Rank: 2

credits
71
Published in 2018-3-24 00:02:02 | Show all floors
I modified script.bin but I cannot boot anymore:
stucked on "Hit any key to stop autoboot: 0"


Do you mean you did that modification or ttyS1 was available from scratch ?

2

threads

12

posts

71

credits

Registered member

Rank: 2

credits
71
Published in 2018-4-3 04:58:35 | Show all floors
I had to enable ttyS1 with armbian-config first :
then it worked!


This thread contains more resources

You need to Log in to download or view,No account?    Register

x
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list