Socket programming with NetCom serial-to-ethernet module

Ryan Swindle swindle at ifa.hawaii.edu
Tue Nov 10 01:24:19 CET 2009


Hi,

This is my first Python-list post; I hope it's going to the right place.
 Here's my problem:

I've read many tutorials on socket programming, but I can't seem to piece
them together for my particular case.  I have 3 serial ports, each of which
individually connects to a port on a NetCom box, which converts them to
TCP/IP ports (see e.g.
http://www.serialgear.com/4--Port-Serial-TCP-IP-NETCOM-411.html).  But I'll
just focus on communicating with 1 serial port right now (assume that I have
a 1-port NetCom box).  So, the flow pattern goes like this -- ascii string
from my Python program via the ethernet card to the NetCom box, which feeds
the serial port; this serial port is the input/output to a board that
controls a motor.  So, I can send an ascii string like "MI100\n", which
tells that motor to move 100 steps.  Currently, I can accomplish this using
sockets.  But if I instead want to request something from the motor, like
it's current position, how do I return this information back to my Python
program and still keep the socket alive and listening for say another
position request?

FYI, the NetCom box works on DHCP.  So, I could use 'arp' or another method
to actually find it's IP address, and I can connect to it using say port
2000.  At this point, it looks as if I would setup a server socket for the
NetCom box, and then create a client socket for the motor controller board
to talk to the NetCom box (and e.g. give the current position of the motor,
upon my request).  But the hard part seems to be how to retrieve that
information from the controller board, once it responds.  For instance, if I
were to just use pySerial, I open up a connection to the serial port, then
serial.send(ascii) sends the request, and serial.readline() reads the
response.  I need to know how to implement this basic functionality with
sockets, where the sockets remain alive and listening after each
request/response, just as pySerial does.

Any advice, sockets or not, is helpful and appreciated, and I can elaborate
further on the problem, if requested.  (Again, I hope this was not a misuse
of the list in some way; I apologize, if so).  Many thanks.

-Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091109/996df185/attachment.html>


More information about the Python-list mailing list