Replacement for hal utilities in a serial port list script

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Monsta
Level 10
Level 10
Posts: 3071
Joined: Fri Aug 19, 2011 3:46 am

Replacement for hal utilities in a serial port list script

Post by Monsta »

At work, I sometimes deal with various USB-RS232 devices which are recognized by the system as serial ports with device names like /dev/ttyUSBn, where n >= 0.
A few years ago I wrote a script that prints all currently connected serial ports - their device names and product descriptions (to distinguish between FTDI and Prolific devices, for example):

Code: Select all

#!/bin/bash

list_all_ports() {
    for ((i = 0; i < dev_count; i++ ))
    do
        dev_description=`hal-get-property --udi ${dev_list[$i]} --key info.product`
        dev_name=`hal-get-property --udi ${dev_list[$i]} --key serial.device`
        echo -e $dev_name'\t'$dev_description
    done
}

declare -a dev_list
dev_list=(`hal-find-by-property --key info.subsystem --string tty`)
dev_count=${#dev_list[*]}

echo List of comports in the system:
list_all_ports | sort
This script calls two hal utilities: hal-get-property and hal-find-by-property. Now that hal is obsolete and not present neither in Ubuntu-based Mint nor in LMDE, this script ceased to function.

What could I possibly use to replace these calls?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
WharfRat

Re: Replacement for hal utilities in a serial port list scri

Post by WharfRat »

Hal was replaced by udev so you might want to look into udevadm

Code: Select all

udevadm info --export-db
Locked

Return to “Scripts & Bash”