stockton
Posts: 136
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa
Contact: Website

Addressing a USB port

Sun Jul 08, 2018 9:10 am

If I dmesg | grep usb I get

Code: Select all

[    2.190960] usb 1-1.2: New USB device found, idVendor=0665, idProduct=5161
[    2.190980] usb 1-1.2: New USB device strings: Mfr=3, Product=1, SerialNumber=0
[    2.203838] hid-generic 0003:0665:5161.0001: hiddev96,hidraw0: USB HID v1.11 Device [HID 0665:5161] on usb-3f980000.usb-1.2/input0
[    2.312407] usb 1-1.4: new high-speed USB device number 5 using dwc_otg
[    2.444003] usb 1-1.4: New USB device found, idVendor=0bda, idProduct=8176
[    2.444022] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    2.444033] usb 1-1.4: Product: 802.11n WLAN Adapter
[    2.444043] usb 1-1.4: Manufacturer: Realtek
[    2.444053] usb 1-1.4: SerialNumber: 00e04c000001
[    4.404444] usbcore: registered new interface driver rtl8192cu
which looks like the device I would like to access but

Code: Select all

import serial
serialData = serial.Serial('/dev/ttyS5',115200); #//  ACM0',115200); 
# Body of data acquisition code
while True:
    line = serialData.read(256);
    print ("Line = ",line);
gives me

Code: Select all

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyS5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./readusb.py", line 2, in <module>
    serialData = serial.Serial('/dev/ttyS5',115200); #//  ACM0',115200); 
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 236, in __init__
    self.open()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyS5: [Errno 2] No such file or directory: '/dev/ttyS5'

Please tell me what I should use to address that port?

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Addressing a USB port

Sun Jul 08, 2018 9:16 am

There seem to be 2 usb devices listed in your summary.

Neither appears to be a serial port device, so using the Python serial library may not be appropriate.

What is the device that you expect to be addressed by /dev/ttyS5?

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Addressing a USB port

Sun Jul 08, 2018 9:18 am

I may be missing something but how do you conclude that /dev/ttyS5 is the device you're looking for?

stockton
Posts: 136
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa
Contact: Website

Re: Addressing a USB port

Sun Jul 08, 2018 9:28 am

The line from dmesg | grep USB reading
"new high-speed USB device number 5 using dwc_otg"
made me think of /devb/ttyS5

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Addressing a USB port

Sun Jul 08, 2018 9:51 am

stockton wrote:
Sun Jul 08, 2018 9:28 am
The line from dmesg | grep USB reading
"new high-speed USB device number 5 using dwc_otg"
made me think of /devb/ttyS5
It does not work like that.
Normally the device ID is listed in the log, somewhere near the device detection message.

You can also try to plug in the device after booting the Pi. Then look at the last few log entries with dmesg to see which device was allocated

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Addressing a USB port

Sun Jul 08, 2018 9:57 am

stockton wrote:
Sun Jul 08, 2018 9:28 am
The line from dmesg | grep USB reading
"new high-speed USB device number 5 using dwc_otg"
made me think of /devb/ttyS5

It goes on to identify it as a Realtek Wlan adaptor:

Code: Select all

[    2.312407] usb 1-1.4: new high-speed USB device number 5 using dwc_otg
[    2.444003] usb 1-1.4: New USB device found, idVendor=0bda, idProduct=8176
[    2.444022] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    2.444033] usb 1-1.4: Product: 802.11n WLAN Adapter
[    2.444043] usb 1-1.4: Manufacturer: Realtek
[    2.444053] usb 1-1.4: SerialNumber: 00e04c000001

stockton
Posts: 136
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa
Contact: Website

Re: Addressing a USB port

Sun Jul 08, 2018 1:34 pm

I missed seeing the WLAN adapter. Sorry.
So how does one without rebooting, identify USB devices?
I've tried grep -iR usb /var/log/messages and syslog as well as
grep -iR tty on both files. All without success.

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Addressing a USB port

Sun Jul 08, 2018 1:36 pm

stockton wrote:
Sun Jul 08, 2018 1:34 pm
So how does one without rebooting, identify USB devices?
See my post above... (plug in after boot, then check last lines of log using dmesg, don't use grep!)

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Addressing a USB port

Sun Jul 08, 2018 1:39 pm

Also, use the lsusb command (That's LSUSB in lower-case) before and after and see what has changed.

User avatar
topguy
Posts: 6491
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Addressing a USB port

Sun Jul 08, 2018 7:36 pm


stockton
Posts: 136
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa
Contact: Website

Re: Addressing a USB port

Mon Jul 09, 2018 7:51 am

topguy you reply bears no fruit. It does not work.

User avatar
topguy
Posts: 6491
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Addressing a USB port

Mon Jul 09, 2018 10:01 am

I just asked if it was relevant.,
You havent really told us what kind of device you have so I had to google the vendorId/productId to try to find out.

What did you try ? Windows and the tool from Cypress ?
So is this a seperate usb2serial device or is at a part of a bigger unit like an UPS ?

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Addressing a USB port

Mon Jul 09, 2018 5:08 pm

Example of the output of dmesg when I connect an USB 2 serial device.

Code: Select all

[Mon Jul  9 17:58:12 2018] usb 1-1.1: new full-speed USB device number 5 using dwc_otg
[Mon Jul  9 17:58:12 2018] usb 1-1.1: New USB device found, idVendor=067b, idProduct=2303
[Mon Jul  9 17:58:12 2018] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[Mon Jul  9 17:58:12 2018] usb 1-1.1: Product: USB-Serial Controller
[Mon Jul  9 17:58:12 2018] usb 1-1.1: Manufacturer: Prolific Technology Inc.
[Mon Jul  9 17:58:12 2018] pl2303 1-1.1:1.0: pl2303 converter detected
[Mon Jul  9 17:58:12 2018] usb 1-1.1: pl2303 converter now attached to ttyUSB1
As you can see it says it's attached to /dev/ttyUSB1
Output of lsusb for this device:

Code: Select all

Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
I connected the device after booting so that the log messages would show at the end of the log. No need to use grep (which may cause messages to get lost if it doesn't contain the search string).

So does your mystery device show up with lsusb and / or dmesg?

Return to “Python”