stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.44k stars 1.75k forks source link

unit test server fails for bad error reponse test case #6

Closed harihanv closed 13 years ago

harihanv commented 13 years ago

When i was testing the libmodbus 2.9.3 , i observed the following error in the server

Waiting for a indication...

<11><03><00><9E><00><1E><7E> ERROR CRC received 1E7E != CRC calculated 2ECC Quit the loop: Invalid CRC and iwith client TEST MANUAL EXCEPTION: [11][03][00][6C][00][03][C7][46] Waiting for a confirmation... <11><03><06><02><2B><00><00><00><00><51> - modbus_read_registers at special address: FAILED I made it working by adding modbus_flush at the end of the loop. Regards harish
stephane commented 13 years ago

Which loop? Could you send me your modified code? Do you use the new the tarball for v2.9.3?

harihanv commented 13 years ago

I have used the tarball v2.9.3. To pass all the test cases, I have modified for loop in the unit-test-server.c to flush data. please find the snippet of code for reference, i have also marked "modbus_flush" function in bold.

for (;;) { rc = modbus_receive(ctx, -1, query); if (rc == -1) { /* Connection closed by the client or error */ break; }

    /* Read holding registers */
    if (query[header_length] == 0x03) {
        if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 3)
            == UT_REGISTERS_NB_POINTS_SPECIAL) {
            printf("Set an incorrect number of values\n");
            MODBUS_SET_INT16_TO_INT8(query, header_length + 3,
                                     UT_REGISTERS_NB_POINTS);
        } else if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 1)
            == UT_REGISTERS_ADDRESS_SPECIAL) {
            modbus_reply_exception(ctx, query,
                                   MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY);
            continue;
        }
    }

    rc = modbus_reply(ctx, query, rc, mb_mapping);
    if (rc == -1) {
        break;
    }

    modbus_flush(ctx);
stephane commented 13 years ago

OK, it's just a workaround but unit tests contain many strange things on purpose so I don't want to hide them with this call. I don't have the problem on my computer so could you post at least 25 lines of history of server/client tests (github offers a pastebin like). Did you use TCP tests on localhost?