Home Forum XScopes PC Interface control the scope with python, here are ...
 Gabotronics Forum :: XScopes PC Interface
Welcome Guest   
 Subject :control the scope with python, here are some code examples.. 2018-12-18 06:02:01 
nicole wolffer
Joined: 2018-12-18 11:51:37
Posts: 1


The pyusb module allows to control xpotolab with python.

I tried with a xprotolab plain, a computer on Ubuntu and a Raspberry pi

I tried the scope mode only.


First, one need to install pyusb




libusb must also be installed, but, if Gabriel's program is running, it’s already done


One must be sure the scope is triggered. If it is not , a time out error will occur while trying to transfer the frame data

On Ubuntu or Raspberry, open python in super user mode.


it’s ready, here are the code examples


#first, import the modules

import sys

import usb.core

import usb.util


#find the scope

xscope = usb.core.find(idVendor=5840, idProduct=1785)

if xscope is None:

print'Xscope is not connected'


#find the number of configurations

print 'nomber of configurations : ',xscope.bNumConfigurations



#find the number of interfaces and alternate settings

print "nomber of interfaces of config 0 : ",cfg.bNumInterfaces


print "nomber of alternate settings : ",intf.bAlternateSetting


#find the end points

print "nomber of end point : ",intf.bNumEndpoints



print "ep0 adress: ",ep0.bEndpointAddress

print "ep1 :adress ",ep1.bEndpointAddress

print "packet max of ep0 : ",ep0.wMaxPacketSize

print "packet max of ep1 : ",ep1.wMaxPacketSize


#set configuration before beeing able to communicate with the scope






#for each frame, 12 paquets of 64 bytes and a paquet of 2 bytes (frame and index)

#get paquets using bulk transfer untill the frame and index are send


while u>2:

data = xscope.read(ep0.bEndpointAddress,ep0.wMaxPacketSize)

u = len(data)


#paquets will now correspond to a new frame

#get ch1 data


for u in range (4):

#bulk transfer of 64 bytes

data = xscope.read(ep0.bEndpointAddress,ep0.wMaxPacketSize)

#add data to ch1


print 'ch1 = ', ch1


#get ch2 data


for u in range (4):

data = xscope.read(ep0.bEndpointAddress,ep0.wMaxPacketSize)


print 'ch2 = ',ch2


#get chD data


for u in range (4):

data = xscope.read(ep0.bEndpointAddress,ep0.wMaxPacketSize)


print 'chD = ',chD


#get frame, index data

data = xscope.read(ep0.bEndpointAddress,ep0.wMaxPacketSize)


print 'frame and index =', frameindex




#Now, one want to read and change the scope settings.


#commands are sent as CONTROL READ requests.

#commands are letters which can be found in the manual

#There are only two details one has to be carefull :

#first, do not use the command letters as string but use the ASCII value of the command letter.

#For example , to ask the firmware version, do not write ‘a’ but write ord(‘a’) or 0x61.

#Also, ask the exact number of bytes the scope is ready to send, no more, no less.


#To ask for firmware version :

data = xscope.ctrl_transfer(0xC0,0x61,0,0,4)

print data


version = chr(v[0])+chr(v[1])+chr(v[2])+chr(v[3])

print version


#my version is 2,38



#to read registers : command is 'u', 44 bytes are send to computer

data = xscope.ctrl_transfer(0xC0,ord('u'),0,0,44)

print data


#mind, in older devices, there may be only 43 bytes



#to restore defaults , command is ‘k’



#to write the settings, command is 'b' and 0 byte is send to computer,

#for example

#to set channel A gain (index 12 ) to level 3 :


#to set channel B gain (index 13 ) to level 5 :


#to set timescale (index 0 ) to level 5 :




p { margin-bottom: 0.25cm; line-height: 120%; }a:link { }

IP Logged
Page # 

Powered by ccBoard