Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61825
| Date | 2013-12-13 16:35 +0100 |
|---|---|
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| Subject | Re: [newbie] trying socket as a replacement for nc |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4072.1386948939.18130.python-list@python.org> (permalink) |
----- Original Message -----
> I have an ethernet-rs232 adapter which allows me to connect to a
> measurement instrument by means of netcat on a linux system.
> e.g. entering nc 10.128.59.63 7000
> allows me to enter e.g.
> *IDN?
> after which I get an identification string of the measurement
> instrument back.
> I thought I could accomplish the same using the python module
> "socket"
> and tried out the sample program below which doesn't work however:
> #!/usr/bin/env python
>
> """
> A simple echo client
> """
> import socket
> host = '10.128.59.63'
> port = 7000
> size = 10
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((host,port))
> s.send('*IDN?')
> data = s.recv(size)
> s.close()
> print 'Received:', data
>
> Can anyone here tell me how to do it properly?
> thanks in advance
> jean
Such equipment often implements a telnet protocol. Have use try using the telnetlib module ?
http://docs.python.org/2/library/telnetlib.html
t = Telnet(host, port)
t.write('*IDN?')
print t.read_until('Whateverprompt')
# you can use read_very_eager also
JM
-- IMPORTANT NOTICE:
The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-13 16:35 +0100
Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-14 05:33 -0800
Re: [newbie] trying socket as a replacement for nc Dan Stromberg <drsalists@gmail.com> - 2013-12-14 17:03 -0800
Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-15 07:35 -0800
Re: [newbie] trying socket as a replacement for nc Chris Angelico <rosuav@gmail.com> - 2013-12-16 02:50 +1100
Re: [newbie] trying socket as a replacement for nc Dan Stromberg <drsalists@gmail.com> - 2013-12-15 13:14 -0800
csiph-web