RoGeorge / DS1054Z_screen_capture

Capture the display of a Rigol DS1000Z series oscilloscope by LAN only, using LXI SCPI commands. No USB, no VISA, no IVI and no Rigol drivers are required.
https://hackaday.io/project/5807-driverless-rigol-ds1054z-screen-capture-over-lan
GNU General Public License v2.0
208 stars 55 forks source link

OscScreenGrabLAN.py line 107 may need updating to add \n #2

Open thephantom1492 opened 8 years ago

thephantom1492 commented 8 years ago

I needed to replace it to: tn.write("*idn?\n") # ask for instrument ID Else it wasn't finding it.

RoGeorge commented 8 years ago

Could not reproduce. Closed as not reproducible.

Thank you very much for your feedback.

elmicha commented 7 years ago

I had the same problem with the latest version:

2016-09-30 22:49:22,938 - INFO - New run started...
2016-09-30 22:49:22,938 - INFO - Log message: INFO level set.
2016-09-30 22:49:22,938 - INFO - ***** Running Python version:
2016-09-30 22:49:22,938 - INFO - 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609], sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0)
2016-09-30 22:49:22,938 - INFO - sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0)
2016-09-30 22:49:23,042 - INFO - Installed Python modules:['backports.ssl-match-hostname==3.5.0.1', 'binwalk==2.1.0', 'bottle==0.12.9', 'click==5.1', 'esptool==1.2.dev0', 'freekey==0.1.1', 'ino==0.3.6', 'keyring==9.3', 'keyrings.alt==1.1.1', 'ordereddict==1.1', 'paho-mqtt==1.1', 'platformio==2.6.1', 'pushbullet-cli==0.7.5', 'pushbullet.py==0.10.0', 'pyrtlsdr==0.2.2', 'python-magic==0.4.11', 'pyvisa-py==0.2', 'pyvisa==1.8', 'websocket-client==0.37.0']
2016-09-30 22:49:23,050 - INFO - SCPI to be sent: *idn?
2016-09-30 22:49:23,050 - INFO - Send SCPI: *OPC?
2016-09-30 22:49:24,050 - INFO - Received response: 
2016-09-30 22:49:24,051 - INFO - Send SCPI: *OPC?
2016-09-30 22:49:25,052 - INFO - Received response: 
2016-09-30 22:49:25,052 - INFO - Send SCPI: *OPC?

After appending a \n to "_idn?", "display:data?" and "_OPC?", and also reducing expected_len and terminator_len it works.

diff --git a/OscScreenGrabLAN.py b/OscScreenGrabLAN.py
old mode 100644
new mode 100755
index b3cf7a1..1a6cff2
--- a/OscScreenGrabLAN.py
+++ b/OscScreenGrabLAN.py
@@ -57,9 +57,9 @@ IP_DS1104Z = "192.168.1.3"
 # Rigol/LXI specific constants
 port = 5555

-expected_len = 1152068
+expected_len = 1152066
 TMC_header_len = 11
-terminator_len = 3
+terminator_len = 1

 big_wait = 10
 small_wait = 1
@@ -128,7 +128,7 @@ if response != 0:
 # The default telnetlib drops 0x00 characters,
 #   so a modified library 'telnetlib_receive_all' is used instead
 tn = Telnet(IP_DS1104Z, port)
-instrument_id = command(tn, "*idn?")    # ask for instrument ID
+instrument_id = command(tn, "*idn?\n")    # ask for instrument ID

 # Check if instrument is set to accept LAN commands
 if instrument_id == "command error":
@@ -155,7 +155,7 @@ filename = path_to_save + id_fields[model] + "_" + id_fields[serial] + "_" + tim
 if file_format in ["png", "bmp"]:
     # Ask for an oscilloscope display print screen
     print "Receiving screen capture..."
-    buff = command(tn, "display:data?")
+    buff = command(tn, "display:data?\n")

     # Just in case the transfer did not complete in the expected time
     while len(buff) < expected_len:
diff --git a/Rigol_functions.py b/Rigol_functions.py
index 8d3e7f9..ae16470 100644
--- a/Rigol_functions.py
+++ b/Rigol_functions.py
@@ -21,7 +21,7 @@ def command(tn, SCPI):
     answer_wait_s = 1
     response = ""
     while response != "1\n":
-        tn.write("*OPC?")  # previous operation(s) has completed ?
+        tn.write("*OPC?\n")  # previous operation(s) has completed ?
         logging.info("Send SCPI: *OPC?")
         response = tn.read_until("\n", 1)  # wait max 1s for an answer
         logging.info("Received response: " + response)

I'm using the current firmware 00.04.04.SP1 for DS1054Z.

The "MSO1000Z/DS1000Z Programming Guide" says

The terminator '\n'(0X0A) at the end of the data should be removed.

and I got

Receiving screen capture...
ERROR

before reducing terminator_len.

RoGeorge commented 7 years ago

Thank you for letting me know. There are 2 problems with v1.0.0 of the script. First, is that somehow I managed to push a broken version and tag it as the first release, v1.0.0. My bad here, sorry for that. Second is that different versions of oscilloscope firmware respond different to the same SCPI commands sent by the script.

As an example, the firmware version I have on my scope now, 00.04.03 SP1, is accepting commands without '\n' at the end. Other firmware versions seems to require a mandatory '\n' at the end of each command.

Also, 00.04.03 SP1 is adding 2 unexpected bytes at the end of the bitmap file. These two bytes does not follow the description of the BMP format, and does not follow the description of the response described in the Rigol's own manual. These 2 extra bytes can also be seen with Wireshark.

Long story short, this weekend I will try to fix all the reported issues: