4 map a serial port to an outgoing TCP connection 5 Released under GNU GPLv3 or later 7 from __future__
import print_function
9 from argparse
import ArgumentParser
15 parser = ArgumentParser(description=__doc__)
16 parser.add_argument(
"--baudrate", default=57600, type=int, help=
"baud rate")
17 parser.add_argument(
"serialport", type=str, help=
"serial port")
18 parser.add_argument(
"desthost", type=str, help=
"destination host")
19 parser.add_argument(
"destport", type=int, help=
"destination port")
20 args = parser.parse_args()
22 serport = serial.Serial(args.serialport, args.baudrate, timeout=0)
30 tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
31 tcpsock.connect((args.desthost, args.destport))
32 tcpsock.setblocking(0)
33 print(
"Connected to %s:%u" % (args.desthost, args.destport))
47 n = serport.inWaiting()
60 b = tcpsock.recv(1000)
61 except socket.error
as e:
62 if e.args[0]
in [errno.EWOULDBLOCK, errno.EAGAIN]: