Capture the display of a Rigol DS1000Z series oscilloscope by LAN using LXI SCPI commands
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

OscScreenGrabLAN.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. __author__ = 'RoGeorge'
  2. #
  3. # TODO: Port for Linux
  4. # TODO: Add command line parameters for IP, file path and file format
  5. # TODO: Add GUI
  6. # TODO: Add browse and custom filename selection
  7. # TODO: Create executable distributions
  8. #
  9. import telnetlib_receive_all
  10. import time
  11. import Image
  12. import StringIO
  13. import sys
  14. import os
  15. # Update the next lines for your own default settings:
  16. path_to_save = ""
  17. save_format = "PNG"
  18. IP_DS1104Z = "192.168.1.3"
  19. # Rigol/LXI specific constants
  20. port = 5555
  21. expected_len = 1152068
  22. TMC_header_len = 11
  23. terminator_len = 3
  24. big_wait = 10
  25. small_wait = 1
  26. company = 0
  27. model = 1
  28. serial = 2
  29. # Check parameters
  30. script_name = os.path.basename(sys.argv[0])
  31. # Print usage
  32. print
  33. print "Usage:"
  34. print " " + script_name + " [oscilloscope_IP [save_path [PNG | BMP]]]"
  35. print
  36. print "Usage examples:"
  37. print " " + script_name
  38. print " " + script_name + " 192.168.1.3"
  39. print " " + script_name + " 192.168.1.3 my_place_for_osc_captures"
  40. print " " + script_name + " 192.168.1.3 my_place_for_osc_captures BMP"
  41. print
  42. print "This program capture the image displayed"
  43. print " by a Rigol DS1000Z series oscilloscope, then save it on the computer"
  44. print " as a PNG or BMP file with a timestamp in the file name."
  45. print
  46. print " The program is using LXI protocol, so the computer"
  47. print " must have LAN connection with the oscilloscope."
  48. print " USB and/or GPIB connections are not used by this software."
  49. print
  50. print " No VISA, IVI or Rigol drivers are needed."
  51. print
  52. # Create/check if 'path' exists
  53. # Check network response (ping)
  54. response = os.system("ping -n 1 " + IP_DS1104Z + " > nul")
  55. if response != 0:
  56. print
  57. print "No response pinging " + IP_DS1104Z
  58. print "Check network cables and settings."
  59. print "You should be able to ping the oscilloscope."
  60. # Open a modified telnet session
  61. # The default telnetlib drops 0x00 characters,
  62. # so a modified library 'telnetlib_receive_all' is used instead
  63. tn = telnetlib_receive_all.Telnet(IP_DS1104Z, port)
  64. tn.write("*idn?") # ask for instrument ID
  65. instrument_id = tn.read_until("\n", 1)
  66. # Check if instrument is set to accept LAN commands
  67. if instrument_id == "command error":
  68. print instrument_id
  69. print "Check the oscilloscope settings."
  70. print "Utility -> IO Setting -> RemoteIO -> LAN must be ON"
  71. sys.exit("ERROR")
  72. # Check if instrument is indeed a Rigol DS1000Z series
  73. id_fields = instrument_id.split(",")
  74. if (id_fields[company] != "RIGOL TECHNOLOGIES") or \
  75. (id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
  76. print
  77. print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
  78. sys.exit("ERROR")
  79. print "Instrument ID:"
  80. print instrument_id
  81. # Prepare filename as C:\MODEL_SERIAL_YYYY-MM-DD_HH.MM.SS
  82. timestamp = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime())
  83. filename = path_to_save + id_fields[model] + "_" + id_fields[serial] + "_" + timestamp
  84. # Ask for an oscilloscope display print screen
  85. tn.write("display:data?")
  86. print "Receiving..."
  87. buff = tn.read_until("\n", big_wait)
  88. # Just in case the transfer did not complete in the expected time
  89. while len(buff) < expected_len:
  90. tmp = tn.read_until("\n", small_wait)
  91. if len(tmp) == 0:
  92. break
  93. buff += tmp
  94. # Strip TMC Blockheader and terminator bytes
  95. buff = buff[TMC_header_len:-terminator_len]
  96. # Save as PNG
  97. im = Image.open(StringIO.StringIO(buff))
  98. im.save(filename + ".png", "PNG")
  99. print "Saved file:", filename + ".png"
  100. # Save as BMP
  101. # scr_file = open(filename + ".bmp", "wb")
  102. # scr_file.write(buff)
  103. # scr_file.close()
  104. tn.close()