python-ivi / python-usbtmc

Provides a USBTMC driver for controlling instruments over USB
MIT License
160 stars 69 forks source link

usbtmc Access Denied #33

Closed macdroid53 closed 7 years ago

macdroid53 commented 7 years ago

Hi, sudo usbtmc-shell --backend python_usbtmc USB::0x1ab1::0x0588::INSTR Runs fine, without sudo I get access denied. I added the udev rule, added group usbtmc, added usbtmc group to user. Running Ubuntu 16.04. I'm assuming I did something wrong... :(

alexforencich commented 7 years ago

Did you reload udev rules and re-plug the device? Did you log out and log in again so the new group membership takes effect? Or reboot?

macdroid53 commented 7 years ago

First tried unplug/plug, then logout/login, then reboot.

On Wed, May 17, 2017 at 9:35 AM, Alex Forencich notifications@github.com wrote:

Did you reload udev rules and re-plug the device? Did you log out and log in again so the new group membership takes effect? Or reboot?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-302091823, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iCnr7HnQP7RQzd8iIK3EGztlVoLhks5r6veTgaJpZM4Nd2oj .

alexforencich commented 7 years ago

OK. What are the device permissions in /dev/bus/usb?

macdroid53 commented 7 years ago

Permissions shown below.

But, after my last email, I unplugged, rebooted, then plugged...now non-sudo works. :/

ls -la /dev/bus/usb total 0 drwxr-xr-x 4 root root 80 May 17 09:43 . drwxr-xr-x 3 root root 60 May 17 09:43 .. drwxr-xr-x 2 root root 180 May 17 09:47 001 drwxr-xr-x 2 root root 60 May 17 09:43 002

PS: USB::0x1ab1::0x0588::INSTR is for a Rigol DS1102D scope (I note you have other Rigols in usbtmc.rules https://github.com/python-ivi/python-usbtmc/blob/master/usbtmc.rules

On Wed, May 17, 2017 at 9:49 AM, Alex Forencich notifications@github.com wrote:

OK. What are the device permissions in /dev/bus/usb?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-302095743, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iO0N-06Tw5QFu_mo9oT7UEJs2Sl7ks5r6vrPgaJpZM4Nd2oj .

alexforencich commented 7 years ago

I need the permissions of the device itself, not the hub. Run lsusb to figure out what the bus number is, cd into that folder, and run ls -a there. That should show the current owner, group, and permissions of the device.

macdroid53 commented 7 years ago

Oh.ok its bus 1 device 7

ls -la total 0 drwxr-xr-x 2 root root 180 May 17 09:47 . drwxr-xr-x 4 root root 80 May 17 09:43 .. crw-rw-r-- 1 root root 189, 0 May 17 09:43 001 crw-rw-r-- 1 root root 189, 1 May 17 09:43 002 crw-rw-r-- 1 root root 189, 2 May 17 09:43 003 crw-rw-r-- 1 root root 189, 3 May 17 09:43 004 crw-rw-r-- 1 root root 189, 4 May 17 09:43 005 crw-rw-r-- 1 root root 189, 5 May 17 09:43 006 crw-rw---- 1 root usbtmc 189, 6 May 17 10:02 007

On Wed, May 17, 2017 at 10:07 AM, Alex Forencich notifications@github.com wrote:

I need the permissions of the device itself, not the hub. Run lsusb to figure out what the bus number is, cd into that folder, and run ls -a there. That should show the current owner, group, and permissions of the device.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-302101280, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iFxfRuLOh_MHCkB1AQ2anEnBTzrYks5r6v8qgaJpZM4Nd2oj .

alexforencich commented 7 years ago

So the permissions on that look correct - group writeable, group set to usbtmc. Is it still not working?

macdroid53 commented 7 years ago

Umm...it is working.

In the previous email I noted that after unplugging, rebooting, and then plugging,NON-sudo now works. :)

The only difference was, I plugged it in after rebooting. Not sure why that fixed it...

On Wed, May 17, 2017 at 10:31 AM, Alex Forencich notifications@github.com wrote:

So the permissions on that look correct - group writeable, group set to usbtmc. Is it still not working?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-302109042, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iMdegN60GPDWH25VTNl4IqjqPrR9ks5r6wTGgaJpZM4Nd2oj .

alexforencich commented 7 years ago

Ah, I see. Good to hear that it appears to be working now.

macdroid53 commented 7 years ago

Sorry I didn't get it before I posted the GITHUB issue.

On Wed, May 17, 2017 at 11:06 AM, Alex Forencich notifications@github.com wrote:

Ah, I see. Good to hear that it appears to be working now.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-302120224, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iJO4JSKaRrxkDebbjWRvxrBHRtrwks5r6wztgaJpZM4Nd2oj .

alexforencich commented 7 years ago

No worries!

macdroid53 commented 7 years ago

Hi Alex,

Sorry to raise my hand again...

I now seem to have the scope working consistently. I.e. it's there and I can access it all the time.

But, I can't seem to get to the second Rigol device (a DG1022).

It shows up on lsusb:

lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 004: ID 046d:c52f Logitech, Inc. Unifying Receiver Bus 001 Device 014: ID 1ab1:0588 Rigol Technologies DS1000 SERIES Bus 001 Device 003: ID 2001:f103 D-Link Corp. DUB-H7 7-port USB 2.0 hub Bus 001 Device 002: ID 1c7a:0603 LighTuning Technology Inc. Bus 001 Device 008: ID 8087:0a2a Intel Corp. Bus 001 Device 006: ID 5986:066d Acer, Inc Bus 001 Device 016: ID 0400:09c4 National Semiconductor Corp. Rigol Technologies DG1022 Arbitrary Waveform Generator Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Even from code:

import usbtmc print(usbtmc.list_devices())

produces: import usbtmc print(usbtmc.list_devices())

But:

open scope

oscope = usbtmc.Instrument(0x1ab1, 0x0588) print(oscope.ask("*IDN?"))

initial settings

open Function generator

funcgen = usbtmc.Instrument(0x0400, 0x09c4) print(funcgen.ask("*IDN?"))

produces: Traceback (most recent call last): File "/home/mac/SharedData/PycharmProjs/RigolScope/ResponseMeasure.py", line 24, in print(funcgen.ask("IDN?")) File "/usr/local/lib/python3.5/dist-packages/usbtmc/usbtmc.py", line 753, in ask self.write(message, encoding) File "/usr/local/lib/python3.5/dist-packages/usbtmc/usbtmc.py", line 733, in write self.write_raw(str(message).encode(encoding)) File "/usr/local/lib/python3.5/dist-packages/usbtmc/usbtmc.py", line 599, in write_raw self.open() File "/usr/local/lib/python3.5/dist-packages/usbtmc/usbtmc.py", line 434, in open self.device.set_configuration(self.cfg) File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 869, in set_configuration self._ctx.managed_set_configuration(self, configuration) File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 102, in wrapper return f(self, args, *kwargs) File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 147, in managed_set_configuration self.managed_open() File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 102, in wrapper return f(self, args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 120, in managed_open self.handle = self.backend.open_device(self.dev) File "/usr/local/lib/python3.5/dist-packages/usb/backend/libusb1.py", line 786, in open_device return _DeviceHandle(dev) File "/usr/local/lib/python3.5/dist-packages/usb/backend/libusb1.py", line 643, in init _check(_lib.libusb_open(self.devid, byref(self.handle))) File "/usr/local/lib/python3.5/dist-packages/usb/backend/libusb1.py", line 595, in _check raise USBError(_strerror(ret), ret, _libusb_errno[ret]) usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

But, the bus doesn't have the usbtmc group (see #16):

/dev/bus/usb/001$ ls -la total 0 drwxr-xr-x 2 root root 200 May 22 19:11 . drwxr-xr-x 4 root root 80 May 22 18:30 .. crw-rw-r-- 1 root root 189, 0 May 22 18:53 001 crw-rw-r-- 1 root root 189, 1 May 22 18:53 002 crw-rw-r-- 1 root root 189, 2 May 22 18:53 003 crw-rw-r-- 1 root root 189, 3 May 22 18:53 004 crw-rw-r-- 1 root root 189, 5 May 22 18:53 006 crw-rw-r-- 1 root root 189, 7 May 22 18:53 008 crw-rw---- 1 root usbtmc 189, 13 May 22 19:07 014 crw-rw-r-- 1 root root 189, 15 May 22 19:11 016

This is what I put in the rules file:

USBTMC instruments

Rigol DS1120D

SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="1ab1", ATTRS{idProduct}=="0588", GROUP="usbtmc", MODE="0660" SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="0400", ATTRS{idProduct}=="09C4", GROUP="usbtmc", MODE="0660"

Devices

KERNEL=="usbtmc/", MODE="0660", GROUP="usbtmc" KERNEL=="usbtmc[0-9]", MODE="0660", GROUP="usbtmc"

Any ideas?

Thanks,

Mac

On Wed, May 17, 2017 at 12:24 PM, Alex Forencich notifications@github.com wrote:

No worries!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-302144343, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iNL4gMukyVfXwbyy81GoUSnJTLigks5r6x9KgaJpZM4Nd2oj .

alexforencich commented 7 years ago

idVendor and idProduct are case-sensitive, I think.

macdroid53 commented 7 years ago

hmm...Ok, I'll change that and try again sometime tomorrow.

On May 22, 2017 7:37 PM, "Alex Forencich" notifications@github.com wrote:

idVendor and idProduct are case-sensitive, I think.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-303248819, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iKBrcGd_CxDtLt5l4vQ5wNpRKyytks5r8hxVgaJpZM4Nd2oj .

macdroid53 commented 7 years ago

Good morning.

I fixed the case in the udev rule and it behaves now when plugging in and the access error is gone.

But, when I access the instrument, it times out. The device shows that it goes into remote mode on its display, does not respond to the *IDN?.

Pertinent parts of code:

import usbtmc print(usbtmc.list_devices())

open scope

oscope = usbtmc.Instrument(0x1ab1, 0x0588) print(oscope.ask("*IDN?"))

initial settings

open Function generator

funcgen = usbtmc.Instrument(0x0400, 0x09c4) print(funcgen.ask("*IDN?"))

Output:

[<DEVICE ID 1ab1:0588 on Bus 001 Address 007>, <DEVICE ID 0400:09c4 on Bus 001 Address 008>] Rigol Technologies,DS1102D,DS1EA113100571,00.04.02.01.00 Traceback (most recent call last): File "/home/mac/SharedData/PycharmProjs/RigolScope/ResponseMeasure.py", line 24, in print(funcgen.ask("*IDN?")) File "/usr/local/lib/python3.5/dist-packages/usbtmc/usbtmc.py", line 754, in ask return self.read(num, encoding) File "/usr/local/lib/python3.5/dist-packages/usbtmc/usbtmc.py", line 737, in read return self.read_raw(num).decode(encoding).rstrip('\r\n') File "/usr/local/lib/python3.5/dist-packages/usbtmc/usbtmc.py", line 656, in read_raw resp = self.bulk_in_ep.read(read_len+USBTMC_HEADER_SIZE+3, timeout=self._timeout_ms) File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 402, in read return self.device.read(self, size_or_buffer, timeout) File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 988, in read self.get_timeout(timeout)) File "/usr/local/lib/python3.5/dist-packages/usb/backend/libusb1.py", line 833, in bulk_read timeout) File "/usr/local/lib/python3.5/dist-packages/usb/backend/libusb1.py", line 936, in read _check(retval) File "/usr/local/lib/python3.5/dist-packages/usb/backend/libusb1.py", line 595, in _check raise USBError(_strerror(ret), ret, _libusb_errno[ret]) usb.core.USBError: [Errno 110] Operation timed out

Note: same error when this is typed in a terminal: usbtmc-shell --backend python_usbtmc USB::0x0400::0x09c4::INSTR

On Mon, May 22, 2017 at 8:17 PM, Mac macdroid53@gmail.com wrote:

hmm...Ok, I'll change that and try again sometime tomorrow.

On May 22, 2017 7:37 PM, "Alex Forencich" notifications@github.com wrote:

idVendor and idProduct are case-sensitive, I think.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-303248819, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iKBrcGd_CxDtLt5l4vQ5wNpRKyytks5r8hxVgaJpZM4Nd2oj .

alexforencich commented 7 years ago

Rigol instruments do not currently implement standards-compliant USBTMC, and they reuse PIDs across many instruments, making it infeasible to reverse-engineer and implement instrument-specific quirks, as each instrument seems to screw up the implementation in different ways. I would recommend using an alternative remote interface, if possible. Their ethernet interfaces seem to have fewer bugs.

macdroid53 commented 7 years ago

Unfortunately, the DG1022 has only usb. :(

Oh, well, maybe I'll try sending various thnings and see if I can figure it out...

Thanks for all the elp though!

Mac

On Tue, May 23, 2017 at 9:11 AM, Alex Forencich notifications@github.com wrote:

Rigol instruments do not currently implement standards-compliant USBTMC, and they reuse PIDs across many instruments, making it infeasible to reverse-engineer and implement instrument-specific quirks, as each instrument seems to screw up the implementation in different ways. I would recommend using an alternative remote interface, if possible. Their ethernet interfaces seem to have fewer bugs.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-303392821, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iE4aeTE6WjK3Sei0MXMhMGqf8GJ_ks5r8tr1gaJpZM4Nd2oj .

alexforencich commented 7 years ago

Yeah, I'm not sure what the issue would be, but it won't be with the syntax of the command, it will be in how the underlying protocol works. So that would mean going and digging around in usbtmc.py. Unforunately, this is a rather difficult issue to work out as there isn't much feedback beyond the command timing out. Probably the only way to make it work would be to capture instrument communication with the rigol provided driver with wireshark and then figure out what it is that the instrument wants to see. However, it's supposed to be USBTMC, and the driver I have follows the USBTMC spec, so the really correct solution is to yell at Rigol until they release a new firmware that actually implements USBTMC correctly.

macdroid53 commented 7 years ago

Hi Alex,

So, I messed with the Rigol function generator some, but basically its a lost cause. They have a new model, so aren't very interested in fixing the older.

I have now been looking at the Rigol DS1102D that I have. It appears to work as long as the program is running. If I attempt to run again, it times out on any function. But if I unplug the usb and re-plug the program runs again.

Would you guess this is the Rigol quirk is see handled in usbtmc.py or some other usb issue? THe re-plug makes me think the connection is just not being closed correctly, even though I do call the usbtmc close().

Regards,Mac

On Tue, May 23, 2017 at 10:50 AM, Alex Forencich notifications@github.com wrote:

Yeah, I'm not sure what the issue would be, but it won't be with the syntax of the command, it will be in how the underlying protocol works. So that would mean going and digging around in usbtmc.py. Unforunately, this is a rather difficult issue to work out as there isn't much feedback beyond the command timing out. Probably the only way to make it work would be to capture instrument communication with the rigol provided driver with wireshark and then figure out what it is that the instrument wants to see. However, it's supposed to be USBTMC, and the driver I have follows the USBTMC spec, so the really correct solution is to yell at Rigol until they release a new firmware that actually implements USBTMC correctly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-ivi/python-usbtmc/issues/33#issuecomment-303422808, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg-iMxg6dI27mHJtqsyCrJdejB15F5jks5r8vI3gaJpZM4Nd2oj .