private static bool ReceiveByteFromBitBangStream(out byte value)
        {
            value = 0;
            try
            {
                Ftd2Xx.FT_STATUS ftStatus;
                uint             bytesRead;

                if (_recBufLastIndex < 0)
                {   // all buffers empty
                    //Debug.WriteLine("Start");
                    ftStatus = Ftd2Xx.FT_ReadWrapper(_handleFtdi, BitBangRecBuffer[0], BitBangRecBufferSize, 0, out bytesRead);
                    if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK)
                    {
                        return(false);
                    }
                    ftStatus = Ftd2Xx.FT_ReadWrapper(_handleFtdi, BitBangRecBuffer[1], BitBangRecBufferSize, 0, out bytesRead);
                    if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK)
                    {
                        return(false);
                    }
                    _recBufLastIndex = 1;
                    _recBufReadPos   = 0;
                    _recBufReadIndex = 0;
                }
                else
                {
                    if (_recBufLastIndex == _recBufReadIndex)
                    {   // get next buffer
                        //Debug.WriteLine("New buf");
                        _recBufLastIndex = (_recBufLastIndex == 0) ? 1 : 0;
                        ftStatus         = Ftd2Xx.FT_ReadWrapper(_handleFtdi, BitBangRecBuffer[_recBufLastIndex], BitBangRecBufferSize, 0, out bytesRead);
                        if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK)
                        {
                            _recBufLastIndex = -1;
                            return(false);
                        }
                    }
                }
                if (!GetByteFromDataStream(out value))
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
        public static bool InterfaceReceiveData(byte[] receiveData, int offset, int length, int timeout, int timeoutTelEnd, EdiabasNet ediabasLog)
        {
            if (_handleFtdi == (IntPtr)0)
            {
                return(false);
            }
#if WindowsCE
            if (timeout < ReadTimeoutCeMin)
            {
                timeout = ReadTimeoutCeMin;
            }
            if (timeoutTelEnd < ReadTimeoutCeMin)
            {
                timeoutTelEnd = ReadTimeoutCeMin;
            }
#endif
            try
            {
                int recLen;
#if USE_BITBANG
                if (_bitBangMode)
                {
                    recLen = 0;
                    while (recLen < length)
                    {
                        int  currTimeout = (recLen == 0) ? timeout : timeoutTelEnd;
                        long startTime   = Stopwatch.GetTimestamp();
                        for (; ;)
                        {
                            byte value;
                            if (ReceiveByteFromBitBangStream(out value))
                            {
                                receiveData[offset + recLen] = value;
                                recLen++;
                                break;
                            }
                            if (recLen >= length)
                            {
                                break;
                            }
                            if ((Stopwatch.GetTimestamp() - startTime) > currTimeout * TickResolMs)
                            {
                                if (ediabasLog != null)
                                {
                                    ediabasLog.LogData(EdiabasNet.EdLogLevel.Ifh, receiveData, offset, recLen, "Rec ");
                                }
                                return(false);
                            }
                        }
                    }
                    if (ediabasLog != null)
                    {
                        ediabasLog.LogData(EdiabasNet.EdLogLevel.Ifh, receiveData, offset, recLen, "Rec ");
                    }
                    return(true);
                }
#endif
                uint bytesRead;

                Ftd2Xx.FT_STATUS ftStatus = Ftd2Xx.FT_SetTimeouts(_handleFtdi, (uint)timeout, WriteTimeout);
                if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK)
                {
                    return(false);
                }
                ftStatus = Ftd2Xx.FT_ReadWrapper(_handleFtdi, receiveData, 1, offset, out bytesRead);
                if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK)
                {
                    return(false);
                }
                recLen = (int)bytesRead;
                if (recLen < 1)
                {
                    return(false);
                }
                if (recLen < length)
                {
                    ftStatus = Ftd2Xx.FT_SetTimeouts(_handleFtdi, (uint)timeoutTelEnd, WriteTimeout);
                    if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK)
                    {
                        return(false);
                    }
                    while (recLen < length)
                    {
                        ftStatus = Ftd2Xx.FT_ReadWrapper(_handleFtdi, receiveData, length - recLen, offset + recLen, out bytesRead);
                        if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK)
                        {
                            return(false);
                        }
                        if (bytesRead <= 0)
                        {
                            break;
                        }
                        recLen += (int)bytesRead;
                    }
                }
                if (ediabasLog != null)
                {
                    ediabasLog.LogData(EdiabasNet.EdLogLevel.Ifh, receiveData, offset, recLen, "Rec ");
                }
                if (recLen < length)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }