old_contents: import sys
  import connection as CN
  import serial
  import os
  import time
  
  host = "127.0.0.1"
  port=7645
  serial_device_basename = "/dev/ttyACM"
  serial_device_init = 3
  baudrate = 9600
  
  def open_serial():
      #serial.tools.list_ports
      serial_device = False
      for i in range(serial_device_init,8):
          try: 
              os.stat(serial_device_basename+str(i))
              serial_device = serial_device_basename+str(i)
              break
          except FileNotFoundError:
              pass
      if not serial_device:
          print("Error, cannot find a valid serial device")
          sys.exit(2)
      print("Opening serial device " + serial_device)
      return serial.Serial(serial_device, baudrate, timeout=0)
  
  def read(s):
      while not s.inWaiting(): pass
      line = s.readline().decode('utf-8')
      return line
  
  def connect():
      socket = CN.Client(host,port)
      socket.connect()
      return socket
  
  serial_con = open_serial()
  try:
      client = connect()
  except ConnectionRefusedError:
      print("Cannot connect to server")
      sys.exit(2)
  
  while True:
      data = read(serial_con)
      print(data)
      client.send(data.encode())
      time.sleep(0.2)
  
  client.close()
  
  
new_contents: #!/usr/bin/env python2.7
  import sys
  import connection as CN
  import serial
  import os
  import time
  import argparse
  
  host = "127.0.0.1"
  port=7645
  serial_device_basename = "/dev/ttyACM"
  serial_device_init = 3
  baudrate = 9600
  
  def parse_args():
    parser = argparse.ArgumentParser(
        description='Trastos monitor')
    parser.add_argument(
        '-d',
        dest='serial_device',
        type=str,
        default=None,
        help='Serial device')
    parser.add_argument(
        '-i',
        dest='recolector_id',
        type=int,
        default=0,
        help='Recolector identifier')
    return parser.parse_args()
  
  def open_serial(device):
      #serial.tools.list_ports
      if device == None:
        serial_device = False
        for i in range(serial_device_init,8):
            try: 
                os.stat(serial_device_basename+str(i))
                serial_device = serial_device_basename+str(i)
                break
            except Exception as e:
                print(e)
                pass
  
        if not serial_device:
            print("Error, cannot find a valid serial device.")
            sys.exit(2)
      else: serial_device = device
      print("Opening serial device " + serial_device)
      return serial.Serial(serial_device, baudrate, timeout=0)
  
  def read(s):
      while not s.inWaiting(): pass
      line = s.readline().decode('utf-8')
      return line
  
  def connect():
      socket = CN.Client(host,port)
      socket.connect()
      return socket
  
  args = parse_args()
  recolector_id = args.recolector_id
  serial_con = open_serial(args.serial_device)
  
  try:
      client = connect()
  except ConnectionRefusedError:
      print("Cannot connect to server")
      sys.exit(2)
  
  while True:
      data = str(recolector_id)+":"+read(serial_con)
      print(data)
      client.send(data.encode())
      time.sleep(0.2)
  
  client.close()
  
  
subject: Add command line parameters to specify device and identifier