Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39896 > unrolled thread
| Started by | chris.annin@gmail.com |
|---|---|
| First post | 2013-02-25 09:02 -0800 |
| Last post | 2013-02-25 20:44 -0500 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.python
telnet to Cognex In-Sight 4001 camera chris.annin@gmail.com - 2013-02-25 09:02 -0800
Re: telnet to Cognex In-Sight 4001 camera MRAB <python@mrabarnett.plus.com> - 2013-02-25 17:29 +0000
Re: telnet to Cognex In-Sight 4001 camera chris.annin@gmail.com - 2013-02-25 11:48 -0800
Re: telnet to Cognex In-Sight 4001 camera chris.annin@gmail.com - 2013-02-25 11:48 -0800
Re: telnet to Cognex In-Sight 4001 camera chris.annin@gmail.com - 2013-02-25 17:16 -0800
Re: telnet to Cognex In-Sight 4001 camera Roy Smith <roy@panix.com> - 2013-02-25 20:44 -0500
| From | chris.annin@gmail.com |
|---|---|
| Date | 2013-02-25 09:02 -0800 |
| Subject | telnet to Cognex In-Sight 4001 camera |
| Message-ID | <d0462043-2195-4272-b13d-fd04d1d87695@googlegroups.com> |
Hello, ive been struggling with this for a couple weeks now and was hoping someone might be able to help. I have an older Cognex camera that I need to communicate with via telnet. I can get a response from the camera when 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:
[code]
>>>import sys
>>>import telnetlib
>>>HOST = "10.31.18.21"
>>>USER = "admin"
>>>tn = telnetlib.Telnet(HOST)
>>>tn.read_until("Login: ")
"Welcome to In-Sight(R) 4001 Session 1\r\nUser:"
>>>tn.write(USER + "\r\n")
>>>tn.read_until("User: ")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\telnetlib.py", line 319,
return self.read_very_lazy()
File "C:\Python27\lib\telnetlib.py", line 395,
raise EOFError, 'telnet connection closed'
EOFError: telnet connection closed
>>>
[\code]
if i do a read_all instead of read_until for user I just get "..." returned. Im assuming tn.write command isnt working? any help would be greatly appreciated.
thank you
Chris
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-02-25 17:29 +0000 |
| Message-ID | <mailman.2511.1361813390.2939.python-list@python.org> |
| In reply to | #39896 |
On 2013-02-25 17:02, chris.annin@gmail.com wrote:
> Hello, ive been struggling with this for a couple weeks now and was hoping someone might be able to help. I have an older Cognex camera that I need to communicate with via telnet. I can get a response from the camera when 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:
> [code]
>>>>import sys
>>>>import telnetlib
>>>>HOST = "10.31.18.21"
>>>>USER = "admin"
>>>>tn = telnetlib.Telnet(HOST)
>>>>tn.read_until("Login: ")
> "Welcome to In-Sight(R) 4001 Session 1\r\nUser:"
The returned string ends with "User:", presumably the prompt to enter
the username, which makes we wonder whether you should be reading until
"User:" instead of until "Login: ".
>>>>tn.write(USER + "\r\n")
Should you be ending that with just "\r" or just "\n" instead? (That
would be equivalent to typing the username and then pressing the Return
key.)
>>>>tn.read_until("User: ")
Haven't you already seen "User: "?
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "C:\Python27\lib\telnetlib.py", line 319,
> return self.read_very_lazy()
> File "C:\Python27\lib\telnetlib.py", line 395,
> raise EOFError, 'telnet connection closed'
> EOFError: telnet connection closed
>>>>
> [\code]
>
> if i do a read_all instead of read_until for user I just get "..." returned. Im assuming tn.write command isnt working? any help would be greatly appreciated.
>
[toc] | [prev] | [next] | [standalone]
| From | chris.annin@gmail.com |
|---|---|
| Date | 2013-02-25 11:48 -0800 |
| Message-ID | <961815dc-dc33-4afc-92e7-a3c01274b057@googlegroups.com> |
| In reply to | #39899 |
On Monday, February 25, 2013 9:29:54 AM UTC-8, MRAB wrote:
> On 2013-02-25 17:02, chris.annin@gmail.com wrote:
>
> > Hello, ive been struggling with this for a couple weeks now and was hoping someone might be able to help. I have an older Cognex camera that I need to communicate with via telnet. I can get a response from the camera when 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:
>
> > [code]
>
> >>>>import sys
>
> >>>>import telnetlib
>
> >>>>HOST = "10.31.18.21"
>
> >>>>USER = "admin"
>
> >>>>tn = telnetlib.Telnet(HOST)
>
> >>>>tn.read_until("Login: ")
>
> > "Welcome to In-Sight(R) 4001 Session 1\r\nUser:"
>
>
>
> The returned string ends with "User:", presumably the prompt to enter
>
> the username, which makes we wonder whether you should be reading until
>
> "User:" instead of until "Login: ".
>
>
>
> >>>>tn.write(USER + "\r\n")
>
>
>
> Should you be ending that with just "\r" or just "\n" instead? (That
>
> would be equivalent to typing the username and then pressing the Return
>
> key.)
>
>
>
> >>>>tn.read_until("User: ")
>
>
>
> Haven't you already seen "User: "?
>
>
>
> > Traceback (most recent call last):
>
> > File "", line 1, in
>
> > File "C:\Python27\lib\telnetlib.py", line 319,
>
> > return self.read_very_lazy()
>
> > File "C:\Python27\lib\telnetlib.py", line 395,
>
> > raise EOFError, 'telnet connection closed'
>
> > EOFError: telnet connection closed
>
> >>>>
>
> > [\code]
>
> >
>
> > if i do a read_all instead of read_until for user I just get "..." returned. Im assuming tn.write command isnt working? any help would be greatly appreciated.
>
yea you are right I shouldnt be doing read_until("User: ") I tried read_until("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 “Send Line Ends with Line Feeds” option for it to work. I thought by using "\r\n" would emulate the same thing?
[toc] | [prev] | [next] | [standalone]
| From | chris.annin@gmail.com |
|---|---|
| Date | 2013-02-25 11:48 -0800 |
| Message-ID | <mailman.2520.1361822516.2939.python-list@python.org> |
| In reply to | #39899 |
On Monday, February 25, 2013 9:29:54 AM UTC-8, MRAB wrote:
> On 2013-02-25 17:02, chris.annin@gmail.com wrote:
>
> > Hello, ive been struggling with this for a couple weeks now and was hoping someone might be able to help. I have an older Cognex camera that I need to communicate with via telnet. I can get a response from the camera when 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:
>
> > [code]
>
> >>>>import sys
>
> >>>>import telnetlib
>
> >>>>HOST = "10.31.18.21"
>
> >>>>USER = "admin"
>
> >>>>tn = telnetlib.Telnet(HOST)
>
> >>>>tn.read_until("Login: ")
>
> > "Welcome to In-Sight(R) 4001 Session 1\r\nUser:"
>
>
>
> The returned string ends with "User:", presumably the prompt to enter
>
> the username, which makes we wonder whether you should be reading until
>
> "User:" instead of until "Login: ".
>
>
>
> >>>>tn.write(USER + "\r\n")
>
>
>
> Should you be ending that with just "\r" or just "\n" instead? (That
>
> would be equivalent to typing the username and then pressing the Return
>
> key.)
>
>
>
> >>>>tn.read_until("User: ")
>
>
>
> Haven't you already seen "User: "?
>
>
>
> > Traceback (most recent call last):
>
> > File "", line 1, in
>
> > File "C:\Python27\lib\telnetlib.py", line 319,
>
> > return self.read_very_lazy()
>
> > File "C:\Python27\lib\telnetlib.py", line 395,
>
> > raise EOFError, 'telnet connection closed'
>
> > EOFError: telnet connection closed
>
> >>>>
>
> > [\code]
>
> >
>
> > if i do a read_all instead of read_until for user I just get "..." returned. Im assuming tn.write command isnt working? any help would be greatly appreciated.
>
yea you are right I shouldnt be doing read_until("User: ") I tried read_until("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 “Send Line Ends with Line Feeds” option for it to work. I thought by using "\r\n" would emulate the same thing?
[toc] | [prev] | [next] | [standalone]
| From | chris.annin@gmail.com |
|---|---|
| Date | 2013-02-25 17:16 -0800 |
| Message-ID | <71787193-b4aa-438f-a8f1-058873346e27@googlegroups.com> |
| In reply to | #39896 |
On Monday, February 25, 2013 9:02:54 AM UTC-8, chris...@gmail.com wrote:
> Hello, ive been struggling with this for a couple weeks now and was hoping someone might be able to help. I have an older Cognex camera that I need to communicate with via telnet. I can get a response from the camera when 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:
>
> [code]
>
> >>>import sys
>
> >>>import telnetlib
>
> >>>HOST = "10.31.18.21"
>
> >>>USER = "admin"
>
> >>>tn = telnetlib.Telnet(HOST)
>
> >>>tn.read_until("Login: ")
>
> "Welcome to In-Sight(R) 4001 Session 1\r\nUser:"
>
> >>>tn.write(USER + "\r\n")
>
> >>>tn.read_until("User: ")
>
> Traceback (most recent call last):
>
> File "<stdin>", line 1, in <module>
>
> File "C:\Python27\lib\telnetlib.py", line 319,
>
> return self.read_very_lazy()
>
> File "C:\Python27\lib\telnetlib.py", line 395,
>
> raise EOFError, 'telnet connection closed'
>
> EOFError: telnet connection closed
>
> >>>
>
> [\code]
>
>
>
> if i do a read_all instead of read_until for user I just get "..." returned. Im assuming tn.write command isnt working? any help would be greatly appreciated.
>
>
>
> thank you
>
>
>
> Chris
After much goofing around I figured out that every time I read from this Cognex 4000 series camera the connection either goes dead or disconnects. If I simply stop trying to read_until or read_all and just write everything it works fine. here is what worked for me:
import sys
import telnetlib
host = "10.31.18.21"
tn = telnetlib.Telnet(host)
tn.write("admin\r\n") #the user name is admin
tn.write("\r\n") #there is no password - just return - now logged in
tn.write("SO0\r\n") #"SO"=cognex "set online" therefore "SO0" = camera offline
tn.write("LFsomevisionjob.job\r\n") #"LF" = cognex native command "load file"
tn.write("SO1\r\n") #"SO"=cognex "set online" therefore "SO1" = camera online
tn.close()
I doubt anyone has a camera this old they are trying to telnet to in python but if so maybe this thread will help someone out.
thanks again for all your replies - really appreciate you guys helping me out.
Chris
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-02-25 20:44 -0500 |
| Message-ID | <roy-076098.20441925022013@news.panix.com> |
| In reply to | #39919 |
In article <71787193-b4aa-438f-a8f1-058873346e27@googlegroups.com>, chris.annin@gmail.com wrote: > On Monday, February 25, 2013 9:02:54 AM UTC-8, chris...@gmail.com wrote: > > Hello, ive been struggling with this for a couple weeks now and was hoping > > someone might be able to help. I have an older Cognex camera that I need > > to communicate with via telnet. I can get a response from the camera when > > 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. Two suggestions I can make. One is to use the command-line telnet utility to talk to the camera. Verify that you can at least make a connection and authenticate that way. Second, use a packet sniffer to watch the actual traffic going back and forth to the camera. On a Unix box, I would do: $ tcpdump -s 0 -A host 10.31.18.21 but it looks like you're on windows, so you'll want to use Wireshark (http://www.wireshark.org/) instead of tcpdump. If you're not familiar with TCP protocol details, you'll want to read up on it so you can properly interpret what tcpdump or Wireshark is telling you.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web