usb.core.USBTimeoutError: [Errno 110] Operation timed out
Hello,
I would like to read data from USB port connected to USB-to-CAN v2 compact adapter which is also connected to force/torque tactile sensor.
Working environment: Ubuntu 22.04, python 3.10.12, pyusb library
Using pyusb library, I opened the USB port and it seemed there's no problem to write data. But when I tried to read data from the USB port, I got the following errors (USBTimeoutError).
test_usb3.py:None (test_usb3.py)
test_usb3.py:54: in <module>
data = dev.read(epi.bEndpointAddress, epi.wMaxPacketSize, 1000)
../../../.local/lib/python3.10/site-packages/usb/core.py:1029: in read
ret = fn(
../../../.local/lib/python3.10/site-packages/usb/backend/libusb1.py:846: in bulk_read
return self.__read(self.lib.libusb_bulk_transfer,
../../../.local/lib/python3.10/site-packages/usb/backend/libusb1.py:954: in __read
_check(retval)
../../../.local/lib/python3.10/site-packages/usb/backend/libusb1.py:602: in _check
raise USBTimeoutError(_strerror(ret), ret, _libusb_errno[ret])
E usb.core.USBTimeoutError: [Errno 110] Operation timed out
I tested the code with optical USB mouse and there's no problem to read data from the mouse .
I am stuck here.
Must there be some control command to initiate the data transmission to read?
Please help me out.
Thank you.
Sahg-Gyu
-----------------------------------
The following is my test code.
import usb.core
import usb.util
# find a device
dev = usb.core.find(idVendor=0x08d8, idProduct=0x0008) # IXXAT usb-to-can v2
if dev is None:
raise ValueError('Device not found')
dev.set_configuration()
dev.reset()
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0, 0)]
# print('cfg = ', cfg)
print('intf = ', intf)
epi = usb.util.find_descriptor(
intf,
custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
print('epi = ', epi)
assert epi is not None
# write the data
try:
data = dev.read(epi.bEndpointAddress, epi.wMaxPacketSize, 1000)
print('read data = ', data)
except usb.core.USBError:
print('read error')
-
Official comment
Hello Sahg-Gyu,
I see you're working on a low-level USB communication.
Do you want to work with CAN-Bus data?
Then you can use easily SocketCAN.
We have on our web page a SocketCAN driver for the USB-to-CAN V2.
SocketCAN is also supported by the Python-CAN library. This gives you easy CAN handling for Python.
This library you'll find in at Github.
If you really want to use the low-level communication, then you should find the needed information in the SocketCAN drivers which are open source.
SocketCAN driver download:
https://www.hms-networks.com/p/1-01-0281-12001-ixxat-usb-to-can-v2-compact?tab=tab-support
Best regards,
Peter -
Hi Peter,
Thank you for your quick reply.
A tactile sensor is connected to the USB-to-CAN v2 adapter and the adapter is connected to USB port in PC.
What I want to do is to read data from the tactile sensor and apply some signal processing to the data.
Since the tactile sensor is connected to USB port eventually, I tried to read the data using pyusb library.
Now, you recommend to use SocketCAN library and I will try to use this.
BTW, could you recommend a feasible and easier method to read tactile sensor data in Python?
Thank you.
Best regards,
Sahg-Gyu
0 -
Hi again,
Your link for SocketCAN driver leads to 'Support and downloads page' in your homepage.
I downloaded 'SocketCAN Driver for Linux' in the drivers page. The size of the downloaded file 'socketcan-linux.gz' is 392.4kB and the unzipped file has only one file 'socketcan-linux' without any readme file.
How can I proceed with it?
I googled hms.how page (https://forum.hms-networks.com/t/socketcan-driver-for-linux-20-04/70299), downloaded SocketCAN_2_0_378_Modified_PeWu_2022-02-11.tar (3.6 MB) file and installed the file.
Now, I can see can0 device thru 'ip link list' command.
Is this correct way to go?
Ubuntu 22.04, Kernel version: 6.8.0-40-generic
Thank you.
Best regards,
Sahng-Gyu
0 -
Hello Sahng-Gyu,
you're right. When I try to unpack this gz file with "gzip -d" I see the same file without extension.
Please use:
$ tar -xf socketcan-linux_V2_0_561.gz
Then you have a list of files there:ix_active_can_2.0.556-REL.tgz
ix_passive_can_2.0.561-REL.tgz
ix_passive_canfd_2.0.556-REL.tgz
IX_SECUREBOOT_1.0.307-REL.tgz
IX_SocketCAN-example_1.0.492-REL.tgz
ix_usb_can_2.0.520-REL.tgz
README.mdNow you can select the CAN interface type you want to use. In your case USB-to-CAN V2.
Here a command sequence to create a own subdirectory to the USB-to-CAN drivers, unpack it there:$ mkdir ix_usb_can_2.0.520
$ mv ix_usb_can_2.0.520-REL.tgz ./ix_usb_can_2.0.520
$ cd ix_usb_can_2.0.520/
$ tar -xf ix_usb_can_2.0.520-REL.tgz
$ rm ix_usb_can_2.0.520-REL.tgzThe sequence how to install it:
$ make
$ sudo make installTest if the USB-to-CAN V2 was successfully installed:
$ ip a
Now you should have an entry like this:
5: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN group default qlen 10
Best regards,
Peter0 -
Hello Sahng-Gyu,
working with SocketCAN and can-utils.
Here is the SocketCAN web page: https://docs.kernel.org/networking/can.html
There is all needed information about it.
For easy use from the shell, I recommend using the can-utils.
It's a set of great tools, please find the sources and documentation here:
https://github.com/linux-can/can-utils
Install the can-utils:
$ sudo apt install can-utilsNow you can initialize and start the CAN controller, the example uses 500 kBit/s as baud rate:
$ sudo ip link set can0 up type can bitrate 500000Show CAN traffic:
$ candump can0Send a CAN message:
$ cansend can0 123#010203
You'll find a lot of information on the web sites above and also by search the Internet.
Best regards,
Peter0 -
Hello Sahng-Gyu,
use SocketCAN in Python.
There is great library using CAN in the Python environment: python-can
Here you'll find documentation about it:
https://python-can.readthedocs.io/en/stable/
Best regards,
Peter0 -
Hi Peter,
Thank you again for your replies.
I followed your instruction to install socketCan.
I got the following results after the installation.
$ip a
5: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN group default qlen 10
link/can 48:57:37:31:37:39:34:35:00:00:00:00:00:00:00:00 brd 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00--> O.K.
$ sudo ip link set can0 up type can bitrate 500000
--> O.K.
$candump can0
--> nothing to display (Not O.K.)
So, I tried to see the followings.
$ifconfig
can0: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 48-57-37-31-37-39-34-35-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 2 bytes 16 (16.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1 bytes 3 (3.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0--> TX packet number is increasing as I input 'cansend can0 123#010203, but RX packet number is not changing.
$ip a
: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP group default qlen 10
link/can 48:57:37:31:37:39:34:35:00:00:00:00:00:00:00:00 brd 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00----------------------
'candump can0' does not display anything. Data read must have a problem. I don't know why.
Do I need to trigger the adapter to start data transmission?
I looked over some example codes. But I couldn't find any code to trigger the data transmission.
Thank you.
Best regards,
Sahng-Gyu
0 -
Hi Sahng-Gyu,
you can use loopback messages. Then the sent messages are routed back to the receive queue, and you'll see it.
$ sudo ip link set can0 up type can bitrate 500000 loopback onNotes about CAN-bus behavior:
All nodes in the CAN-bus network must have the same baud rate.
At the 2 physical ends of the CAN-bus a 120 Ohm resistor must be placed between CAN-High and CAN-Low.
CAN nodes need at least one other CAN node which acknowledges sent messages.
Else the CAN node will retransmit the message till it is stopped or another node is available.At my test I did not see an acknowledge error in the "candump" terminal.
But the CAN LED on the USB-to-CAN V2 flashes red.
In the moment I add another CAN node the red led stops, and I see the message in candump.Best regards,
Peter0 -
Hi Peter,
I connected two USB-to-CAN v2 adapters to PC and wired CAN-High and CAN-Low pins together between two DB9 connectors to make loopback path and tested the loopback message's sending and receiving.
I succeeded to see loopback messages between two adapters. Now, I know there's no problem in the adapter.
But, I cannot still get any data from force/torque sensor connected to the USB-to-CAN v2 adapter.
There must be some mismatch in the adapter setting. Do you have any suggestion to set up the adapter parameters to read data from the sensor? Maybe adapter's bitrate?
Thank you.
Best regards,
Sahng-Gyu
0 -
Hi Sahng-Gyu,
I wrote above about that acknowledge flag.
You can use 1 CAN channel of the USB-to-CAN V2 and connect it to your sensor.
Don't forget the terminating resistors.
Then you send one single CAN messages. If it is acknowledged, then the sensor CAN is active and has the same baud rate. If it the USB-to-CAN V2 has an acknowledge error, then there is no reaction from the sensor. If you see something like form errors or bus off, then you have maybe invalid baud rates. And bus off state can be also a cabling problem.
Normally in the description of the sensor you should find more information about CAN connection and baud rates.
If you have an oscilloscope then you can check the signals CAN-High - CAN Ground, and CAN-Low - CAN Ground.If you don't like to share in public the sensor information, then we can communicate also in a closed support issue. This you can create here: mysupport.hms.se
Best regards,
Peter0 -
Hi Peter,
The problem has been solved now.
I checked the bitrate of force sensor connected to the USB-to-CAN v2 adapter by using oscilloscope and it was 1MHz.
I tried to change adapter's bitrate using 'sudo ip link set can0 up type can bitrate 500000' hundreds times before. 1MHz bitrate was included in the test setting, but, it didn't work.
What needed was to reset sensor by turn-off and on the power beforehand and set the correct bitrate.
It took quite long time to find out this setup sequence.
Now, I can see the beautiful scroll of numbers from the sensor through 'candump can0' command.
Your guide was very kind and helpful. I appreciate your help much.
Best regards,
Sahng-Gyu
0 -
Hi Sahng-Gyu,
thank you for sharing the result. Then bitrate 1000000 should be the correct setting.
As it is a public forum maybe it can be helping others to bring up their systems.
Then enjoy working with CAN which is an easy to use and robust field bus.
Best regards,
Peter0
Please sign in to leave a comment.
Comments
12 comments