Open GoogleCodeExporter opened 9 years ago
Hi, I use Mtester & QModbus for all my testing, "Illegal data value" means
either your starting address is incorrect or you are trying to read too many
registers at once. Using Mtester the starting address is 1 and the amount of
registers to read is 9 when referring to the slave example. It includes the
offset starting address.
When using QModbus the starting address is 0.
Original comment by bester.j...@gmail.com
on 28 Dec 2012 at 9:08
Thanks for replay,
I found my mistake and now I can control arduino via modbus.Now i want to
configurate arduino ethernet as tcp/modbus master and read data from other
arduinos and send data to server whith tcp protocol.Is this possible and
how can I do this.
Original comment by dilie...@gmail.com
on 7 Jan 2013 at 8:33
In addition to Modbus ASCII and RTU there also exist a Modbus/TCP protocol but
this must be targeted on the TCP layer and adhere to the Modbus/TCP standard
and is going to be hard work to port.
I would suggest (and maybe this is what you meant :-) that you just set up as
much packets with different array registers as you need with SimpleModbusMaster
and then use the array of data as any other data when using the TCP library.
Original comment by bester.j...@gmail.com
on 9 Jan 2013 at 8:50
I Have been using libmodbus rtu pc as master smart energy meter as a slave while sending a read command i'll always get illegal data value repeatedly
/*
//#include "slave.h" /* The goal of this program is to check all major functions of libmodbus:
read_registers
All these functions are called with random values on a address range defined by the following defines. */
/* At each loop, the program works in the range ADDRESS_START to
int main(int argc,char argv[]) { modbus_t ctx; int rc; int i; // char x[5]; float tab_reg[128]; int code ; //uint16_t command[100]=; ; // int nb_fail; // int nb_loop; // int addr; / RTU / // modbus_rtu_set_serial_mode(ctx);
//code=atoi(argv[1]);
int Slave_ID;
Slave_ID=atoi(argv[1]);
code=atoi(argv[2]);
// list();
/ printf("Please enter the slave ID: \n");
for(i=22;i<=23;i++) {
printf("->Enter ID %d for slave %d: \n",i, i);
}
/
int c;
FILE *file;
file = fopen("/home/aviconn/opt/openHAB/distribution-1.7.0-runtime/configurations/slave", "r");
if (file) {
while ((c = getc(file)) != EOF)
putchar(c);
fclose(file);
}
printf("\n");
//printf("Please enter the slave ID: ");
//scanf("%d",&Slave_ID);
/* if(Slave_ID==22 || Slave_ID==23)
{
printf ("slave is present");
}
else{
printf("slave is absent");
}
/ FILE fp = popen("ls -1 /dev/ttyUSB", "r"); char path[500]; / Read the output a line at a time - output it. */ printf("\n%s\n", "Available USBs are:"); //while (fgets(path, sizeof(path)-1, fp) != NULL) { for (int j=0; fgets(path, sizeof(path)-1, fp) != NULL; ++j) { printf("[%d] %s\n", j, path); }
/ for(int k=0; x[k] != NULL; k++) { printf("%s\n",x[k]); }/ // printf("enter the required USB port "); // gets(x);
/* char a[20]= "/dev/ttyUSB"; char b[1]; scanf("%s", &b); strcat(a,b);
printf("\n-------------------------------------------------------------------------------------------------------------------------\n");
ctx = modbus_new_rtu(a, 9600, 'N', 8, 1);
*/
ctx = modbus_new_rtu("/dev/ttyUSB0", 9600, 'N', 8, 1);
modbus_set_slave(ctx, Slave_ID);
modbus_set_debug(ctx, TRUE);
modbus_set_error_recovery(ctx,
MODBUS_ERROR_RECOVERY_LINK |
MODBUS_ERROR_RECOVERY_PROTOCOL);
if (modbus_connect(ctx) == -1) {
fprintf(stderr, "Connection failed: %s\n",
modbus_strerror(errno));
modbus_free(ctx);
return -1;
}
if (code==03)
{
tab_reg[0]=atoi(argv[3]);
tab_reg[1]=atoi(argv[4]);
tab_reg[2]=atoi(argv[5]);
tab_reg[3]=atoi(argv[6]);
tab_reg[4]=atoi(argv[7]);
tab_reg[5]=atoi(argv[8]);
tab_reg[6]=atoi(argv[9]);
tab_reg[7]=atoi(argv[10]);
tab_reg[8]=atoi(argv[11]);
//tab_reg[9]=atoi(argv[12]);
/*tab_reg[10]=atoi(argv[13]);
tab_reg[11]=atoi(argv[14]);
tab_reg[12]=atoi(argv[15]);
tab_reg[13]=atoi(argv[16]);*/
//tab_reg[14]=atoi(argv[17]); //tab_reg[15]=atoi(argv[18]); //tab_reg= {61,73,71,,72,31,00}; //tab_reg[10] //tab_reg[11]
//tab_reg[0]="61 73 6d 5f 71 6b 72 5f 31 00";
//tab_reg[0]=argv[3];
rc = modbus_read_registers(ctx, 1001, 4, tab_reg);
if (rc == -1) {
fprintf(stderr, "%s\n", modbus_strerror(errno));
return -1;
}
for (i=0; i < rc; i++) {
printf("reg[%d]=%d (0x%X)\n", i, tab_reg[i], tab_reg[i]);
}
}
// modbus_set_slave(ctx, Slave_ID); if(code==10) { tab_reg[0]=atoi(argv[3]); tab_reg[1]=atoi(argv[4]); tab_reg[2]=atoi(argv[5]); tab_reg[3]=atoi(argv[6]); tab_reg[4]=atoi(argv[7]); tab_reg[5]=atoi(argv[8]); tab_reg[6]=atoi(argv[9]); tab_reg[7]=atoi(argv[10]); tab_reg[8]=atoi(argv[11]); tab_reg[9]=atoi(argv[12]); //tab_reg[10]=atoi(argv[13]) //tab_reg[11]=atoi(argv[14]); rc = modbus_write_registers(ctx, 1000, 20, tab_reg); if (rc == -1) { fprintf(stderr, "%s\n", modbus_strerror(errno)); return -1; }
for (i=0; i < rc; i++) { printf("reg[%d]=%d (0x%X)\n", i, tab_reg[i], tab_reg[i]); } }
modbus_close(ctx); modbus_free(ctx);
return 0;
}
Original issue reported on code.google.com by
dilie...@gmail.com
on 8 Dec 2012 at 10:14