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.