C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
c program for modbus TCP/ip Posted by gowtham1000 on 18 Jan 2013 at 1:48 AM
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 <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <modbus.h>
/* 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)\n", 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)\n");
}
void modbus_close(ctx);

}







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.