Capture the display of a Rigol DS1000Z series oscilloscope by LAN using LXI SCPI commands
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

OscScreenGrabLAN.py 3.2KB

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