Capture the display of a Rigol DS1000Z series oscilloscope by LAN using LXI SCPI commands
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Rigol_functions.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. __author__ = 'RoGeorge'
  2. import time
  3. import pip
  4. import sys
  5. import logging
  6. def print_running_Python_versions():
  7. print "Running Python version:"
  8. print (sys.version) # parentheses necessary in python 3.
  9. print sys.version_info
  10. print
  11. installed_packages = pip.get_installed_distributions()
  12. installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
  13. print "Installed Python modules:"
  14. print(installed_packages_list)
  15. print
  16. def command(tn, SCPI):
  17. logging.info("SCPI to be sent: " + SCPI)
  18. answer_wait_s = 1
  19. response = ""
  20. while response != "1\n":
  21. tn.write("*OPC?") # previous operation(s) has completed ?
  22. logging.info("Send SCPI: *OPC?")
  23. response = tn.read_until("\n", 1) # wait max 1s for an answer
  24. logging.info("Received response: " + response)
  25. tn.write(SCPI)
  26. logging.info("Sent SCPI: " + SCPI)
  27. response = tn.read_until("\n", answer_wait_s)
  28. logging.info("Received response: " + response)
  29. return response
  30. def get_memory_depth(tn):
  31. # Define number of horizontal grid divisions for DS1054Z
  32. h_grid = 12
  33. # ACQuire:MDEPth
  34. mdep = command(tn, "ACQ:MDEP?")
  35. # if mdep is "AUTO"
  36. if mdep == "AUTO\n":
  37. # ACQuire:SRATe
  38. srate = command(tn, "ACQ:SRAT?")
  39. # TIMebase[:MAIN]:SCALe
  40. scal = command(tn, "TIM:SCAL?")
  41. # mdep = h_grid * scal * srate
  42. mdep = h_grid * scal * srate
  43. # return mdep
  44. return int(mdep)
  45. # return maximum achieved stop point, or 0 for wrong input parameters
  46. # if achieved == requested, then set the start and stop waveform as n1_d and n2_d
  47. def is_waveform_from_to(tn, n1_d, n2_d):
  48. # read current
  49. # WAVeform:STARt
  50. n1_c = int(command(tn, "WAV:STAR?"))
  51. # WAVeform:STOP
  52. n2_c = int(command(tn, "WAV:STOP?"))
  53. if (n1_d > n2_d) or (n1_d < 1) or (n2_d < 1):
  54. # wrong parameters
  55. return 0
  56. elif n2_d < n1_c:
  57. # first set n1_d then set n2_d
  58. print "a ", "n1_d=", n1_d, "n2_d=", n2_d
  59. command(tn, "WAV:STAR " + str(n1_d))
  60. command(tn, "WAV:STOP " + str(n2_d))
  61. else:
  62. # first set n2_d then set n1_d
  63. print "b ", "n2_d", n2_d, "n1_d=", n1_d
  64. command(tn, "WAV:STOP " + str(n2_d))
  65. command(tn, "WAV:STAR " + str(n1_d))
  66. # read achieved n2
  67. n2_a = int(command(tn, "WAV:STOP?"))
  68. if n2_a < n2_d:
  69. # restore n1_c, n2_c
  70. is_waveform_from_to(tn, n1_c, n2_c)
  71. # return n2_a
  72. return n2_a