#!/usr/bin/env python3 address = "TCPIP::10.42.47.104::INSTR" import pyvisa, sys, io from PIL import Image rm = pyvisa.ResourceManager() instr = rm.open_resource(address) instr.write('SCDP') answer = instr.read_raw() img = Image.open(io.BytesIO(answer)) sys.stdout.buffer.write(b"Content-type: image/png\n\n") img.save(sys.stdout.buffer, 'png')