Response not from requested slave

559 views
Skip to first unread message

f mariani

unread,
Feb 12, 2015, 9:49:17 AM2/12/15
to libm...@googlegroups.com
Hi all,
this is my code:
#include <iostream>
#include <stdio.h>
#include "modbus.h"
#include <string.h>

//parameters for modbus_new_rtu
int  baud  = 9600;        //baud rate
char par   = 'O';        //parity
int  d_bit = 8;            //number of bits of data
int  s_bit = 1;            //bits of stop
int  slave = 2;

//parameters for modbus_read_registers
int index =    501;
int n_reg = 2;


using namespace std;

int main(){

    modbus_t
*ctx;
    uint16_t tab_reg
[64];
    uint32_t old_response_to_sec
;
    uint32_t old_response_to_usec
;
    uint32_t new_response_to_sec
;
    uint32_t new_response_to_usec
;
   
int rc;

    ctx
= modbus_new_rtu("COM2", baud, par, d_bit, s_bit);  //modbus_t *modbus_new_rtu(const char *device, int baud, char parity, int data_bit, int stop_bit);
   
int s_stat = modbus_set_slave(ctx, slave);
   
if (s_stat == -1) {
        fprintf
(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free
(ctx);
       
return -1;
   
}
   
else
        cout
<< "Slave index: "<<slave<<endl;
   
   
if (modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485) == -1)
        fprintf
(stderr, "Unable to set mode: %s\n", modbus_strerror(errno));
   
    modbus_set_debug
(ctx, TRUE);
    modbus_get_response_timeout
(ctx, &old_response_to_sec, &old_response_to_usec);

   
int c_stat = modbus_connect(ctx);
   
if (c_stat == -1) {
        fprintf
(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free
(ctx);
       
return -1;
   
}
   
else
        cout
<< "Connection started"<< endl;    

    modbus_get_response_timeout
(ctx, &new_response_to_sec, &new_response_to_usec);
   
if ((old_response_to_sec == new_response_to_sec) && (old_response_to_usec == new_response_to_usec)){
        cout
<< "No response timeout modification on connect"<<endl;
   
}
   
else{
        cout
<< "Response timeout modification on connect"<<endl;
       
return -1;
   
}
   
    rc
= modbus_read_registers(ctx, index, n_reg, tab_reg);
   
if (rc == -1){
        cout
<< "read failed: " << modbus_strerror(errno) << endl;
       
return -1;
   
}
   
else {
       
for (int i = 0; i<rc; i++){
            cout
<< "reg[" << i << "] = " << tab_reg[i] << endl;
       
}
   
}

    free
(tab_reg);
    modbus_close
(ctx);
    modbus_free
(ctx);
    system
("PAUSE");
   
return 0;
}
when I run the program this is the error:
Slave index: 1
Unable to set mode: Unknown error
Opening COM2 at 9600 bauds (O, 8, 1)
Connection started
No response timeout modification on connect[01][03][01][F5][00][02][D5][C5]
Waiting for a confirmation...
<FD><FB><F7><FF><FD>
Request for slave 253 ignored (not 1)
The responding slave 253 isn't the requested slave 1
read failed: Response not from requested slave
My network is composed by my computer (master) and a plc Panasonic FP-X0. This error is shown only if I set the right address of the slave. If I don't set the right slaveID this is the error:
Slave index: 1
Unable to set mode: Unknown error
Opening COM2 at 9600 bauds (O, 8, 1)
Connection started
No response timeout modification on connect
[01][03][01][F5][00][02][D5][C5]
Waiting for a confirmation...
ERROR
Unknown error: select
read failed
: Unknown error
And the same happen when I try to write on a holding register.
Seem that something goes wrong with the response of PLC and not in the master trasmission.
Which could be the problem?
I found this discussion:
https://groups.google.com/forum/?hl=IT#!searchin/libmodbus/response$20not$20from$20requested/libmodbus/FgOkfWCLu-0/6LVc5e2gkoEJ
but the way followed buy this guys is no good for me because my code is the same of their corrected one.

I'm clueless. Somebody help me :(((.

Regards,
Federico.



Eduardo Wirth

unread,
May 5, 2015, 8:46:26 PM5/5/15
to libm...@googlegroups.com
Hello Mariani
you tried to use modbus_rtu_set_rts....
...

Christophe Lemaire

unread,
Jan 27, 2017, 10:40:42 AM1/27/17
to libmodbus
Hello,

I have the same problem to communicate with a electrical counter.

Do you have a solution ?
Reply all
Reply to author
Forward
0 new messages