zzeroo / libmodbus-rs

Libmodbus bindings for Rust
http://zzeroo.github.io/libmodbus-rs/
GNU Lesser General Public License v2.1
10 stars 5 forks source link

implementation of 'rtu_set_custom_rts' #18

Open fel115 opened 1 year ago

fel115 commented 1 year ago

I require the activation of 2 pins in the high state during transmission, and in the low state for receiving. To achieve this, I need to utilize the 'rtu_set_custom_rts' function. Alternatively, is there another approach to accomplish the same task?

fel115 commented 1 year ago

This is the link to the documentation

fel115 commented 1 year ago

our custom rts-function should look like the following code. fd_273 and fd_272 are the file-descriptor to our PINs which should be set.

void set_rts_custom(modbus_t *ctx, int on){
    if (on){
        if (write(fd_272, "1", 1) != 1) {
            perror("Error writing to /sys/class/gpio/gpio272/value");
            exit(1);
        }
        if (write(fd_273, "1", 1) != 1) {
            perror("Error writing to /sys/class/gpio/gpio273/value");
            exit(1);
        }
    }else{
        if (write(fd_272, "0", 1) != 1) {
            perror("Error writing to /sys/class/gpio/gpio272/value");
            exit(1);
        }
        if (write(fd_273, "0", 1) != 1) {
            perror("Error writing to /sys/class/gpio/gpio273/value");
            exit(1);
        }
    }
}

This works fine in C, but we would like to use this function also in Rust