Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 telnet中的telnetlib和python子进程_Python 2.7_File_Subprocess_Telnet_Telnetlib - Fatal编程技术网

Python 2.7 telnet中的telnetlib和python子进程

Python 2.7 telnet中的telnetlib和python子进程,python-2.7,file,subprocess,telnet,telnetlib,Python 2.7,File,Subprocess,Telnet,Telnetlib,我正在远程登录Keysight N1914A功率计和python子进程。签出[(“测量:功率?)不起作用。因此我正在尝试使用python telnetlib。登录时不需要用户名或密码。IP地址和端口号就是它所需的全部 有很多例子展示了如何登录设备。我的问题是如何在输入命令后从设备获取结果 例如:在设备中,我键入*IDN?将生成其设备信息;当我键入Measure:Power?时,将以分贝格式生成功率 import time import csv from string import split i

我正在远程登录Keysight N1914A功率计和python子进程。签出[(“测量:功率?)不起作用。因此我正在尝试使用python telnetlib。登录时不需要用户名或密码。IP地址和端口号就是它所需的全部

有很多例子展示了如何登录设备。我的问题是如何在输入命令后从设备获取结果

例如:在设备中,我键入*IDN?将生成其设备信息;当我键入Measure:Power?时,将以分贝格式生成功率

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)
类型(tn.read_all())是str,但在实际屏幕中大约有40行空行,输出文本文件中没有存储任何内容

结果如下:

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
您登录了吗
回溯(最近一次呼叫最后一次):
文件“sunlook.py”,第25行,在
tn.write(“*IDN?”)
写入文件“/usr/lib/python2.7/telnetlib.py”,第282行
self.sock.sendall(缓冲区)
文件“/usr/lib/python2.7/socket.py”,第224行,meth格式
返回getattr(self.\u sock,name)(*args)
socket.error:[Errno 32]管道破裂