I have a simple script to check if a USB device (UART) is plugged in.
(OS = Ubuntu 22.04, Python 3.10).
import os
path = os.path.join('dev', 'ttyUSB0')
print(f'DBG exists: {os.path.exists(path)}')
print(f'DBG isfile: {os.path.isfile(path)}')
print(f'DBG isdir : {os.path.isdir(path)}')
# print(f'DBG isdevdrive: {os.path.isdevdrive(path)}')
# causes: AttributeError: module 'posixpath' has no attribute 'isjunction'
print(f'DBG islink: {os.path.islink(path)}')
# print(f'DBG isjunction: {os.path.isjunction(path)}')
# causes: ditto
print(f'DBG lexists: {os.path.lexists(path)}')
output is:
DBG exists: False
DBG isfile: False
DBG isdir : False
DBG islink: False
DBG lexists: False
but the file definitely exists:
$ ls -al /dev/ttyUSB0
crw-rw----+ 1 root dialout 188, 0 Sep 25 10:42 /dev/ttyUSB0
Just curious, what is it about ttyUSB0
that makes the os.path.xx
functions always report False?
8