Пример #1
0
            /// <summary>
            /// Поиск устройств доступных для подключения
            /// </summary>
            /// <returns> кол-во устройств доступных для подключения </returns>
            public Int16 SearchDevice()
            {
                //cmbDevList.SelectedIndex = iCurrentIndex;
                FT_HANDLE ftHandle = new FT_HANDLE();
                FT_DEVICE ftDevice;
                FT_STATUS ftStatus;
                Int16 numDevs;

                string MyText = "";

                ftStatus = FT_ListDevices(&numDevs, null, FT_LIST_NUMBER_ONLY);

                if (ftStatus == FT_STATUS.FT_OK)
                {
                    MyText += "Number of devices is: " + numDevs.ToString() + "\n";
                }
                else
                {
                    MyText += "Error";
                }

                DevInformation = new DevData[numDevs];
                //pN->NumDeviceInLine=numDevs;

                for (int i = 0; i < numDevs; i++)
                {

                    ftStatus = FT_Open((uint)i, ref ftHandle);
                    if (ftStatus != FT_STATUS.FT_OK)
                    {
                        MyText += "Open failed\n";
                        continue;
                    }
                    byte Tim = 1;
                    ftStatus = FT_SetLatencyTimer(ftHandle,
                        Tim);

                    Tim = 0;
                    ftStatus = FT_GetLatencyTimer(ftHandle,
                        ref Tim);

                    MyText += "Dev " + i.ToString() + " - ";

                    if (ftStatus == FT_STATUS.FT_OK)
                    {
                        MyText += "\tTim="; MyText += Tim;
                    }
                    else
                    {
                        MyText += "FAILED\n";
                    }
                    string devSerial = "";
                    string devDescription = "";
                    byte[] SerialNumber = new byte[16];
                    byte[] sDescription = new byte[64];
                    uint devID = 0;
                    FT_DEVICE devType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    fixed (byte* pS = &SerialNumber[0])
                    fixed (byte* pD = &sDescription[0])
                    {
                        ftStatus = FT_GetDeviceInfo(
                            ftHandle
                            , ref devType
                            , ref devID
                            , pS
                            , pD
                            , 0);
                    }

                    for (int j = 0; j < SerialNumber.Length; j++)
                    {
                        if ((char)SerialNumber[j] == '\0') break;
                        devSerial += (char)SerialNumber[j];
                    }

                    for (int j = 0; j < sDescription.Length; j++)
                    {
                        if ((char)sDescription[j] == '\0') break;
                        devDescription += (char)sDescription[j];
                    }

                    DevData CurDev = new DevData()
                                 {
                                     DevDescription = devDescription,
                                     DevID = devID,
                                     DevInfo = devType,
                                     DevSerial = devSerial
                                 };
                    DevInformation[i] = CurDev;

                    FT_Close(ftHandle);

                }
                return numDevs;
            }