[newbie] trying socket as a replacement for nc
Jean Dubois
jeandubois314 at gmail.com
Wed Dec 11 18:08:00 EST 2013
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
More information about the Python-list
mailing list