[solved] cannot use serial port
Edited by wwwlu at 2017-2-24 17:51I can't read the serial port of my OPI pc plus with Armbian
My python script (which works fine on lubuntu)
#!/usr/bin/env python
# -*- coding: latin-1 -*-
import serial
import os
ser = serial.Serial('/dev/ttyS0', 9600)
while True :
data = ser.readline()
print (data)
if "stop" in data:
os.system('sudo shutdown -h now')
returns :
Traceback (most recent call last):
File "off.py", line 10, in <module>
data = ser.readline()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 453, in read
buf = os.read(self.fd, size-len(read))
OSError: Resource temporarily unavailable
I tried :
sudo minicom -D /dev/ttyS0result:
Device /dev/ttyS0 is locked.
and with:
dmesg | grep ttyi get :
[ 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
[ 0.000000] console enabled
[ 0.460131] uart0: ttyS0 at MMIO 0x1c28000 (irq = 32) is a SUNXI
[ 6.252629] systemd: Expecting device dev-ttyS0.device...
[ 6.488254] systemd: Starting system-getty.slice.
[ 6.497739] systemd: Created slice system-getty.slice.
[ 6.502287] systemd: Starting system-serial\x2dgetty.slice.
[ 6.511686] systemd: Created slice system-serial\x2dgetty.slice.
What can I do ?
Thanks!
I changed the serial config using minicom and now I get :
Traceback (most recent call last):
File "off.py", line 11, in <module>
data = ser.readline()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 495, 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?)
ps -ef | grep tty:
root 787 7800 13:44 tty7 00:00:50 /usr/lib/xorg/Xorg :0 -nolisten tcp vt7
root 1260 10 13:44 tty1 00:00:00 /sbin/agetty --noclear tty1 linux
root 5347 10 15:09 ttyS0 00:00:00 /bin/login --
lu 536015720 15:09 pts/0 00:00:00 grep --color=auto tty
Does this mean ttyS0 is already used by root ? what should I do ?
Thanks 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 You can't use ttyS0 since it's in use / enabled by default for serial console. On all our builds.
Use ttyS1 or other. It works fine with ttyS1 !!!:)
Thanks a lot Igor and JRios for your great help! 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 ? I had to enable ttyS1 with armbian-config first :
then it worked!
page:
[1]