I am new to PyUSB and I am trying to communicate with this oscilloscope using my Laptop via USB. I have established the initial communication with the scope but I cannot send any commands to the scope as I am getting a "Pipe error".
This is my code:
import time
import csv
import usb.core
import usb.util
import array
import codecs
import sys
# Vendor and Product ID is obtained from the device datasheet.
dev = usb.core.find(idVendor=0x699, idProduct=0x105)
# Check whether the device is found.
if dev is None:
raise ValueError('Device is not found!')
else:
print(dev) #Used to find out the IN and OUT endpoint addresses.
dev.reset() #Resetting the device.
dev.set_configuration()#Getting the device ready.
usb.util.claim_interface(dev, 0)
time.sleep(1)
cmd = '*IDN?' # This is the command
dev.ctrl_transfer(0x40, 0x04, 0, 0, cmd, 1000)
time.sleep(1)
As seen in the code, I am trying to send '*IDN?' to the scope to get manufacturer and other such identification details about the scope. This is the error that I am getting (happens due to dev.ctrl_transfer()):
File "C:\Users\Name\Desktop\Work_related\Read_data_from_oscilloscope\Read_data_from_MSO.py", line 28, in <module>
dev.ctrl_transfer(0x40, 0x04, 0, 0, cmd, 1000)
File "C:\Users\Name\AppData\Local\Programs\Python\Python37\Lib\site-packages\usb\core.py", line 1089, in ctrl_transfer
self.__get_timeout(timeout))
File "C:\Users\Name\AppData\Local\Programs\Python\Python37\Lib\site-packages\usb\backend\libusb1.py", line 901, in ctrl_transfer
timeout))
File "C:\Users\Name\AppData\Local\Programs\Python\Python37\Lib\site-packages\usb\backend\libusb1.py", line 604, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 32] Pipe error
I tried ctrl_transfer() because the data that I get using read() and write() is garbage. I don't know why. This is the code using read() and write():
cmd = 'DATE?'
dev.write(1, cmd, 1000)
time.sleep(1)
data = dev.read(0x81, 128)
time.sleep(1)
data = list(data)
data_in_unicode = [chr(i) for i in data]
print(''.join(data_in_unicode))
How can I remove the "Pipe Error" issue? Any help is greatly appreciated.