我想通过代码自动获得串行连接的权限,而不是每次都要使用终端来授予权限。你知道吗
我试着使用导入操作系统操作系统()自动授予权限,但权限始终被拒绝。你知道吗
def checkConnection(password):
if os.path.exists('/dev/ttyUSB0'):
usb = '/dev/ttyUSB0'
os.system('echo password | sudo chmod 666 /dev/ttyUSB0')
return usb
elif os.path.exists('/dev/ttyUSB1'):
usb = '/dev/ttyUSB0'
os.system('echo password | sudo chmod 666 /dev/ttyUSB1')
return usb
else:
print('Is there a console connected?')
我经常犯的错误是
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'
我知道你在努力实现什么,我听到你在说什么,但这不是正确的方法。使用
echo password
既不合理,也没有给设备666
的想法。只需将您的用户添加到拥有这些设备的组中,并将其保留。你知道吗相关问题 更多 >
编程相关推荐