Skip to content
This repository was archived by the owner on Feb 2, 2026. It is now read-only.
This repository was archived by the owner on Feb 2, 2026. It is now read-only.

Problems getting a Rigol DSA1020 to respond properly #1

@MikeSandford

Description

@MikeSandford

I've got a small program that I'm using to try and connect up to a Rigol Spectrum Analyzer.

import usbtmc
listOfDevices = usbtmc.list_devices()
for device in listOfDevices:
print hex(device.idVendor), hex(device.idProduct)

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

When running it I get this output. Even after chmodding 777 /dev/usbtmc2 I still need to sudo which is interesting.

sandford@MikeLinux ~/projects $ sudo python usbtmc_test.py
0x400 0x9c4
<usbtmc.usbtmc.Instrument object at 0x7f3a78e1d750>
Traceback (most recent call last):
File "usbtmc_test.py", line 11, in
print instrument.ask("*IDN?")
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 346, in ask
return self.read(num, encoding)
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 341, in read
return self.read_raw(num).decode(encoding).rstrip('\r\n')
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 309, in read_raw
msgid, btag, btaginverse, transfer_size, transfer_attributes, data = self.unpack_dev_dep_resp_header(bytearray(resp))
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 259, in unpack_dev_dep_resp_header
msgid, btag, btaginverse = self.unpack_bulk_in_header(data[0:4])
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 255, in unpack_bulk_in_header
msgid, btag, btaginverse = struct.unpack('BBBx', data[0:4])
struct.error: unpack requires a string argument of length 4
sandford@MikeLinux ~/projects $

So then I modified the source to print out the data going in to unpack_bulk_in_header, did "sudo python setup.py install" and re-ran and saw this:

sandford@MikeLinux ~/projects $ sudo python usbtmc_test.py
0x400 0x9c4
<usbtmc.usbtmc.Instrument object at 0x7fd0cc66c750>
[bytearray(b'\x02\x02\xfd\x00')]
Traceback (most recent call last):
File "usbtmc_test.py", line 11, in
print instrument.ask("*IDN?")
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 347, in ask
return self.read(num, encoding)
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 342, in read
return self.read_raw(num).decode(encoding).rstrip('\r\n')
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 310, in read_raw
msgid, btag, btaginverse, transfer_size, transfer_attributes, data = self.unpack_dev_dep_resp_header(bytearray(resp))
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 260, in unpack_dev_dep_resp_header
msgid, btag, btaginverse = self.unpack_bulk_in_header(data[0:4])
File "/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.py", line 256, in unpack_bulk_in_header
msgid, btag, btaginverse = struct.unpack('BBBx', data[0:4])
struct.error: unpack requires a string argument of length 4
sandford@MikeLinux ~/projects $

There are four bytes in that array but the last one is a null. I'm not terribly familiar with the code or usbtmc as a standard so I'm afraid I don't really know what to do here. Any help is greatly appreciated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions