Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'sys': 0.05; 'emulate': 0.07; 'returned.': 0.07; 'username,': 0.07; 'python': 0.09; 'pressing': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; '2.7': 0.13; 'read.': 0.13; '"..."': 0.16; '"\\r\\n"': 0.16; 'isnt': 0.16; 'skip:> 20': 0.16; 'telnetlib': 0.16; 'string': 0.17; 'wrote:': 0.17; 'typing': 0.17; 'windows': 0.19; 'equivalent': 0.20; 'skip:" 30': 0.20; '"",': 0.22; 'assuming': 0.22; 'help.': 0.22; 'cc:2**0': 0.23; 'work.': 0.23; 'monday,': 0.23; "haven't": 0.23; 'raise': 0.24; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'appreciated.': 0.26; '(most': 0.27; 'older': 0.27; 'wonder': 0.27; 'skip:> 10': 0.27; '>>>>': 0.29; 'didnt': 0.29; 'initiate': 0.29; 'connection': 0.30; 'ends': 0.30; 'returned': 0.30; 'file': 0.32; 'traceback': 0.33; 'code:': 0.33; 'weeks': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'option': 0.37; 'communicate': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'instead': 0.39; 'hello,': 0.39; 'skip:" 10': 0.40; 'subject:-': 0.40; 'help': 0.40; 'from:no real name:2**0': 0.60; '(that': 0.62; 'email addr:gmail.com': 0.63; 'dont': 0.64; 'here': 0.65; 'charset:windows-1252': 0.65; 'camera': 0.65; 'hoping': 0.72; 'prompt': 0.78; '2013': 0.84; 'difference.': 0.84; 'presumably': 0.84 X-Received: by 10.49.24.13 with SMTP id q13mr1141926qef.33.1361821726650; Mon, 25 Feb 2013 11:48:46 -0800 (PST) Newsgroups: comp.lang.python Date: Mon, 25 Feb 2013 11:48:46 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=199.181.155.130; posting-account=NWckLgoAAAA_ESRKeclDK3J-ZCP6LE-U References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 199.181.155.130 MIME-Version: 1.0 Subject: Re: telnet to Cognex In-Sight 4001 camera From: chris.annin@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 86 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361822516 news.xs4all.nl 6939 [2001:888:2000:d::a6]:52712 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39910 On Monday, February 25, 2013 9:29:54 AM UTC-8, MRAB wrote: > On 2013-02-25 17:02, chris.annin@gmail.com wrote: >=20 > > Hello, ive been struggling with this for a couple weeks now and was ho= ping someone might be able to help. I have an older Cognex camera that I n= eed to communicate with via telnet. I can get a response from the camera w= hen I initiate a telnet session but I dont seem to get any response when I = write the user name to the camera - I havnt been able to get any response = writing anything. Im using python 2.7 and windows xp. here is the code: >=20 > > [code] >=20 > >>>>import sys >=20 > >>>>import telnetlib >=20 > >>>>HOST =3D "10.31.18.21" >=20 > >>>>USER =3D "admin" >=20 > >>>>tn =3D telnetlib.Telnet(HOST) >=20 > >>>>tn.read_until("Login: ") >=20 > > "Welcome to In-Sight(R) 4001 Session 1\r\nUser:" >=20 >=20 >=20 > The returned string ends with "User:", presumably the prompt to enter >=20 > the username, which makes we wonder whether you should be reading until >=20 > "User:" instead of until "Login: ". >=20 >=20 >=20 > >>>>tn.write(USER + "\r\n") >=20 >=20 >=20 > Should you be ending that with just "\r" or just "\n" instead? (That >=20 > would be equivalent to typing the username and then pressing the Return >=20 > key.) >=20 >=20 >=20 > >>>>tn.read_until("User: ") >=20 >=20 >=20 > Haven't you already seen "User: "? >=20 >=20 >=20 > > Traceback (most recent call last): >=20 > > File "", line 1, in=20 >=20 > > File "C:\Python27\lib\telnetlib.py", line 319, >=20 > > return self.read_very_lazy() >=20 > > File "C:\Python27\lib\telnetlib.py", line 395, >=20 > > raise EOFError, 'telnet connection closed' >=20 > > EOFError: telnet connection closed >=20 > >>>> >=20 > > [\code] >=20 > > >=20 > > if i do a read_all instead of read_until for user I just get "..." retu= rned. Im assuming tn.write command isnt working? any help would be greatl= y appreciated. >=20 yea you are right I shouldnt be doing read_until("User: ") I tried read_unt= il("Password: ") instead but didnt make any difference. If I use read_all(= ) I just get ,,, like there is nothing to read. in hyperterminal I had to = set the =93Send Line Ends with Line Feeds=94 option for it to work. I thou= ght by using "\r\n" would emulate the same thing?