python-ivi / python-usbtmc

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

Add an additional Rigol quirk to skip INITIATE_CLEAR #62

Open tai opened 1 year ago

tai commented 1 year ago

Hi. This patch updates usbtmc.py quirk handling to make it work better with Rigol DS1000Z-series oscilloscope (and probably also with DS2000-series).

DS1000Z does not handle INITIATE_CLEAR well, and USB response just times out (and hangs) once it receives this message. INITIATE_CLEAR is a required command as per USBTMC spec, but Rigol's implementation is known to be broken in many parts.

There's a workaround to do echo *IDN? > /dev/usbtmc<N> to initialize the device without sending INITIATE_CLEAR, but that's Linux-specific and user has to figure out which /dev/usbtmc* device to use. This patch will make things much easier and portable.

I have tested this patch with rigolcap.py script I pasted to gist: https://gist.github.com/tai/408053a0955bf1712a5809240aa5544f

Also, just FYI, https://github.com/jtambasco/RigolOscilloscope.git which uses python-usbtmc works with Rigol, but has a following hack to make it work:

os.system('echo *IDN? >> /dev/%s' % dev[3])

With this patch, user of usbtmc.py can now just do this:

tmc = usbtmc.Instrument(0x1ab1, 0x04ce)
tmc.write_raw(b'*IDN?')