How to config RS485

Issue #23 new
Hani Jorfi
created an issue

hi, I have to read data via a RS485 in python 2 on linux which must I use? Device or BitBangDevice as I did with C# I had to change Setbitmode but here I dont know how

Comments (4)

  1. Ben Bass repo owner

    Hi Hani,

    I've not used RS485 before, but as an asynchronous protocol, I assume you want to use Device() or SerialDevice() - not BitBangDevice().

    Looking at the libftdi docs, the only references to RS-485 or the TXDEN line is around EEPROM setup, but I assume that's already done with your device?

    Without more info (e.g. which FTDI device are you using, which version of libftdi) I'm not sure I can provide more help...

  2. Hani Jorfi reporter

    it is a USB TO RS485 UART SERIAL CONVERTER PCB from FTDICHIP company, which connects a board with installed sensors to computer, I need to set bitmode but I dont find it,s method

  3. Ben Bass repo owner

    The Device class has a ftdi_fn 'forwarder' attribute which supplies the FTDI context as the first argument to libftdi functions automatically.

    This means that to call the ftdi_set_bitmode function, create a Device instance and call device.ftdi_fn.ftdi_set_bitmode(...). For example, the standard Device() class resets a device to RS232 mode on startup (so it's in a known state) using the following:

    self.ftdi_fn.ftdi_set_bitmode(0, BITMODE_RESET)

    whereas BitBangDevice does the following:

    # new_dir is the set of 'direction' bits, self.bitbang_mode defaults to 1
    self.ftdi_fn.ftdi_set_bitmode(new_dir, self.bitbang_mode)

    So to set bitmask to 0 and mode to e.g. 5, do the following:

    dev = Device()
    dev.ftdi_fn.ftdi_set_bitmode(0, 5)

    Reference - note that the ftdi_context is provided automatically.

    I hope this answers your question.

  4. Hani Jorfi reporter

    i did set bitmode with the same values I did in C# and it send's mee data but it looks the data are not correct values, here is my code

    With Device () as fd:
          if fd._opened==True:
          fd.ftdi_fn.ftdi_set_bitmode(0xff, 0x20)
          fd.ftdi_fn.ftdi_set_bitmode(0xff, 0x20)
          print "Device Read:", fd.readlines()
  5. Log in to comment