public void SetDefaultSetting(ref TFtConfigData ftData)
 {
     ftData.BaudRate = FT_BAUD_250000;//FT_INDEX_BAUD_115200;
     ftData.DataBits = FT_BITS_8;
     ftData.StopBits = FT_STOP_BITS_1;
     ftData.Parity = FT_PARITY_NONE;
     ftData.FlowControl = FT_FLOW_NONE;
     ftData.RtsHi = true;
     ftData.DtrHi = true;
     ftData.Xon = 0x11;
     ftData.Xoff = 0x13;
     ftData.EventChar = 0;
     ftData.ErrorChar = 0;
     ftData.EventCharEnabled = false;
     ftData.ErrorCharEnabled = false;
     ftData.CtsHi = false;
     ftData.DsrHi = false;
     ftData.DcdHi = false;
     ftData.RingHi = false;
     ftData.RxTimeout = 15;//FT_DEFAULT_RX_TIMEOUT;
     ftData.TxTimeout = 10;//FT_DEFAULT_TX_TIMEOUT;
     ftData.EventMask = 0;
 }
            public bool SetSettingPort(FT_HANDLE ftHandle, TFtConfigData* ftData)
            {
                uint BaudRate;
                byte WordLength;
                byte StopBits;
                UInt16 FlowControl;
                byte XonChar;
                byte XoffChar;
                FT_STATUS ftStatus;

                ftStatus = FT_ResetDevice(ftHandle);
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    goto close;
                }

                BaudRate = ftData->BaudRate;
                ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    goto close;
                }

                WordLength = (byte)(ftData->DataBits);

                switch (ftData->StopBits)
                {
                    default:
                        StopBits = FT_STOP_BITS_1;
                        break;
                    case 1:
                        StopBits = FT_STOP_BITS_2;
                        break;
                }

                ftStatus = FT_SetDataCharacteristics(
                    ftHandle,
                    WordLength,
                    StopBits,
                    ftData->Parity
                    );
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    goto close;
                }

                FlowControl = FT_FLOW_NONE;
                XonChar = 0;
                XoffChar = 0;

                switch (ftData->FlowControl)
                {

                    case 0:	// NONE
                    default:
                        break;

                    case 1:	// RTS
                        FlowControl = FT_FLOW_RTS_CTS;
                        break;

                    case 2:	// DTR
                        FlowControl = FT_FLOW_DTR_DSR;
                        break;

                    case 3:	// XON/XOFF
                        FlowControl = FT_FLOW_XON_XOFF;
                        XonChar = ftData->Xon;
                        XoffChar = ftData->Xoff;
                        break;

                }

                ftStatus = FT_SetFlowControl(
                    ftHandle,
                    FlowControl,
                    XonChar,
                    XoffChar
                    );
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    goto close;
                }

                ftStatus = FT_SetChars(
                    ftHandle,
                    ftData->EventChar,
                    ftData->EventCharEnabled ? (byte)1 : (byte)0,
                    ftData->ErrorChar,
                    ftData->ErrorCharEnabled ? (byte)1 : (byte)0
                    );
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    goto close;
                }

                FT_SetEventNotification(ftHandle, ftData->EventMask, null);

                if (ftData->DtrHi)
                {
                    FT_SetDtr(ftHandle);
                }
                else
                {
                    FT_ClrDtr(ftHandle);
                }

                if (ftData->RtsHi)
                {
                    FT_SetRts(ftHandle);
                }
                else
                {
                    FT_ClrRts(ftHandle);
                }

                FT_SetTimeouts(ftHandle, ftData->RxTimeout, ftData->TxTimeout);

                FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX);

                return true;

                close:
                FT_Close(ftHandle);
                return false;
            }
            public int ConnectWithSetting(uint NumDev, TFtConfigData ftData)
            {
                //Открытие устройства

                FT_STATUS ftStatus;

                FT_Close(curFtHandle);
                ftStatus = FT_Open(NumDev, ref curFtHandle);
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    return 1;
                }
                byte Tim = 1;
                ftStatus = FT_SetLatencyTimer(curFtHandle,
                    Tim);
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    return 1;
                }
                Tim = 0;
                ftStatus = FT_GetLatencyTimer(curFtHandle,
                    ref Tim);
                //FT_Close(ftHandle);
                if (ftStatus != FT_STATUS.FT_OK)
                {
                    return 1;
                }
                if (SetSettingPort(curFtHandle, &ftData) == false) return 1;
                // curFtHandle = ftHandle;
                return 0;
            }