title: RS485 modbus incomplete packets
body: <p>I have two usb to serial cables connected to each other on 2 different usb ports on the same pc. </p>
  
  <p>The ground and A and B cables are all connected to eachother. the voltage cable is isolated. </p>
  
  <p>When I send ASCII characters using a serial terminal i can communicate both ways.</p>
  
  <p>But when I run a python script for a modbus slave and a master It works sometimes and sometimes it doesnt. I cannot find a pattern in when it works and when not.</p>
  
  <p>I can see when it works all the sent bytes are received by the slave but when it doesnt work the slave receives atleast 1 byte but not the rest.
  Then it obviously gives a CRC error and crashes.
  How come some bytes are missing  through modbus and not ASCII serial terminals?</p>
  
  <p>Is this a hardware problem? How can I find out? I didnt connect extra resistors.</p>
  
  <p>I can show the code for the slave and master, Thanks</p>
  
  <p><a href="https://i.stack.imgur.com/OwDOE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OwDOE.jpg" alt="enter image description here"></a>
  As you can see I have three USB-to-serial cables connected in parallel, the orange and yellow cables are the A and B cables and the black ones are the grounds cables. </p>
  
  <p>The cables are these <a href="http://www.ftdichip.com/Products/Cables/USBRS485.htm" rel="nofollow noreferrer">http://www.ftdichip.com/Products/Cables/USBRS485.htm</a></p>
  
  <p>This is the slave code but I tried different libraries and got the same results so I doubt its the code:</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf_8 -*-
  """
   Modbus TestKit: Implementation of Modbus protocol in python
   (C)2009 - Luc Jean - luc.jean@gmail.com
   (C)2009 - Apidev - http://www.apidev.fr
   This is distributed under GNU LGPL license, see license.txt
  """
  
  import sys
  
  import modbus_tk
  import modbus_tk.defines as cst
  from modbus_tk import modbus_rtu
  import serial
  
  #PORT = 0
  PORT = '/dev/ttyUSB2'
  
  def main():
      """main"""
      logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s")
  
      #Create the server
      server = modbus_rtu.RtuServer(serial.Serial(port=PORT, baudrate=9600, bytesize=8, parity='N', stopbits=1, xonxoff=0))
  
      try:
          logger.info("running...")
          logger.info("enter 'quit' for closing the server")
  
          server.start()
  
          slave_1 = server.add_slave(1)
          slave_1.add_block('0', cst.HOLDING_REGISTERS, 0, 100)
          while True:
              cmd = sys.stdin.readline()
              args = cmd.split(' ')
  
              if cmd.find('quit') == 0:
                  sys.stdout.write('bye-bye\r\n')
                  break
  
              elif args[0] == 'add_slave':
                  slave_id = int(args[1])
                  server.add_slave(slave_id)
                  sys.stdout.write('done: slave %d added\r\n' % (slave_id))
  
              elif args[0] == 'add_block':
                  slave_id = int(args[1])
                  name = args[2]
                  block_type = int(args[3])
                  starting_address = int(args[4])
                  length = int(args[5])
                  slave = server.get_slave(slave_id)
                  slave.add_block(name, block_type, starting_address, length)
                  sys.stdout.write('done: block %s added\r\n' % (name))
  
              elif args[0] == 'set_values':
                  slave_id = int(args[1])
                  name = args[2]
                  address = int(args[3])
                  values = []
                  for val in args[4:]:
                      values.append(int(val))
                  slave = server.get_slave(slave_id)
                  slave.set_values(name, address, values)
                  values = slave.get_values(name, address, len(values))
                  sys.stdout.write('done: values written: %s\r\n' % (str(values)))
  
              elif args[0] == 'get_values':
                  slave_id = int(args[1])
                  name = args[2]
                  address = int(args[3])
                  length = int(args[4])
                  slave = server.get_slave(slave_id)
                  values = slave.get_values(name, address, length)
                  sys.stdout.write('done: values read: %s\r\n' % (str(values)))
  
              else:
                  sys.stdout.write("unknown command %s\r\n" % (args[0]))
      finally:
          server.stop()
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>EDIT: I just changed to baudrate to 115200 and the errors are way less. Is there anything else i can do?</p>