public static bool InterfaceConnect(string port, object parameter) { if (_handleFtdi != (IntPtr)0) { return(true); } try { Ftd2Xx.FT_STATUS ftStatus; if (!port.StartsWith(PortId, StringComparison.OrdinalIgnoreCase)) { InterfaceDisconnect(); return(false); } string portData = port.Remove(0, PortId.Length); if ((portData.Length > 0) && (portData[0] == ':')) { // special id if (portData.StartsWith(":SER=", StringComparison.OrdinalIgnoreCase)) { // serial number string id = portData.Remove(0, 5); ftStatus = Ftd2Xx.FT_OpenEx(id, Ftd2Xx.FT_OPEN_BY_SERIAL_NUMBER, out _handleFtdi); } else if (portData.StartsWith(":DESC=", StringComparison.OrdinalIgnoreCase)) { // description string id = portData.Remove(0, 6); ftStatus = Ftd2Xx.FT_OpenEx(id, Ftd2Xx.FT_OPEN_BY_DESCRIPTION, out _handleFtdi); } else if (portData.StartsWith(":LOC=", StringComparison.OrdinalIgnoreCase)) { // location long loc = EdiabasNet.StringToValue(portData.Remove(0, 5)); ftStatus = Ftd2Xx.FT_OpenEx((IntPtr)loc, Ftd2Xx.FT_OPEN_BY_LOCATION, out _handleFtdi); } else { InterfaceDisconnect(); return(false); } if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } } else { uint usbIndex = Convert.ToUInt32(port.Remove(0, PortId.Length)); ftStatus = Ftd2Xx.FT_Open(usbIndex, out _handleFtdi); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } } #if USE_BITBANG _bitBangMode = false; _bitBangOutput = BitBangBits.Dtr | BitBangBits.Rts | BitBangBits.Txd; #endif ftStatus = Ftd2Xx.FT_SetBitMode(_handleFtdi, 0x00, Ftd2Xx.FT_BITMODE_RESET); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } ftStatus = Ftd2Xx.FT_SetUSBParameters(_handleFtdi, UsbBufferSizeStd, UsbBufferSizeStd); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } ftStatus = Ftd2Xx.FT_SetLatencyTimer(_handleFtdi, 2); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } ftStatus = Ftd2Xx.FT_SetBaudRate(_handleFtdi, Ftd2Xx.FT_BAUD_9600); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } _currentBaudRate = 9600; ftStatus = Ftd2Xx.FT_SetDataCharacteristics(_handleFtdi, Ftd2Xx.FT_BITS_8, Ftd2Xx.FT_STOP_BITS_1, Ftd2Xx.FT_PARITY_NONE); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } _currentWordLength = 8; _currentParity = EdInterfaceObd.SerialParity.None; ftStatus = Ftd2Xx.FT_SetTimeouts(_handleFtdi, 0, WriteTimeout); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } ftStatus = Ftd2Xx.FT_SetFlowControl(_handleFtdi, Ftd2Xx.FT_FLOW_NONE, 0, 0); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } ftStatus = Ftd2Xx.FT_ClrDtr(_handleFtdi); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } ftStatus = Ftd2Xx.FT_ClrRts(_handleFtdi); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } ftStatus = Ftd2Xx.FT_Purge(_handleFtdi, Ftd2Xx.FT_PURGE_TX | Ftd2Xx.FT_PURGE_RX); if (ftStatus != Ftd2Xx.FT_STATUS.FT_OK) { InterfaceDisconnect(); return(false); } } catch (Exception) { InterfaceDisconnect(); return(false); } return(true); }