modbus_rtu_set_custom_rts

406 views
Skip to first unread message

Noel

unread,
Jun 17, 2016, 6:17:09 AM6/17/16
to libmodbus
My target hardware is ar9331 where the RTS is shared with the reset line. Rather than modify this I'd like to use io/8 as RTS.

I found the function modbus_rtu_set_custom_rts might do what I need. I can then just write the set_rts function to operate my io/8.

Unfortunately I can not find any example of use of this function on the web at all. Could anyone post one maybe?

I wrote my application using this function and compiled. Something starting as such:

    ctx = modbus_new_rtu("/dev/ttyATH0", 9600, 'N', 8, 2);
    modbus_set_debug
(ctx, 1);
    modbus_set_slave
(ctx, 103);
    modbus_rtu_set_serial_mode
(ctx, MODBUS_RTU_RS232);
    modbus_rtu_set_rts
(ctx, MODBUS_RTU_RTS_DOWN);
    modbus_rtu_set_custom_rts
(ctx, csetrts());

with

void csetrts(modbus_t *ctx, int on){
   
int gpio = 8;
   
if (on){
        gpioSet
(gpio, 0);
   
}
   
else{
        gpioSet
(gpio, 1);
   
}
}


However I get a segmentation fault when I run it. I tracked down the issue coming from _modbus_rtu_send when it hits the line:
ctx_rtu->set_rts(ctx, ctx_rtu->rts == MODBUS_RTU_RTS_UP);

My function csetrts works perfectly fine when called on its own. But it seems to fail when called by _modbus_rtu_send.

Noel

unread,
Jun 21, 2016, 6:03:46 PM6/21/16
to libmodbus
I sorted something out for myself but I had to modify modbus-rtu.c file.

I included my custom function in this file. This is the only way I could get this to work.

I am still very keen to see how this is intended to be coded in the state of art. Documentation does not give any example unfortunately.

I figured out from the libmodbus code that modbus_rtu_set_custom_rts must be called before modbus_rtu_set_rts. (not what my example says).

Noel

unread,
Jun 25, 2016, 6:51:51 AM6/25/16
to libmodbus
Am I the first one to use this function?

Noel

unread,
Jul 4, 2016, 10:59:33 AM7/4/16
to libmodbus
Just a post a link in relation to that issue:
https://github.com/stephane/libmodbus/pull/189

Still looking for a helpful hand about this. Thank you.

Gianluca Di Simone

unread,
Dec 9, 2016, 11:44:19 AM12/9/16
to libmodbus
Hi Noel, do you solved problem? i also need to use that function, can you share example of use?

Ggianluca
Message has been deleted

Arvind Allawadi

unread,
Jul 19, 2017, 5:00:01 PM7/19/17
to libmodbus
Just a query: during sending data, DE pin (one gpio) should be high, as well as RE/ pin (another gpio) should be high too?! right?

Arvind Allawadi

unread,
Jul 19, 2017, 5:55:47 PM7/19/17
to libmodbus
how are you making on=1? as we can't pass arguments but only address of the function pointer?! any help would be appreciated, thanks!!


On Friday, 17 June 2016 03:17:09 UTC-7, Noel wrote:
Reply all
Reply to author
Forward
0 new messages