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 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import pip
  2. import sys
  3. import logging
  4. __author__ = 'RoGeorge'
  5. def log_running_python_versions():
  6. logging.info("Python version: " + str(sys.version) + ", " + str(sys.version_info)) # () required in Python 3.
  7. installed_packages = pip.get_installed_distributions()
  8. installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
  9. logging.info("Installed Python modules: " + str(installed_packages_list))
  10. def command(tn, scpi):
  11. logging.info("SCPI to be sent: " + scpi)
  12. answer_wait_s = 1
  13. response = ""
  14. while response != b"1\n":
  15. tn.write("*OPC?\n") # previous operation(s) has completed ?
  16. logging.info("Send SCPI: *OPC? # May I send a command? 1==yes")
  17. response = tn.read_until(b"\n", 1) # wait max 1s for an answer
  18. logging.info("Received response!")
  19. tn.write(scpi + "\n")
  20. logging.info("Sent SCPI: " + scpi)
  21. response = tn.read_until(b"\n", answer_wait_s)
  22. logging.info("Received response!")
  23. return response
  24. # first TMC byte is '#'
  25. # second is '0'..'9', and tells how many of the next ASCII chars
  26. # should be converted into an integer.
  27. # The integer will be the length of the data stream (in bytes)
  28. # after all the data bytes, the last char is '\n'
  29. def tmc_header_bytes(buff):
  30. return 2 + int(buff[1:2])
  31. def expected_data_bytes(buff):
  32. return int(buff[2:tmc_header_bytes(buff)])
  33. def expected_buff_bytes(buff):
  34. return tmc_header_bytes(buff) + expected_data_bytes(buff) + 1
  35. def get_memory_depth(tn):
  36. # Define number of horizontal grid divisions for DS1054Z
  37. h_grid = 12
  38. # ACQuire:MDEPth
  39. mdep = command(tn, ":ACQ:MDEP?")
  40. # if mdep is "AUTO"
  41. if mdep == "AUTO\n":
  42. # ACQuire:SRATe
  43. srate = command(tn, ":ACQ:SRAT?")
  44. # TIMebase[:MAIN]:SCALe
  45. scal = command(tn, ":TIM:SCAL?")
  46. # mdep = h_grid * scal * srate
  47. mdep = h_grid * float(scal) * float(srate)
  48. # return mdep
  49. return int(mdep)