USB Serial driver in Linux and device name - linux

My device is a USB serial device. When I plug in, the cdc_acm.ko driver detects it and a node is created under /dev/ with the device name as ttyACM0. When I do a soft reset, the device appears with the name ttyACM1. Where can I get the information regarding the device name [under /proc/ or /etc]. Currently I am relying on dmesg to detect the device name. Once I intend to automate it, I would like to know where I can get the device name information.

use /proc/devices for reading major number and device name information.
a sample output is attached.
useer#useer-VirtualBox:~$ cat /proc/devices
Character devices:
1 mem
4 /dev/vc/0
4 tty
4 ttyS
5 /dev/tty
5 /dev/console
5 /dev/ptmx
5 ttyprintk
6 lp
7 vcs
10 misc
13 input
Left side integers are major number of the corresponding devices.

Related

Reading from /dev/hidraw1 device connected to linux system

I have a QR/Bar code scanner connected to my linux system, which comes up as /dev/hidraw1 device.
If I do ls -la /dev/hidraw* I get
crw------- 1 root root 248, 0 May 5 10:18 /dev/hidraw0
crw------- 1 root root 248, 1 May 5 11:05 /dev/hidraw1
Whenever I try to read from this device using cat /dev/hidraw1 command I get a lot of junk data along with the encoded data also the it doesn't comes up in a formatted way. Here is the output of one of the QR code
68<,?
.4xml ve7'rsion4="1
..0"4 encod-%in4876g=
"UTF-8"?><PrintLetterB,
.arcod4e&D!'ata"&% ' uid=$"12345,.678",name=
"Rohit 4Ka,
poo.44r,."4 gend&& er=4"M,."4 yob=8"319,93" co
="S
,/O:
Mukesh 4,
Why its not coming in continuous readable string, changing the Baud-rate also didn't made any difference.
Here is the screenshot attached
Yours is a HID device, not an RS-232 one. The protocol it uses is binary. What you really get each time you read() from the device is a HID report, not a text line.
The format of the report varies from device to device. The HID specification mandates that the device publishes a HID report descriptor that describes the format of the report. That is... complicated, but if you only want to work with this particular device you can just look at the read reports and try to deduce what it means.
In my experience, barcode scanners usually contain a small header and then the payload data. The header usually has fields for the barcode type and the length of the data. And since the report size is fixed, but the barcodes are arbitrarily long, long barcodes are split into multiples reports, so there are also flags to signal whether this is a first, continuation or last block.
If you want to post dumps of the device, for further analysis, please do not use cat. Use hexdump -C or od -tx1 or something similar that shows the proper binary data.
Most scanners can be configured as HID device or USB CDC device. Check the manual of your scanner for sth like "USB Interface Configuration" and see if it can be set to USB CDC (or USB Com Port Emulation). If it can, it will attach on linux as /dev/ttyACM* and provide data as a serial stream, which is easier to read.

USB HID ATmega32u4 Arduino - system device ID / name changing from default Arduino Leonardo

I'm building a USB HID device using Arduino Leonardo mini clone, based on ATmega32u4. That particular IC has got a USB controller built in, and turning it in to a HID device is simple. You just need to include Keyboard.h and then use Keyboard.print...
Where can I set/define the name of the device that is shown, when that Arduino is connected to a PC, because at the moment it is named Arduino Leonardo.
The default automated name for tty is usbmodemHIDP1.
In system preferences, I can see:
ID product: 0x8036
ID vendor: 0x2341
Wersion: 1.00
Serial number: HIDPC
Speed: do 12 Mb/sek.
Vendor: Arduino LLC
ID location: 0x14200000 / 16
So where in Arduino is file Keyboard.h? Can I change that name, or ID's?
Is it possible?
Because in my opinion it should be, but I just can't find the right place, and I do not have experience with Arduino AVR as I was working with Microchips Mplab X before for different ICs ;).
The "iProduct" string sent by the board on enumeration tells the operating system to give it the human-readable name. The value of that string is set near the top of USBCore.cpp in hardware/arduino/cores/arduino/. It's a Unicode string, so we need looking for 'L', 'e', 'o', 'n' [...], not "Leonardo". The string used depends on the PID number of the device (also sent during enumeration) which is given in boards.txt.
For distributing own custom hardware based on the Leonardo, there is a need to provide your own VID.
Also there can be used alternative firmware.
The Arduino '32U4 bootloader, Caterina, can be found under hardware/arduino/bootloaders/caterina. It requires LUFA in order to build.

How can you check whether your kernel supports GPIO on your hardware?

My aim is to control the GPIO pins in Peppermint 4 Linux (Kernel version 3.8.0) on an Intel motherboard (NM70 chipset with C1037U processor).
How can you check whether your kernel supports GPIO on your hardware?
Background
Motherboard: Intel with NM70 chipset
Processor: C1037U processor
OS: Peppermint 4 Linux
Kernel version: 3.8.0
GPIO interface: sysfs
I'm attempting to use the sysfs interface, which allows GPIO pins to be accessed from userspace through the filesystem.
I’ve successfully followed the "Alternate Build Method: The Old-Fashioned Debian Way" section of https://help.ubuntu.com/community/Kernel/Compile to recompile the kernel in order to expose GPIO access in user space and to turn on debug mode for GPIO:
Once the new kernel was compiled, I was able to see the GPIO folder in /sys/class/gpio for the first time. Then, in theory, it should be a case of being able to turn GPIO ports ON/OFF by writing to the filesystem. This approach is outlined at http://falsinsoft.blogspot.co.uk/2012/11/access-gpio-from-linux-user-space.html.
When attempting to export pins 0 to 255 by
echo XX > /sys/class/gpio/export
for XX from 0 to 255, I get the following error message
echo: write error: No such device
When attempting to export pins outside the range 0 to 255 by
echo XX > /sys/class/gpio/export
I get the following error message
echo: write error: Invalid argument
The tutorial suggests this could be because the GPIO ports are reserved for another program and that, if so, the debug file (/sys/kernel/debug/gpio) would be able to show where they are reserved.
However, /sys/kernel/debug/gpio is empty.
I can see and control the GPIO pins in the BIOS (change pins to be input or output HIGH/LOW).
Related questions
Under what conditions would /sys/kernel/debug/gpio be empty?
writing to /sys/class/gpio/export failing

Not getting host, id, channel number of scsi

I am writing a program which will print host, channel number, id number, lun of a SCSI device.
cat /proc/scsi/scsi
giving the information about it. But i want print it through c program. I'm getting vendor id, device type, revision level... but not lun , bus no etc.
Is there any ioctl command to get lun, bus, id numbers?
Did you try the ioctls for SCSI generic :
http://sg.danny.cz/sg/p/sg_v3_ho.html#ioctl ?
SCSI_IOCTL_GET_IDLUN, SG_GET_SCSI_ID should do the trick.
I did not use any SCSI HW in the last years though, and I hope the documentation is still valid for current kernels. I don't see any reason to have changed the ioctls though.

Find which drive corresponds to which USB mass storage device in Linux

I have several USB mass storage flash drives connected to a Ubuntu Linux computer (Ubuntu 10.04.1, kernel 2.6.32-25-386), and I need to tell them apart programatically (from bash if possible, but I'm not afraid of compiling either) - I need to find which block device corresponds to which physical device (e.g. /dev/sdb1 -> device in USB port 1; in my case, one device ~ one volume).
In other words, I know that I have three hardware devices plugged into USB ports; each of them shows up in the system as a USB mass storage device (as seen with lsusb), is created as a block device (/dev/sdb1) and automounted by UUID (/media/1234-5678).
USB device block device mountpoint
USB device in port 2.2 <-> /dev/sdb1 <-> /media/1234-5678
I'm not trying to find the relationship between block device and mountpoint; I'm trying to find the relationship between block device and USB device, is there a way?
Why? There will be some writes on the disks, with unpredictable time of completion. I need to give the operator some indication like "you can now remove the disk in port 2 (which is second from the left)". I have found which physical port corresponds to which port number on that specific machine, and finding block devices from mountpoints is simple; now I'm stuck mapping the logical USB ports to block devices.
I can see the disks with lsusb :
Bus 001 Device 058: ID 067b:2517 Prolific Technology, Inc. Mass Storage Device
Bus 001 Device 060: ID 067b:2517 Prolific Technology, Inc. Mass Storage Device
Bus 001 Device 061: ID 067b:2517 Prolific Technology, Inc. Mass Storage Device
and I can see them mounted (by their UUID):
/dev/sdb1 on /media/BC88-15C4 type vfat
/dev/sdc1 on /media/AE54-65AA type vfat
/dev/sdd1 on /media/58D2-FED1 type vfat
Now, all the drives are the same model from the same manufacturer, so I can't distinguish them by that, and I can't guarantee they'll be plugged in a particular order.
I have found /sys/bus/usb/devices (a list of USB devices), but it seems to be the same data that I get from lsusb - I don't see a mapping to disks there.
There's also /sys/block/sdb and /sys/block/sdb/sdb1 (the block device and its first partition; similarly for sdc and sdd), but again, I see no mapping to devices.
I'm not sure in which kernel version this was implemented, but the /sys/block/* entries are symlinks to the devices.
In other words, /sys/block/sdb symlinks to a different directory, and its name contains the USB device ID.
$ file /sys/block/sdb
/sys/block/sdb: symbolic link to `../devices/pci0000:00/0000:00:02.1/usb1/1-1/1-1.1/1-1.1:1.0/host31/target31:0:0/31:0:0:0/block/sdb'
USB version and port here---^^^^^
The 1-1.1 is the interesting part, denoting usb1-port 1.device 1. When plugged into a hub, another level is added: 1-2.3.1, denoting usb1-port 2.port 3.device 1.
Pseudocode:
get partition name # e.g. /dev/sdb1
get disk name # that would be /dev/sdb
get your basename # sdb
see where /sys/block/$your_basename points to # e.g. ../devices/blah/blah/1-2.1/blah
get the longest substring matching "\d-\d+(.\d+)*" # e.g. 1-2.1
that is the device id you want
/sys/bus/usb/devices/$device_id/ has all kinds of information about it
the ID corresponds to hardware USB ports
Working example script in bash.
I use the path:
/sys/bus/usb/drivers/usb-storage/4-1:1.0/host4/target4:0:0/4:0:0:0/block/sda
so you can see usb bus 4, port 1 is connected with a usb storage /dev/sda
Can't you use disk labels?
http://ubuntuforums.org/showthread.php?t=322973
Here is how I do it.
lsusb -v shows all the devices disks get an iserial number take note of them
ls -l /dev/disk | grep [iserial]
Everything in /dev/disk is a symlink so follow the symlink to see the device.

Resources