Op maandag 16 december 2013 15:16:17 UTC+1 schreef Jean-Michel Pichavant: > ----- Original Message ----- > > Op maandag 16 december 2013 13:05:41 UTC+1 schreef Jean-Michel > > Pichavant: > > > > Here is the code: > > > > #!/usr/bin/env python > > > > import telnetlib > > > > host = '10.128.59.63' > > > > port = 7000 > > > > t = Telnet(host, port) > > > > t.write('*IDN?\n') > > > > print t.read_until('Whateverprompt') > > > > # you can use read_very_eager also > > > > > > > > and this is the result of executing the code(from which I deduce > > > > I > > > > have to > > > > install telnetlib, but how?) > > > > Traceback (most recent call last): > > > > File "./nctelnet.py", line 5, in <module> > > > > t = Telnet(host, port) > > > > NameError: name 'Telnet' is not defined > > > > > > > > kind regards, > > > > jean > > > t = telnetlib.Telnet(host, port) > > this helps, but I don't know what to do with > > "print t.read_until('Whateverprompt')" > > > > should I send CTRL-ALT-ALTGR-] after some time? > > > > kind regards, > > jean > one way to approach the problem is to first make some monkey tests. > 1/ connect to your equipment using telnet (from the linux shell) > 2/ try typing some commands like *IDN? > 3/ see how the equipment is answering > 4/ you need to identify what is the prompt, and what EndOfLine sequence is > used. > 5/ then in a python shell, try to reproduce the behavior: > import telnetlib > t = telnetlib.Telnet(host, port) > t.read_very_eager() #flush > t.write('\n') > prompt = t.read_very_eager() #this is one way to get the prompt > print repr(prompt) #you may identify the EOL sequence with this one > When you get a good feeling about how it works, write the code. Running you code I get as response: ''
This is what I got using telnet: [jean:~] $ telnet 10.128.59.63 7000 Trying 10.128.59.63... Connected to 10.128.59.63. Escape character is '^]'. *IDN? KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32 Oct 4 2010 14:20:11/A02 /E/ H after pressing CTRL-ALT-ALTGR-] I get this: ^[^] after which I get the telnet-prompt >telnet and I can quit telnet by entering quit kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list