Hi guys,
I try to write a script in python to save the screenshoot in a png file but I get some errors. If any body can have a look on this. I am new in Python.
Many thanks for your help.
import visa
rm=visa.ResourceManager('@py')
scope = rm.open_resource('GPIB::6::0')
scope.write('HARDCOPY:FILENAME "test.png"')
scope.write('HARDCOPY:FORMAT PNG')
scope.write('HARDCOPY:LAYOUT LANDSCAPE')
scope.write('HARDCOPY:PORT GPIB')
scope.write('HARDCOPY START')
raw_data=scope.read()
fid=open('/home/pi/test.png','wb')
fid.write(raw_data)
fid.close()
And I got this error
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 312, in read
message = self.read_raw().decode(enco)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 1031: ordinal not in range(128)
No need to post in two separate threads (o;
Think I already posted my screen dump code somewhere here....but here it is again:
#!/usr/bin/python
import sys
from subprocess import Popen, PIPE
import errno
import shlex
hpgl = ""
hp2xx = "/usr/bin/hp2xx -m png -c 12445611 -d 150 -D 90 -q -f "
cat = "/bin/cat"
from Gpib import *
file_name = sys.argv[1]
hp2xx += file_name
hp2xx += ".png"
p = Popen(shlex.split(hp2xx), shell=False, stdin=PIPE)
bytes = 200
inst = Gpib(0,1)
inst.write("HCSU DEV,HP7550A")
inst.write("SCDP")
p.stdin.write(inst.read(bytes))
count = 0
while inst.ibcnt() == bytes:
print 'Bytes read: ',count
p.stdin.write(inst.read(bytes))
count += bytes
print '\nFinished dumping... '
print hp2xx
p.stdin.close()
p.wait()
Most difficult was to find out how to launch the external hp2xx program in a shell and write the screen dump to stdout...but you won't need this as you dump a bitmap image...