Advertisement
Guest User

applyCode.py

a guest
Jul 2nd, 2013
1,470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. """
  2. Version 1.0a, 29 Jun 13
  3. """
  4.  
  5. import time, sys, array, string
  6. import rigol, usb.core, usb.util
  7.  
  8. ds2072 = rigol.Scope(VID = 0x1ab1, PID = 0x04b0, EP_OUT=0x01, EP_IN=0x86)
  9.  
  10. code = "LLLLLLLRLGLLDSDSA9LLLLLLLLLL"
  11.  
  12. def main():
  13.  
  14. try:
  15. # wait for the scope to come online
  16. ret = ds2072.findDevice()
  17. while (ret == False):
  18. print("Looking for device.")
  19. time.sleep(5)
  20. ret = ds2072.findDevice()
  21. print ("Device found.")
  22.  
  23. # if you want to read the setup from a file instead of the
  24. # scope itself, use the following lines and comment out the
  25. # section of code below reading back the scope's setup
  26. """
  27. with open('example.stp', 'rd') as f:
  28. read_data = ":SYST:SET #9000002579" + f.read()
  29. """
  30.  
  31. print ("Getting setup data.")
  32. # get the setup data from the scope
  33. ds2072.write(":SYSTem:SETup?")
  34. response = ds2072.trim_response(ds2072.read(no_of_bytes=500))
  35. read_data = ":SYST:SET " + str(response)
  36. while (len(response) == 500):
  37. response = response = ds2072.trim_response(ds2072.read(no_of_bytes=500))
  38. read_data += str(response)
  39.  
  40. # apply the code
  41. print("Applying code:" + code)
  42. ds2072.write(":SYSTem:OPTion:INSTall " + code + "\n")
  43.  
  44. time.sleep(2)
  45. print ("Writing back setup data.")
  46. # send back the setup data
  47. ds2072.write(read_data)
  48.  
  49. # This exception will be caused by the USB device
  50. # going off-line (e.g. being unplugged).
  51. # It may also be cause by a timeout, usually surrounding
  52. # a device not having the bus closed on exit.
  53. except usb.core.USBError:
  54. pass
  55.  
  56. ds2072.close()
  57.  
  58.  
  59. if __name__ == '__main__':
  60. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement