Problems reading registers using FTDI USB-RS485 adapter on Linux

701 views
Skip to first unread message

Hal Martin

unread,
Mar 22, 2015, 9:58:03 AM3/22/15
to libm...@googlegroups.com
Hello,

I am trying to read the registers in a Rail 350V 3-phase electricity
meter over RS-485 using an FTDI RS-485 to USB adapter ( FTDI
USB-RS485-WE-1800-BT )

However the communication is very unreliable at all the supported bit
rates from the meter (4800, 9600, 19200). Reading the registers works
perhaps 1 time in 25, which seems quite unreliable considering the
device is only about 2m away. There are no other devices attached to the
modbus network.

Has anyone else experienced difficulty reading from a modbus device
using an FTDI adapter before? I have tried to read the device using
Windows modbus software from http://modbustools.com/ which seems quite
reliable (no obvious errors are encountered across multiple register
reads). However I would like to read the device in Linux not Windows,
and this unreliability is quite high considering the circumstances.

Thanks,
Hal Martin

== C test application ==

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <modbus.h>

int main(int argc, char *argv[]) {

modbus_t *ctx;
uint16_t tab_reg[64];
int rc;
int i;

ctx = modbus_new_rtu("/dev/ttyUSB0", 19200, 'N', 8, 1);
if (ctx == NULL) {
fprintf(stderr, "Unable to create the libmodbus context\n");
return -1;
}
modbus_set_slave(ctx, 1);
modbus_set_debug(ctx, TRUE);
if (modbus_connect(ctx) == -1) {
fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
modbus_free(ctx);
return -1;
}

rc = modbus_read_registers(ctx, 2819, 10, tab_reg);
if (rc == -1) {
fprintf(stderr, "%s\n", modbus_strerror(errno));
return -1;
}

for (i=0; i < rc; i++) {
printf("reg[%d]=%d (0x%X)\n", i, tab_reg[i], tab_reg[i]);
}

modbus_close(ctx);
modbus_free(ctx);
}

== END ==

== FTDI USB adapter ==

Bus 003 Device 017: ID 0403:6001 Future Technology Devices
International, Ltd FT232 USB-Serial (UART) IC
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0403 Future Technology Devices International, Ltd
idProduct 0x6001 FT232 USB-Serial (UART) IC
bcdDevice 6.00
iManufacturer 1 FTDI
iProduct 2 USB-RS485 Cable
iSerial 3 FT******
bNumConfigurations 1

== END==

== C program output ==

[hmartin@localhost tmp]$ ./a.out
Opening /dev/ttyUSB0 at 19200 bauds (N, 8, 1)
[01][03][02][00][00][0A][C4][75]
Waiting for a confirmation...
ERROR Connection reset by peer: read
Connection reset by peer
[hmartin@localhost tmp]$ ./a.out
Opening /dev/ttyUSB0 at 19200 bauds (N, 8, 1)
[01][03][02][00][00][0A][C4][75]
Waiting for a confirmation...
ERROR Connection reset by peer: read
Connection reset by peer
[hmartin@localhost tmp]$ ./a.out
Opening /dev/ttyUSB0 at 19200 bauds (N, 8, 1)
[01][03][02][00][00][0A][C4][75]
Waiting for a confirmation...
ERROR Connection reset by peer: read
Connection reset by peer
[hmartin@localhost tmp]$ ./a.out
Opening /dev/ttyUSB0 at 19200 bauds (N, 8, 1)
[01][03][02][00][00][0A][C4][75]
Waiting for a confirmation...
ERROR Connection reset by peer: read
Connection reset by peer

(repeated approximately 30 more times)

[hmartin@localhost tmp]$ ./a.outmodbus_set_response_timeout(ctx,
&response_timeout);
Opening /dev/ttyUSB0 at 19200 bauds (N, 8, 1)
[01][03][02][00][00][0A][C4][75]
Waiting for a confirmation...
<01><03><14><00><00><00><05><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><B0><36>

reg[0]=0 (0x0)
reg[1]=5 (0x5)
reg[2]=0 (0x0)
reg[3]=0 (0x0)
reg[4]=0 (0x0)
reg[5]=0 (0x0)
reg[6]=0 (0x0)
reg[7]=0 (0x0)
reg[8]=0 (0x0)
reg[9]=0 (0x0)
[hmartin@localhost tmp]$

== END ==

Hal Martin

unread,
Mar 22, 2015, 10:02:51 AM3/22/15
to libm...@googlegroups.com
Sorry I forgot to add:

libmodbus: 3.0.6

Arch Linux
Linux localhost 3.18.6-1-ARCH #1 SMP PREEMPT Sat Feb 7 08:44:05 CET 2015
x86_64 GNU/Linux

libmodbus backend: RTU

Chuck Watson

unread,
Mar 22, 2015, 10:16:01 AM3/22/15
to libm...@googlegroups.com
Try installing bias resisters as shown here.

http://www.ni.com/support/serial/resinfo.htm

I had a problem with this device and called the manufacturer. This is what they suggested and it corrected the issue. The +5VDC is available in the cable.

Chuck Watson BS, CEM, CMVP
Direct USA 724-799-1529
--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes libmodbus.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/d/optout .

Reply all
Reply to author
Forward
0 new messages