/* Receives a fixed block from the open com port. Returns when the block is completely filled or the timeout period has passed  */
int ReceiveComPortBlockComplete(ISP_ENVIRONMENT *IspEnvironment, void *block, size_t size, unsigned timeout)
/* Receives a fixed block from the open com port. Returns when the block is completely filled or the timeout period has passed  */
int ReceiveComPortBlockComplete(ISP_ENVIRONMENT *IspEnvironment, void *block, size_t size, unsigned timeout)
{
    unsigned long realsize = 0, read;
    char *result;
    char tmp_string[32];
    result = (char*) block;
    SerialTimeoutSet(IspEnvironment, timeout);
    do
    {
        ReceiveComPortBlock(IspEnvironment, result + realsize, size - realsize, &read);
        realsize += read;
    } while ((realsize < size) && (SerialTimeoutCheck(IspEnvironment) == 0));
    sprintf(tmp_string, "Answer(Length=%ld): ", realsize);
    DumpString(3, result, realsize, tmp_string);
    if (realsize != size)
    {
        return 1;
    }
    return 0;
}