dpenkler / linux-usbtmc

Experimental linux usbtmc driver
GNU General Public License v2.0
21 stars 12 forks source link

Timeout #3

Closed anantapalani closed 3 years ago

anantapalani commented 6 years ago

We have a Thorlabs CLD1010LP laser driver that we want to control over USB. We are able to do so with pyVISA and the pyVISA-py pure python driver (uses pyUSB backed by libusb). However, with the linux usbtmc kernel driver we are getting timeouts. Here is the dmesg log immediately after plugging in the device:

user@machine:~$ sudo dmesg --clear
user@machine:~$ dmesg
[  424.730305] usbtmc: Experimental driver version 1.1 unloaded
[  433.586940] usb 1-8: new full-speed USB device number 12 using xhci_hcd
[  438.736767] usb 1-8: New USB device found, idVendor=1313, idProduct=804f
[  438.736769] usb 1-8: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  438.736770] usb 1-8: Product: CLD1010LP
[  438.736772] usb 1-8: Manufacturer: Thorlabs
[  438.736773] usb 1-8: SerialNumber: M00420016
[  438.737361] usbtmc 1-8:1.0: usbtmc_probe called
[  438.737361] usbtmc: Experimental driver version 1.1 loaded
[  438.737362] usbtmc: Params: io_buffer_size = 2048, usb_timeout = 5000
[  438.737364] usbtmc 1-8:1.0: Trying to find if device Vendor 0x1313 Product 0x804F has the RIGOL quirk
[  438.737366] usbtmc 1-8:1.0: Found bulk in endpoint at 130
[  438.737367] usbtmc 1-8:1.0: Found Bulk out endpoint at 2
[  438.737368] usbtmc 1-8:1.0: Found Int in endpoint at 129
[  438.737476] usb 1-8: GET_CAPABILITIES returned 1
[  438.737477] usb 1-8: Interface capabilities are 4
[  438.737478] usb 1-8: Device capabilities are 1
[  438.737479] usb 1-8: USB488 interface capabilities are 6
[  438.737480] usb 1-8: USB488 device capabilities are f
[  438.737535] usbtmc 1-8:1.0: Using minor number 0

And the log after trying to cat /dev/usbtmc0:

user@machine:~$ sudo dmesg --clear
user@machine:~$ sudo cat /dev/usbtmc0
cat: /dev/usbtmc0: Connection timed out
user@machine:~$ dmesg
[  479.122503] usbtmc 1-8:1.0: usb_bulk_msg_in: remaining(131072), count(131072)
[  483.946882] usbtmc 1-8:1.0: usb_bulk_msg: retval(4294967186), done(0), remaining(131072), actual(0)
[  483.946884] usbtmc 1-8:1.0: Unable to read data, error -110
user@machine:~$ 

Do you have any idea where this timeout is occurring or how we can further debug this?

Thanks!

GuidoKiener commented 6 years ago

Ananta,

I'm not familiar with your CLD101LP, but I can imagine that you first should send a query to the device, e.g. echo "*idn?" > /dev/usbtmc0 before you can read a response with cat /dev/usbtmc0. Please look at the example code ttmc.c how you can send/receive messages to a T&M instrument.

Guido

anantapalani commented 6 years ago

Guido,

I had tried sending data before, the error is basically the same:

[ 1934.930920]  usbtmc 1-8:1.0: Unable to send data, error -110

My understanding was the /dev/usbtmc0 was for controlling the driver and that a usbtmc1 device should have been created for talking with the device?

-Ananta

GuidoKiener commented 6 years ago

Ananta,

Previous driver versions of Agilent driver were using /dev/usbtmc0 to control the driver. The current Linux driver starts enumeration with 0 and controls your device with /dev/usbtmc0.

Guido

anantapalani commented 6 years ago

Guido,

Thanks for the info. However, the problem still remains that I cannot write or read to the device using the kernel module, but using pyVISA-py pure python driver with libusb I can. Is there nothing else that can be done to debug the timeout?

-Ananta

GuidoKiener commented 6 years ago

Ananta,

After using libusb the usbtmc driver is disabled. You need to reconnect your USB cable to activate the usbtmc driver again. Maybe you want to try my current driver https://github.com/GuidoKiener/linux-usbtmc, then I could better help you.

A udev rule like KERNEL=="usbtmc[0-9]", MODE="0666", GROUP="users" e.g. in /etc/udev/rules.d/50-myrules.rules

helps to to get the I/O access for users. Maybe your device needs a reboot after a lot of experiments, since it is already in an error state.

Regards,

Guido

anantapalani commented 6 years ago

Guido,

Apologies, using ttmc.c I am able to query *IDN? and get a response. However, after running ttmc one to three times, the device starts timing out and i get 'failed to read from scope: Connection timed out' errors from ttmc. Unplugging/replugging the USB cable is sufficient to get ttmc to work again, so I don't think the device is entering an error state.

-Ananta

GuidoKiener commented 6 years ago

Ananta,

Hmm, this is not a very stable connection. Well, on Ubuntu 16.04 there are problems within the USB stack. Which Linux kernel (and distribution) do you use? Of course I'm interested to make a stable usbtmc driver for Linux, but can you also test your device with Windows and a VISA from known vendors?

-Guido

anantapalani commented 6 years ago

Guido,

We're using Kubuntu 17.04 with kernel 4.10.0-42-generic. We've tested the device under Windows using NI-VISA and the connection is very stable. I was mistaken about the one to three times sequentially running ttmc. I've re-tested throughly, and after a single run of ttmc, every following call to ttmc times out. I've stripped down ttmc.c to only:

  1. open the device
  2. ioctl clear
  3. send clear status
  4. send identity query
  5. close device

so there is not much to go wrong. I have the udev rule in place as you suggested.

-Ananta

GuidoKiener commented 6 years ago

Ananta,

Ok, the newer kernel should work and I'm curious about the problem you have with this device. If you like we can track down the problem the next days.

Please try my driver and use the test-raw.c (make test-raw) executable and send me the output and dmesg output for analysis. Please use the direct mail address usbtmc@kiener-muenchen.de for this troubleshooting.

-Guido

anantapalani commented 6 years ago

Guido,

Thank you for your help. I've e-mailed the files.

-Ananta