简体   繁体   English

为 Linux 上的串行设备创建 sylink 时出现问题(`'Inappropriate ioctl for device'`)

[英]Issue creating sylink for serial device on Linux (`'Inappropriate ioctl for device'`)

I am using multiple USB devices connected to an Ubuntu machine and I would like to create a symlink to their corresponding device file so that I can read from these devices in Python.我正在使用连接到 Ubuntu 机器的多个 USB 设备,我想创建一个指向其相应设备文件的符号链接,以便我可以在 ZA7F5F35426B927411FC9231B563827 中读取这些设备。

For example, for the device "ka3305p" I created the rules file /etc/udev/rules.d/ka3305p.rules .例如,对于设备“ka3305p”,我创建了规则文件/etc/udev/rules.d/ka3305p.rules

ATTR{idVendor}=="0416", ATTR{idProduct}=="5011", SYMLINK+="ka3305p", MODE="0660", GROUP="dialout"

When I plug in the device, I see a symlink /dev/ka3305p appear:当我插入设备时,我看到一个符号链接/dev/ka3305p出现:

lrwxrwxrwx   1 root  root              15 Sep 21 10:08 ka3305p -> bus/usb/001/003

However, when I try to read from this file in python I get an error message:但是,当我尝试在 python 中读取此文件时,我收到一条错误消息:

def __init__(self,portname='/dev/ka3305p'):
    self.ser = serial.Serial(
        port=portname,
        baudrate=9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
    )

SerialException: Could not configure port: (25, 'Inappropriate ioctl for device')

Can I change the rules file to avoid this error?我可以更改规则文件以避免此错误吗?

I can read / communicate with the device normally if I use the device file /dev/ttyACM0 .如果我使用设备文件/dev/ttyACM0 ,我可以正常读取/与设备通信。

So I was able to solve this issue, apparently, I had to use ATTRS instead of ATTR in the rules file.所以我能够解决这个问题,显然,我必须在规则文件中使用ATTRS而不是ATTR This fixed the problem and I can now read normally from the device using the symlink.这解决了问题,我现在可以使用符号链接从设备正常读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM