Capture the display of a Rigol DS1000Z series oscilloscope by LAN using LXI SCPI commands
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Rigol_functions.py 2.4KB

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