2017-03-08 88 views
2

我正嘗試將一張來自Rhode的屏幕截圖& Schwarz - FSV信號分析儀傳輸到我的電腦。PYVISA:如何傳輸二進制塊數據以便圖片格式正確並保存到我的PC上?

如何傳輸二進制塊數據,以便將圖片從樂器上正確保存到我的電腦中?我的代碼如下。文件被保存到我的桌面,但是我的電腦會引發錯誤,並且無法打開,因爲文件格式不正確。

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() 

file shows up on Desktop

Error when trying to open file on Desktop

我驗證了屏幕截圖保存在儀器上。還用另一臺儀器驗證SCPI語法是否正確。所以它必須是如何傳輸binblock數據。任何意見是極大的讚賞。

回答

0
import pyvisa 
rm = pyvisa.ResourceManager() 
inst = rm.open_resource('TCPIP0::178.168.48.31::inst0::INSTR') 

inst.values_format.is_binary = True 
inst.values_format.datatype = 'B' 
inst.values_format.is_big_endian = False 
inst.values_format.container = bytearray 

inst.write("mmem:name 'C:\eswScreen.wmf\'") 
img = inst.query_values("MMEM:DATA? 'C:\eswScreen.wmf\'") 

target = open(r"C:\Users\user\Desktop\screenShot.wmf", 'wb') 
target.write(img) 
target.close() 

這對我有效。

相關問題