Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:python-usbtmc:readme [2013/08/08 02:19] alex [Installation] |
en:python-usbtmc:readme [2013/12/17 08:22] (current) alex |
||
---|---|---|---|
Line 4: | Line 4: | ||
Python USBTMC provides a pure Python USBTMC driver for controlling instruments over USB. | Python USBTMC provides a pure Python USBTMC driver for controlling instruments over USB. | ||
+ | |||
+ | ===== Requirements ===== | ||
+ | |||
+ | * Python 2 or Python 3 | ||
+ | * PyUSB | ||
===== Installation ===== | ===== Installation ===== | ||
Line 9: | Line 14: | ||
Extract and run | Extract and run | ||
- | # python setup.py install | + | <code> |
+ | # python setup.py install | ||
+ | </code> | ||
===== Configuring udev ===== | ===== Configuring udev ===== | ||
Line 15: | Line 22: | ||
If you cannot access your device without running your script as root, then you may need to create a udev rule to properly set the permissions of the device. First, connect your device and run lsusb. Find the vendor and product IDs. Then, create a file /etc/udev/rules.d/usbtmc.rules with the following content: | If you cannot access your device without running your script as root, then you may need to create a udev rule to properly set the permissions of the device. First, connect your device and run lsusb. Find the vendor and product IDs. Then, create a file /etc/udev/rules.d/usbtmc.rules with the following content: | ||
- | # USBTMC instruments | + | <code> |
- | + | # USBTMC instruments | |
- | # Agilent MSO7104 | + | |
- | SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="0957", ATTRS{idProduct}=="1755", GROUP="usbtmc", MODE="0660" | + | # Agilent MSO7104 |
+ | SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="0957", ATTRS{idProduct}=="1755", GROUP="usbtmc", MODE="0660" | ||
+ | </code> | ||
substituting the correct idVendor and idProduct from lsusb. You will also need to create the usbtmc group and add yourself to it or substitute another group of your choosing. It seems that udev does not allow 0666 rules, usually overriding the mode to 0664, so you will need to be a member of the associated group to use the device. | substituting the correct idVendor and idProduct from lsusb. You will also need to create the usbtmc group and add yourself to it or substitute another group of your choosing. It seems that udev does not allow 0666 rules, usually overriding the mode to 0664, so you will need to be a member of the associated group to use the device. | ||
Line 24: | Line 33: | ||
If you want to put the kernel usbtmc device in the same group, add the following content to the usbtmc.rules file as well. This is optional as Python USBTMC bypasses and disconnects the kernel usbtmc driver and the device will actually disappear from /dev when Python USBTMC connects. | If you want to put the kernel usbtmc device in the same group, add the following content to the usbtmc.rules file as well. This is optional as Python USBTMC bypasses and disconnects the kernel usbtmc driver and the device will actually disappear from /dev when Python USBTMC connects. | ||
- | # Devices | + | <code> |
- | KERNEL=="usbtmc/*", MODE="0660", GROUP="usbtmc" | + | # Devices |
- | KERNEL=="usbtmc[0-9]*", MODE="0660", GROUP="usbtmc" | + | KERNEL=="usbtmc/*", MODE="0660", GROUP="usbtmc" |
+ | KERNEL=="usbtmc[0-9]*", MODE="0660", GROUP="usbtmc" | ||
+ | </code> | ||
+ | ===== Windows setup ===== | ||
+ | |||
+ | To use Python USBTMC in Windows, PyUSB and libusb are required. They can be downloaded from: | ||
+ | |||
+ | * http://sourceforge.net/projects/pyusb/ | ||
+ | * http://www.libusb.org/wiki/libusb-win32 | ||
+ | |||
+ | An INF file will also need to be created in order to use devices with libusb. Without a properly set up INF file, Python USBTMC will not be able to locate the device. There are instructions on the libusb page for how to generate the INF file. | ||
===== Usage examples ===== | ===== Usage examples ===== | ||
Line 36: | Line 55: | ||
import usbtmc | import usbtmc | ||
instr = usbtmc.Instrument(2391, 5973) | instr = usbtmc.Instrument(2391, 5973) | ||
+ | print(instr.ask("*IDN?")) | ||
+ | # returns 'AGILENT TECHNOLOGIES,MSO7104A,MY********,06.16.0001' | ||
+ | </code> | ||
+ | |||
+ | When multiple instruments are connected they can be identified by serial number: | ||
+ | |||
+ | <code python> | ||
+ | import usbtmc | ||
+ | instr = usbtmc.Instrument(2391, 5973, 'MY********') | ||
+ | print(instr.ask("*IDN?")) | ||
+ | # returns 'AGILENT TECHNOLOGIES,MSO7104A,MY********,06.16.0001' | ||
+ | </code> | ||
+ | |||
+ | It is also possible to connect with VISA resource strings like so: | ||
+ | |||
+ | <code python> | ||
+ | import usbtmc | ||
+ | instr = usbtmc.Instrument("USB::0x0957::0x1755::INSTR") | ||
+ | print(instr.ask("*IDN?")) | ||
+ | # returns 'AGILENT TECHNOLOGIES,MSO7104A,MY********,06.16.0001' | ||
+ | </code> | ||
+ | |||
+ | and: | ||
+ | |||
+ | <code python> | ||
+ | import usbtmc | ||
+ | instr = usbtmc.Instrument("USB::0x0957::0x1755::MY********::INSTR") | ||
print(instr.ask("*IDN?")) | print(instr.ask("*IDN?")) | ||
# returns 'AGILENT TECHNOLOGIES,MSO7104A,MY********,06.16.0001' | # returns 'AGILENT TECHNOLOGIES,MSO7104A,MY********,06.16.0001' |