private static bool SetBitBangOutput(BitBangBits output) { if (_handleFtdi == (IntPtr)0) { return(false); } try { BitBangSendBuffer[0] = (byte)output; uint bytesWritten; Ftd2Xx.FT_STATUS ftStatus = Ftd2Xx.FT_WriteWrapper(_handleFtdi, BitBangSendBuffer, 1, 0, out bytesWritten); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { return(false); } } catch (Exception) { return(false); } return(true); }
public static bool InterfaceSetBreak(bool enable) { if (_handleFtdi == (IntPtr)0) { return(false); } #if USE_BITBANG if (enable) { _bitBangOutput &= ~BitBangBits.Txd; } else { _bitBangOutput |= BitBangBits.Txd; } if (_bitBangMode) { if (!SetBitBangOutput(_bitBangOutput)) { return(false); } return(true); } #endif try { Ftd2Xx.FT_STATUS ftStatus = enable ? Ftd2Xx.FT_SetBreakOn(_handleFtdi) : Ftd2Xx.FT_SetBreakOff(_handleFtdi); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { return(false); } } catch (Exception) { return(false); } return(true); }
public static bool InterfaceSetRts(bool rts) { if (_handleFtdi == (IntPtr)0) { return(false); } #if USE_BITBANG if (rts) { _bitBangOutput &= ~BitBangBits.Rts; } else { _bitBangOutput |= BitBangBits.Rts; } if (_bitBangMode) { if (!SetBitBangOutput(_bitBangOutput)) { return(false); } return(true); } #endif try { Ftd2Xx.FT_STATUS ftStatus = rts ? Ftd2Xx.FT_SetRts(_handleFtdi) : Ftd2Xx.FT_ClrRts(_handleFtdi); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { 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); }