Communication problem.

Home Forums MultiConnect OCG Communication problem.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2649
    JM K
    Participant

    Hi,

    I have been so far unsuccessful in trying to communicate with a PLC (Modbus Slave) from a SCADA (Modbus Master). I am using the latest version of libmodbus 3.0.1. All cables are perfectly fine. I even tested the serial port on the SCADA Device (Modbus Master) and made sure it is working well. The strange thing is I am not even able to detect any errors. My program is:

    #include”stdio.h”

    #include”stdlib.h”

    #include”modbus/modbus.h”

    int main(void)

    {

    modbus_t *ctx;

    int rc;

    int nb_fail;

    int nb_loop;

    long int addr;

    int nb;

    uint8_t *tab_rq_bits;

    uint8_t *tab_rp_bits;

    uint16_t *tab_rq_registers;

    uint16_t *tab_rw_rq_registers;

    uint16_t *tab_rp_registers;

    ctx = modbus_new_rtu(“/dev/ttyS2”,9600,’N’,8,1);

    modbus_set_slave(ctx, 1);

    if (ctx == NULL) {

    fprintf(stderr, “Unable to create the libmodbus contextn”);

    return -1;

    }

    if (modbus_connect(ctx) == -1) {

    printf(“Connexion failed: %sn”,stderr);

    modbus_free(ctx);

    return -1;

    }

    printf(“Connection Status: %d and %d, (modbus_connect(ctx)),ctx);

    modbus_close(ctx);

    modbus_free(ctx);

    }

    The output is:

    Connection Status:0 and 69640

    I get the same output though the cable that connects the serial port on the PLC is disconnected. I went through the doc folder and checked the modbus_Connect() page and it says that this function will return 0 only when it is successful.

    My questions are:

    1. Why is the function returning 0 even though there is in reality no ‘connection’ established?

    2. Is there any way to do a sort of loop back test using the same program to make sure that the program is opening the serial port?

    3. In general when the CDP tries to communicate over modbus on the serial port is there a way to check if a program that initiates communication is successfully opening the port?

    While I understand that this forum is not exactly the right place to ask questions regarding libmodbus, I would always appreciate any suggestions that might help solve this issue.

    I would appreciate it if my questions are answered. Thank you very much.

    Best Regards,

    JM

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.