Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

c program for modbus TCP/ip

gowtham1000gowtham1000 Posts: 3Member
hi guys......

i written a code for modbus TCP/ipfor reading and writing holding registers in C. there is a compilition problem in ubuntu. i need to compile it , help me guys.....; u can find the code below...............



#include
#include
#include
#include
#include
#include
/* compiling : gcc master-program.c -o master-program.c -lmodbus */
main ()
modbus_t=modbus_connect;
stuct timeval old respose_timeout;
stuct timeval response_time out;
modbus*ctx;
set_slave;
rc;
wr;
int i;
uint16_t*tab_reg;
const uint16_t*ut_reg
modbus_error_recoverymode* error recovery_link
modbus_connect("128.2.2.1",302);
void modbus_set_socket("128.2.2.1",302);
server_socket=modbus_tcp_listen(ctx;nb_connection);
int modbus_set_slave(ctx,0*FF);
modbus_set_response_timeout(ctx,timeout);
/* Save original timeout */
modbus_get_response_timeout(ctx, &old_response_timeout);

/* Define a new and too short timeout! */
response_timeout.tv_sec = 0;
response_timeout.tv_usec = 0;
modbus_set_error_recovery(ctx,modbus_error_recover_link);
if (rc!== -1) {
printf("sterror recovery_failed%s/n"modbus_set_error recovery)(error);
rc_waiting for reply=0;
}
modbus_read_registers(ctx,ut_reg_adress,ut_reg_nb,tab_reg);
rc=ut_reg_nb;
if(rc=-1) {
fprintf(stderr,"%s/n");
modbus_sterror(errno);
return -1
}
for(i=0 i<rc;i++) {
printf("reg[%d]=%d (0x%X)
", i, tab_reg[i], tab_reg[i]);
}
modbus_write_registers(ctx,ut_reg_adress,ut_reg_nb,ut_reg);
wr=modbus_write_registers;
if (wr=1) {
printf("modebus_write succesful%s/n");
("src[%d]=%d (0x%X)
");
}
void modbus_close(ctx);

}




Sign In or Register to comment.