I am telnet into Keysight N1914A power meter and python subprocess.check_out[("Measure:Power?)] is not working. So I am trying to use the python telnetlib. I do not need username or password to log in. IP address and port number is all it needs.
There are lots of examples showing how to log in the device. My question is that how to obtain the results from the device after input commands.
For example: in the device, I type *IDN? it will result its device information; and when I type Measure:Power? it will result the power in decibel format.
import time
import csv
from string import split
import getpass
import sys
import telnetlib
import subprocess
Host = "192.168.1.10"
PORT = 5024
TIMEOUT =10
i = open('practice1.csv', 'wb')
tn = telnetlib.Telnet(Host,PORT)
print "You log in"
time.sleep(5)
while True:
#Powertemp1 = subprocess.check_output(["Measure:Power?"])
#tn.write("Measure:Power?")
tn.write("*IDN?")
Powertemp1 = tn.read_all()
print type(Powertemp1)
print Powertemp1
#Powertemp = float(Powertemp1)
#print '&s' % Powertemp
#wr = csv.writer(i, dialet = 'excel')
#wr.writerow([Powertemp])
time.sleep(5)
type(tn.read_all()) is str, but in the actual screen it is around 40 empty lines, and nothing is stored in the output text file.
Here is the result:
You log in
Traceback (most recent call last):
File "sunlook.py", line 25, in <module>
tn.write("*IDN?")
File "/usr/lib/python2.7/telnetlib.py", line 282, in write
self.sock.sendall(buffer)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 32] Broken pipe