Portál AbcLinuxu, 6. května 2025 06:33
$ hal-find-by-capability --capability serial | xargs -n 1 hal-deviceŘešení přes
$ ls /dev/ttyS*sice funguje, ale vypíše i porty, které nejsou v systému (ttyS2 a ttyS3). Hledat porty pomocí
$ find /sys/ -name 'ttyS*'také jde, ale také to není ono
Device Node Path: /dev/ttyS0 Unable to find parent usb device.Trpí to ovšem stejným problémem. A to že vypíše i porty, které nejsou v PC (ttyS3, ttyS4). Jak se píše na http://wiki.debian.org/HALRemoval, KDE 4.x používají pro enumeraci zařízení Solid, který zatím používá HAL a dokládá to přiložený screenshot. Vidím to tak, že ač se chtějí HALu všichni zbavit, tak to jde zatím těžko, protože asi má něco do sebe
dmesg | grep serial
$ dmesg | grep serial serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A usbcore: registered new interface driver usbserial usbcore: registered new interface driver usbserial_generic usbserial: USB Serial Driver core pl2303: Prolific PL2303 USB to serial adaptor driverPřesto díky za vyzkoušení.
$ dmesg | grep tty console [tty0] enabled serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A 00:09: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A usb 2-10: pl2303 converter now attached to ttyUSB0 ftdi_sio ttyUSB1: Unable to read latency timer: -32 usb 2-4: FTDI USB Serial Device converter now attached to ttyUSB1 usb 2-7: TI USB 3410 1 port adapter converter now attached to ttyUSB2 usb 2-3: pl2303 converter now attached to ttyUSB3 ti_usb_3410_5052_1 ttyUSB2: TI USB 3410 1 port adapter converter now disconnected from ttyUSB2 usb 2-7: TI USB 3410 1 port adapter converter now attached to ttyUSB2 ti_usb_3410_5052_1 ttyUSB2: TI USB 3410 1 port adapter converter now disconnected from ttyUSB2 usb 2-7: TI USB 3410 1 port adapter converter now attached to ttyUSB2 ftdi_sio ttyUSB1: FTDI USB Serial Device converter now disconnected from ttyUSB1 usb 2-4: FTDI USB Serial Device converter now attached to ttyUSB1 ti_usb_3410_5052_1 ttyUSB2: TI USB 3410 1 port adapter converter now disconnected from ttyUSB2 ftdi_sio ttyUSB1: Unable to write latency timer: -32 ftdi_sio ttyUSB1: Unable to write latency timer: -32 usb 2-7: TI USB 3410 1 port adapter converter now attached to ttyUSB2
dmesg | grep -oE "tty(S|USB)[0-9]+" | sort -u
$ dmesg | grep -oE "tty(S|USB)[0-9]+" | sort -u ttyS0 ttyUSB0 ttyUSB1 ttyUSB2 ttyUSB3Mimochodem, pěkná patička. V této situaci velmi pravdivá
#!/bin/bash for tty in $(find /sys/class/tty/ -type l); do udevadm info --query=path --path=$tty | grep -v virtual > /dev/null if [ $? -eq 0 ]; then echo $tty | sed "s/.*\///" fi doneale mimochodem, co je špatného na
hal-find-by-capability --capability serial | xargs -n 1 hal-device
?
SerialPortInterface::getPorts()
. S trochou úpravy by to mohlo hledat i ty ttyUSB, stačí změnit major a minor, ty se daj najít v dokumentaci jádra. Samozřejmě nutností je používat udev
.
#include <libudev.h> #include <stdio.h> #include <stdlib.h> #include <locale.h> #include <unistd.h> int main (void) { int minor; struct udev *udev; udev = udev_new(); if (!udev) { printf("Can't create udev\n"); exit(1); } for(minor = 0; minor <= 255; ++minor) { struct udev_device * udev_device = udev_device_new_from_devnum(udev, 'c', makedev(188, minor)); if(udev_device != NULL) { printf("%s\n", udev_device_get_devnode(udev_device)); udev_device_unref(udev_device); } else break; // mozna by se melo pokracovat ve vyhledavani.. } for(minor = 64; minor <= 255; ++minor) { struct udev_device * udev_device = udev_device_new_from_devnum(udev, 'c', makedev(4, minor)); if(udev_device != NULL) { printf("%s\n", udev_device_get_devnode(udev_device)); udev_device_unref(udev_device); } else break; // mozna by se melo pokracovat ve vyhledavani.. } udev_unref(udev); return 1; }Možná to ještě zkusit port po portu otevřít, a jestli se podaří, tak ten port tam je... Díky za inspiraci.
# setserial -g /dev/tty[USB]* /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 /dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3 /dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4 /dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3 /dev/ttyUSB0, UART: 16654, Port: 0x0000, IRQ: 0 /dev/ttyUSB1, UART: 16550A, Port: 0x0000, IRQ: 0Funguje to i na USB-serial převodníky i když si vymýšlí typ UARTu
$ hal-find-by-capability --capability serial | xargs -n 1 hal-device udi = '/org/freedesktop/Hal/devices/usb_device_403_6001_12345678_if0_serial_usb_0' // to 12345678 je opravdu sériové číslo převodníku - sám jsem ho do eeprom zapisovalZ dmesg dostanu také vcelku vyčeřpávající informace... Jen z toho HALu je to takové hezké a učesané. Teď to nemohu najít, ale někde v dokumentaci k libudev jsem se dočetl, že mají v plánu obohatit výstupní informace tak, jak to asi dělá HAL. Bylo to někde v souvislosti se SOLIDem z KDE4, který doposud používá HAL. Možná by to byl námět na zpracování enumerátoru sériových portů pro Jardíkainfo.category = 'serial' (string) linux.hotplug_type = 2 (0x2) (int) linux.subsystem = 'tty' (string) linux.device_file = '/dev/ttyUSB2' (string) info.subsystem = 'tty' (string) info.product = 'FT232 USB-Serial (UART) IC' (string) info.udi = '/org/freedesktop/Hal/devices/usb_device_403_6001_12345678_if0_serial_usb_0' (string) linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:02.0/usb2/2-4/2-4:1.0/ttyUSB2/tty/ttyUSB2' (string) info.parent = '/org/freedesktop/Hal/devices/usb_device_403_6001_12345678_if0' (string) serial.originating_device = '/org/freedesktop/Hal/devices/usb_device_403_6001_12345678_if0' (string) info.capabilities = { 'serial' } (string list) serial.device = '/dev/ttyUSB2' (string) serial.port = 0 (0x0) (int) serial.type = 'usb' (string) udi = '/org/freedesktop/Hal/devices/usb_device_451_f430_TUSB34103D299682E658FF15_if0_serial_usb_0' info.category = 'serial' (string) linux.hotplug_type = 2 (0x2) (int) linux.subsystem = 'tty' (string) linux.device_file = '/dev/ttyUSB1' (string) info.subsystem = 'tty' (string) info.product = 'MSP-FET430UIF JTAG Tool' (string) info.udi = '/org/freedesktop/Hal/devices/usb_device_451_f430_TUSB34103D299682E658FF15_if0_serial_usb_0' (string) linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:02.0/usb2/2-7/2-7:2.0/ttyUSB1/tty/ttyUSB1' (string) info.parent = '/org/freedesktop/Hal/devices/usb_device_451_f430_TUSB34103D299682E658FF15_if0' (string) serial.originating_device = '/org/freedesktop/Hal/devices/usb_device_451_f430_TUSB34103D299682E658FF15_if0' (string) info.capabilities = { 'serial' } (string list) serial.device = '/dev/ttyUSB1' (string) serial.port = 0 (0x0) (int) serial.type = 'usb' (string) udi = '/org/freedesktop/Hal/devices/pnp_PNP0501_serial_platform_0' info.category = 'serial' (string) linux.hotplug_type = 2 (0x2) (int) linux.subsystem = 'tty' (string) linux.device_file = '/dev/ttyS0' (string) info.subsystem = 'tty' (string) info.product = '16550A-compatible COM port' (string) // to mi stačí
info.udi = '/org/freedesktop/Hal/devices/pnp_PNP0501_serial_platform_0' (string) linux.sysfs_path = '/sys/devices/pnp0/00:09/tty/ttyS0' (string) info.parent = '/org/freedesktop/Hal/devices/pnp_PNP0501' (string) serial.originating_device = '/org/freedesktop/Hal/devices/pnp_PNP0501' (string) info.capabilities = { 'serial' } (string list) serial.device = '/dev/ttyS0' (string) serial.port = 0 (0x0) (int) serial.type = 'platform' (string) udi = '/org/freedesktop/Hal/devices/usb_device_67b_2303_noserial_if0_serial_usb_0' info.category = 'serial' (string) linux.hotplug_type = 2 (0x2) (int) linux.subsystem = 'tty' (string) linux.device_file = '/dev/ttyUSB0' (string) info.subsystem = 'tty' (string) info.product = 'PL2303 Serial Port' (string) info.udi = '/org/freedesktop/Hal/devices/usb_device_67b_2303_noserial_if0_serial_usb_0' (string) linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:02.0/usb2/2-10/2-10:1.0/ttyUSB0/tty/ttyUSB0' (string) info.parent = '/org/freedesktop/Hal/devices/usb_device_67b_2303_noserial_if0' (string) serial.originating_device = '/org/freedesktop/Hal/devices/usb_device_67b_2303_noserial_if0' (string) info.capabilities = { 'serial' } (string list) serial.device = '/dev/ttyUSB0' (string) serial.port = 0 (0x0) (int) serial.type = 'usb' (string)
cat /proc/devices Character devices: 1 mem 4 /dev/vc/0 4 tty 4 ttyS 5 /dev/tty 5 /dev/console 5 /dev/ptmx 7 vcs 10 misc 13 input 21 sg 29 fb 128 ptm 136 pts 180 usb 189 usb_device 202 cpu/msr 203 cpu/cpuid 226 drm 251 hidraw 252 usbmon 253 bsg 254 rtc Block devices: 1 ramdisk 259 blkext 7 loop 8 sd 9 md 65 sd 66 sd 67 sd 68 sd 69 sd 70 sd 71 sd 128 sd 129 sd 130 sd 131 sd 132 sd 133 sd 134 sd 135 sd 180 ub 253 device-mapper 254 mdp
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.