title: PYVISA: How do I transfer binary block data so that the picture is properly formatted and saved onto my PC?
body: <p>I am trying to transfer a screen shot from an Rhode &amp; Schwarz - FSV Signal Analyzer to my PC.  </p>
  
  <p>How do I transfer binary block data so that the picture is properly saved onto my PC from the Instrument?  My code is below. A file gets saved to my desktop, but my computer throws an error and cannot open because the file is not formatted correctly.</p>
  
  <pre><code>import visa
  rm = visa.ResourceManager()
  inst = rm.open_resource('TCPIP0::178.168.48.31::inst0::INSTR')
  
  inst.write("mmem:name 'C:\eswScreen.wmf\'")
  inst.write("MMEM:DATA? 'C:\eswScreen.wmf\'")
  img = inst.read_raw()
  
  target = open(r"C:\Users\myName\Desktop\screenShot.wmf", 'wb')
  target.write(img)
  target.close()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pyh7G.png" rel="nofollow noreferrer">file shows up on Desktop</a></p>
  
  <p><a href="https://i.stack.imgur.com/dJsG7.png" rel="nofollow noreferrer">Error when trying to open file on Desktop</a></p>
  
  <p>I verified the screen shot is saved on the instrument.  Also verified with another instrument that the SCPI syntax is correct.  So it must be how the binblock data is being transferred.  Any advice is greatly appreciated.</p>