Get in here, tech brehs! I need help! Stop goofing around and let me use your brain power tonight! EDIT Might have found the solution

Joined
Apr 3, 2014
Messages
70,133
Reputation
16,879
Daps
300,780
:damn: I've been wracking my brain for hours.

I'm trying to find the name of my USB device port in Linux so that I can use it in a python script.

Here's an example:


Before some fool tells me to just do
Code:
lsusb
, don't you think I tried that already? :mjtf:


That command gives me all the information about the device that's connected, but I need the actual Port name in a COM format so that again, I can use it in my script.

Help!!!









EDIT

PAUSE ALL RESPONSES, brehs.



I think I might have just figured this out.



I'll be back later with an explanation for those that are interested.
 
Last edited:

Ty Daniels

All Star
Joined
Dec 13, 2019
Messages
1,607
Reputation
2,783
Daps
10,620
I'm not on Linux but this is what Chat-GPT said:

In Linux, USB ports are not typically referred to in COM format as in Windows. COM ports are specific to Windows operating systems and are used to communicate with serial devices. However, if you're looking to find the device name of a USB device in Linux, such as /dev/ttyUSB0 for example, you can use the following steps:

  1. Plug in your USB device.
  2. Open a terminal window.
  3. Run the command ls /dev/ttyUSB*. This will list all the USB serial devices currently connected to your system.
The output will display the device names assigned to the USB serial ports. They typically appear as /dev/ttyUSB0, /dev/ttyUSB1, and so on.

If you're specifically looking for information about USB ports in the context of hardware identification or debugging, you may need to delve into tools like lsusb or usb-devices which provide detailed information about connected USB devices and their attributes.



If you want to find information about USB ports without plugging in a device, you can use various commands to inspect the USB subsystem and see what ports are available. Here are a few methods:

  1. lsusb Command:
    The lsusb command lists USB devices connected to your system. You can run it without any arguments to get a list of all connected USB devices. Open a terminal and type:
    Copy code
    lsusb
    This will give you a list of USB devices along with their details such as vendor ID, product ID, and bus information.
  2. udevadm Command:
    You can also use udevadm to query the udev device manager database for information about USB devices. For example:
    bashCopy code
    udevadm info -a -n /dev/bus/usb/001/001
    This command will give you detailed information about the USB device specified by the path /dev/bus/usb/001/001. You can adjust the path according to your system.
  3. usb-devices Command:
    The usb-devices command gives detailed information about USB devices and their interfaces. Run it without any arguments:
    Copy code
    usb-devices
    This will list all USB devices, including hubs and controllers, connected to your system.
These commands should provide you with information about USB ports and devices without needing to physically plug a device in. However, keep in mind that without a device connected, you won't see the dynamic assignment of ports that occurs when a device is plugged in.



Let me know if any of this works for you
 

humminbird

Veteran
Joined
Nov 18, 2016
Messages
44,246
Reputation
8,497
Daps
182,520
here's what it says
To find the name of your USB device port in Linux, which you can then use in a Python script, you can follow these steps:

1. **List USB devices**: You can use the `lsusb` command in the terminal to list all USB devices connected to your system. This will give you information about the manufacturer and product ID but not the device name (like `/dev/ttyUSB0`).

```bash
lsusb
```

2. **Check system messages**: After plugging in your USB device, you can check the system messages to see how it was recognized. The `dmesg` command is useful for this.

```bash
dmesg | tail
```

Look for lines that mention your device. The device name is usually something like `/dev/ttyUSB0` or `/dev/ttyACM0`.

3. **List tty devices**: Another approach is to list the contents of the `/dev` directory before and after plugging in the USB device.

```bash
ls /dev > before.txt
# Plug in your USB device
ls /dev > after.txt
diff before.txt after.txt
```

The difference shown by the `diff` command will usually include your USB device's name.

4. **Use Python libraries**: In Python, you can use libraries like `pyserial` to list serial ports. First, ensure you have `pyserial` installed:

```bash
pip install pyserial
```

Then, you can use the following Python script to list serial ports:

```python
import serial.tools.list_ports

ports = serial.tools.list_ports.comports()
for port, desc, hwid in sorted(ports):
print("{}: {} [{}]".format(port, desc, hwid))
```

This script will list all available serial ports with their descriptions.

5. **Additional Tools**: You can also use tools like `usb-devices`, a shell script that displays detailed information about USB buses in the system and the devices connected to them.

Remember, the exact name and path of your USB device can vary based on the type of device and how your system's kernel recognizes it.
 
Joined
Apr 3, 2014
Messages
70,133
Reputation
16,879
Daps
300,780
I'm not on Linux but this is what Chat-GPT said:

In Linux, USB ports are not typically referred to in COM format as in Windows. COM ports are specific to Windows operating systems and are used to communicate with serial devices. However, if you're looking to find the device name of a USB device in Linux, such as /dev/ttyUSB0 for example, you can use the following steps:

  1. Plug in your USB device.
  2. Open a terminal window.
  3. Run the command ls /dev/ttyUSB*. This will list all the USB serial devices currently connected to your system.
The output will display the device names assigned to the USB serial ports. They typically appear as /dev/ttyUSB0, /dev/ttyUSB1, and so on.

If you're specifically looking for information about USB ports in the context of hardware identification or debugging, you may need to delve into tools like lsusb or usb-devices which provide detailed information about connected USB devices and their attributes.



If you want to find information about USB ports without plugging in a device, you can use various commands to inspect the USB subsystem and see what ports are available. Here are a few methods:

  1. lsusb Command:
    The lsusb command lists USB devices connected to your system. You can run it without any arguments to get a list of all connected USB devices. Open a terminal and type:
    Copy code
    lsusb
    This will give you a list of USB devices along with their details such as vendor ID, product ID, and bus information.
  2. udevadm Command:
    You can also use udevadm to query the udev device manager database for information about USB devices. For example:
    bashCopy code
    udevadm info -a -n /dev/bus/usb/001/001
    This command will give you detailed information about the USB device specified by the path /dev/bus/usb/001/001. You can adjust the path according to your system.
  3. usb-devices Command:
    The usb-devices command gives detailed information about USB devices and their interfaces. Run it without any arguments:
    Copy code
    usb-devices
    This will list all USB devices, including hubs and controllers, connected to your system.
These commands should provide you with information about USB ports and devices without needing to physically plug a device in. However, keep in mind that without a device connected, you won't see the dynamic assignment of ports that occurs when a device is plugged in.



Let me know if any of this works for you







When I posted this thread, I was in the middle of trying to get some food and some sleep (in that order) so my bad, breh, because I didn't take the time to enumerate all of the solutions that I tried in my OP.

But when I run
Code:
ls /dev/ttyUSB*
this is what I get back:


G7Ookd7.png




As you can see, that ttyUSB directory doesn't even exist, and I'm not sure why. I spent all last night trying to figure that part out.

Does anyone know what could be causing this issue?
 

Ty Daniels

All Star
Joined
Dec 13, 2019
Messages
1,607
Reputation
2,783
Daps
10,620
When I posted this thread, I was in the middle of trying to get some food and some sleep (in that order) so my bad, breh, because I didn't take the time to enumerate all of the solutions that I tried in my OP.

But when I run
Code:
ls /dev/ttyUSB*
this is what I get back:


G7Ookd7.png




As you can see, that ttyUSB directory doesn't even exist, and I'm not sure why. I spent all last night trying to figure that part out.

Does anyone know what could be causing this issue?

Do you use Chat-GPT?

It isn't always correct, but a lot of time it can be helpful (You have to be really specific sometimes with it).

I use it daily to write basic code (utility)functions, that I don't feel like writing.

If not give it a shot, it can help troubleshoot certain tasks.
 

IIVI

Superstar
Joined
Mar 11, 2022
Messages
8,781
Reputation
2,226
Daps
28,524
Reppin
LA
I don't use Python or Linux like that so I'm unfamiliar with the ecosystem, but have you tried prototyping with one of the Python USB libraries?

Do they fail to find it or at least give a different error message?

 
Joined
Apr 3, 2014
Messages
70,133
Reputation
16,879
Daps
300,780
Do you use Chat-GPT?

It isn't always correct, but a lot of time it can be helpful (You have to be really specific sometimes with it).

I use it daily to write basic code (utility)functions, that I don't feel like writing.

If not give it a shot, it can help troubleshoot certain tasks.





Yes I've been using Chatgpt. I think the main issue is that the ttyUSB doesn't exist. I'll circle back around to GPT to see if it can help me figure that part out.
 
Joined
Apr 3, 2014
Messages
70,133
Reputation
16,879
Daps
300,780
I don't use Python or Linux like that so I'm unfamiliar with the ecosystem, but have you tried prototyping with one of the Python USB libraries?

Do they fail to find it or at least give a different error message?





I'm unfamiliar with this too but I'm reading the docs now to see if this will help. Thanks, breh.
 

IIVI

Superstar
Joined
Mar 11, 2022
Messages
8,781
Reputation
2,226
Daps
28,524
Reppin
LA
Asked ChatGPT as well:
Using pyusb how can I find the port number of a usb connected in Linux?

Don't know how accurate it is because I'm sure you know about ChatGPTisms, but this is what it said:
In Linux, USB devices are typically managed by the system and do not have "port numbers" in the same way that serial devices do. However, you can identify a USB device by its unique path or attributes such as the bus number and device address, which can be considered as an equivalent to finding its "port".

Using PyUSB, you can list all connected USB devices and find specific devices by their attributes, such as vendor ID, product ID, bus number, and device address. Here's a basic example of how to use PyUSB to list all connected USB devices and print their bus and device numbers, which can help you identify a specific device:

Code:
import usb.core
import usb.util

# Find all devices
devs = usb.core.find(find_all=True)
for dev in devs:
    # Use dev.bus and dev.address for bus number and device address
    print(f"Device: ID {dev.idVendor:04x}:{dev.idProduct:04x}")
    print(f"  Bus {dev.bus}, Device {dev.address}")
    print(f"  Manufacturer: {usb.util.get_string(dev, dev.iManufacturer)}")
    print(f"  Product: {usb.util.get_string(dev, dev.iProduct)}")
 
Top