Data stills on read buffer..

Asked by Nuno Santos

Hello Sirs,

I'm using the 2.9.3 version and sometimes when I try to do some consecutive readings I'm getting a weird behavior.
In my application ( in this case for a energy meter) I have a list of registers, and in a middle of it, I have to read register 2825 and next the register 2837 (which is the scale to calculate the current real value).
The expected value for register 2825 is about 30 (current value) and for 2837 is 2.
So I read the register 2825 and I get 31, I store this value and next I read the register 2837 to get the scale and I get the same value (31). The read buffer seems that was not cleared.
This issue was being happening many times, so now I'm calling the modbus_flush function before each reading, thus the problem occurs much less times, but stills happening.

Is there anything that I can do to avoid this behavior? Is this a libmodbus 2.9.3 bug?

Thanks in advance,
Nuno Santos

Question information

Language:
English Edit question
Status:
Solved
For:
libmodbus Edit question
Assignee:
No assignee Edit question
Solved by:
Nuno Santos
Solved:
Last query:
Last reply:
Revision history for this message
Stéphane Raimbault (sra) said :
#1

Do you check the result of the modbus function call before accessing the value in the array of registers? If the remote device is slow, there is may be a timeout (see the doc to increase)

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#2

Hello Stéphane,

Thanks for your reply.
Yes I had checked. No error returned.

Best regards,
Nuno

Revision history for this message
Stéphane Raimbault (sra) said :
#3

Which OS do you use? Have you try to run the unit tests on your platform?
Could you post the code used to read the registers?

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#4

Hello Stéphane,

I'm using ubuntu 10.04. I'did't try the unit tests. I tryed with libmodbus 2.0.3 and it works good.

My reading function:

int DeviceConnModbusWrapper::read( uint16_t* oDataRead, int aRegAddr, int aNumberOfReg, ERegType aRegType)
{
 int retVal = -100;

 if ( aRegType == EHoldingReg){
  //For config and status registers reading...
  LogManager::getLogManager()->write("Reading holding registers - address: %d | number of registers: %d ", 5, aRegAddr, aNumberOfReg );

#ifdef LIBMODBUS_293
  modbus_flush(iMbParam);
  retVal = modbus_read_registers( iMbParam, aRegAddr, aNumberOfReg, oDataRead);
#else
  retVal = read_holding_registers( iMbParam, iDevConnSettings->slaveId, aRegAddr, aNumberOfReg, oDataRead);
#endif

 return retVal;
}

Note:
retVal is checked by the function that call this reading function.

When I made debug, I had reproduced the error, and despite retVal not being below zero, the value that I got in oDataRead is the value related of last read executed ( as I already explained in first post).

Since libmodbus 2.0.3 version is working fine (also in other modbus device with other application), I will keep this version until a more stable version on 2.9.3 is released.

Best regards,
Nuno Santos

Revision history for this message
Stéphane Raimbault (sra) said :
#5

libmodbus 3.0 won't be more stable if you don't help us to find the problem! And I'm intend to release 3.0 shortly...

Are you sure to set the slave when required with libmodbus 2.9.3?
Could you enable debug mode with modbus_set_debug(ctx, TRUE) and compare the requests between 2.0.3 and 2.9.3, please?

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#6

I'm setting the slave once, after modbus_new_tcp().

Ok. As soon as possible, I will compare the requests and provide the logs here as well.

Thanks, best regards,
Nuno

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#7

Hello Stéphane,

I recompiled my code with libmodbus 2.9.3 version, but surprisingly, this time I did not find any error.
I try several times but the error that use to come up in a couple of times, this time did not happen.
However, I will let the application running a couple of days and then I tell you something.

If I could do something else to help you, please tell me.

Below are the logs. No error found.

w/ libmodbus 2.9.3:

Reading value:
[00][0D][00][00][00][06][01][03][0B][08][00][01]
Waiting for a confirmation...
<00><0D><00><00><00><05><01><03><02><09><40>
Reading scale:
[00][0E][00][00][00][06][01][03][0B][16][00][01]
Waiting for a confirmation...
<00><0E><00><00><00><05><01><03><02><00><02>

w/ libmodbus 2.0.3:

Reading value:
[00][0D][00][00][00][06][01][03][0B][08][00][01]
Waiting for a message (11 bytes)...
<00><0D><00><00><00><05><01><03><02><09><58>
Reading scale:
[00][0E][00][00][00][06][01][03][0B][16][00][01]
Waiting for a message (11 bytes)...
<00><0E><00><00><00><05><01><03><02><00><02>

Best Regards,
Nuno Santos

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#8

Hello Stéphane,

It looks like 2.9.3 version has no issue.
Maybe the issue I reported was related with the equipment, nevertheless the 2.0.3 was always dealing well with that..

Now my application is built with 2.9.3 and i will keep with that.
Thanks.

If you need something else please tell me.

Best Regards,
Nuno Santos

Revision history for this message
Stéphane Raimbault (sra) said :
#9

Thank you to have taken time to check with libmodbus 2.9.3 again.