telnet to Cognex In-Sight 4001 camera
chris.annin at gmail.com
chris.annin at gmail.com
Mon Feb 25 20:16:59 EST 2013
On Monday, February 25, 2013 9:02:54 AM UTC-8, chris... at 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
More information about the Python-list
mailing list