Enumerating a USB device in Linux - linux

Is there a command to enumerate the USB device (HID) programmatically or through some commands?
In Windows we can do the same using Device Manager or devcon. I tried doing rmmod and insmoding the device driver, but it didn't enumerate the device.

Generally, USB devices are 'enumerated' internally in the kernel driver. Any time you list them with lsusb, this will show the actual devices present at that time. If you want a detailed listing of each devices, add -v (or --verbose) to the command.
Is that the information you are looking for?

To see all USB devices' data:
#!/usr/bin/env python
import sys
import usb.core
# find USB devices
devices = usb.core.find(find_all=True)
# loop through devices, printing vendor and product ids in decimal and hex
for cfg in devices:
sys.stdout.write('Decimal VendorID=' + str(cfg.idVendor) + ' & ProductID=' + str(cfg.idProduct) + '\n')
sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + '\n\n')
(Source: enter link description here)

Related

Jetson AGX Orin: tty device usable only once before failing

I am using a barcode scanner as part of a project, everything works correctly until I exit the program then I can't communicate anymore with the barcode scanner. This holds true for whatever program I'm running, be it one of my own or just using screen to monitor the transmissions. As soon as I exit, the only way to make the scanner work again is to unplug and replug.
The scanner (this one) is always mounted correctly (usually at /dev/ttyACM0) and communicates by SSI over USB CDC.
I’ve tried monitoring with pyserial’s miniterm and with screen /dev/ttyACM0 9600 but the same problem arises (f.e. screen just says [screen is terminating])
Mind you, everything works well on another computer so I believe it might be an issue with the Jetson rather than the scanner.
In the project I’m trying to run, I use pyserial to interact with the device. Here is an extract of the code to give you an idea of how I use it:
import serial
serial_port = "/dev/ttyACM0"
baud_rate = 9600
with serial.Serial(serial_port, baud_rate, timeout=0.1) as device_serial:
device_serial.flush()
while True:
try:
# read a line from the serial port
barcode_byte_string = device_serial.readline()
if len(barcode_byte_string) > 0:
# convert the byte string to a string and strip the newline character
barcode = barcode_byte_string.decode("utf-8").rstrip()
# publish the barcode to the topic
self.publish_barcode(barcode, serial_port)
except serial.SerialException as e:
# exit with error code 1. This will cause the application to be restarted.
sys.exit(1)
except Exception as e:
break

capture v4l : no capture device - but Video Capture Multiplanar?

I would like to capture images from a camera. I used the usual v4lgrab example (https://www.kernel.org/doc/html/v5.4/media/uapi/v4l/capture.c.html) but fail. I get a message that it is not a capture device.
Taking a closer look it is "Video Capture Multiplanar"
Try to read about but don't understand. Also I am new to V4L, so can someone give me a hint how to go on?
v4l2-dbg -D
Driver info:
Driver name : mxc-isi-cap
Card type : mxc-isi-cap
Bus info : platform:32e00000.isi:cap_devic
Driver version: 5.4.24
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Do I undestand it right, it is a device driver issue, nothing to deal with sensorchip?

How to capture wifi packets with a specific channel using Pyshark?

I use codes below to capture wifi packets, and save the pcap file to a text file.
However in the text file it only shows packets with channel 1, even no channel 2 or more.
I'm using python2.7 and pyshark-0.3.8 .
capture = pyshark.LiveCapture(interface = network_card +'mon',output_file=pathfile +'.pcap')
capture.set_debug()
capture.sniff(timeout = scanner_time)
list = str(capture).split('(')[1]
list1 = list.split(' ')[0]
print(list1)
with open(pathfile +'.txt', 'w') as f:
for pkt in range(int(list1)):
f.write(str(capture[pkt]))
Is there any way to capture from a specific channel not just channel 1?
The image is a part of a packet in the text file which shows current channel.
image
I found this command that can change network card in monitor mode and switch to a certain channel.
sudo airmon-ng start 'network_card' 'channel'
Then run the code in my question, pyshark will search the channel you input.
When you want to stop monitoring, just type below:
sudo airmon-ng stop 'network_card'+'mon'

Pyserial: termios.error: (22, 'Invalid argument') while reading from virtual serial port

Is there any posibility to read from virtual serial ports without mentioned error?
I'm trying to reach data sent from symbol/zebra barcode scanner li4278. Device is working in simple com port emulation mode and it's under /dev/usb/hiddev0 as serial port.
I'm sure that emulation works fine because CuteCom can read from it, and also this simple pyton script works too:
defaultDevice = '/dev/usb/hiddev0'
inDev = open(defaultDevice, 'rb')
while True:
inBytes = inDev.read(1)
for x in inBytes:
print(x)
But anytime I'm trying to read it using pyserial with such a minimal code like this:
with serial.Serial('/dev/usb/hiddev0', timeout=1) as ser:
x = ser.read()
print(x)
the same error occurs: termios.error: (22, 'Invalid argument'). It's like it can't read from virtual serial ports.
And no, setting args to rtscts=True, dsrdtr=True doesn't work.
I have the same '22, invalid argument' error.
Linux Mint 18, 64 bit, Python 3.7, pyserial 3.4.
Anyone knows what's the thing?

PySerial "better" port names for Linux?

Followup question to this: permanent USB port names? (Linux)
On Windows the port names don't change between actual physical ports. They are along the lines of "COM3", "COM6", etc.
On Linux, if I plug one USB device first , it will be "ttyUSB0" and if I plug the same device second in any other physical port it will be "ttyUSB1". That won't work if I want to, say, have 2 Arduinos connected via Pyserial to the PC.
In the above answer I was shown a way to get an IP-like "serial name". How can I feed that to the PySerial class instead?
An example:
import serial
ser = serial.Serial(port = "/dev/USBNAME", baudrate=9600)
ser.close()
ser.open()
if ser.isOpen():
ser.write("test")

Resources