Exemple #1
0
        /// <summary>
        /// Initialize the FTDI device
        /// </summary>
        /// <param name="info">The node info of FTDI device</param>
        /// <returns>The number of FTDI device connected</returns>
        /// <exception cref="FTDIException"> When there are failures in the procedure</exception>
        public uint FTDevInit(out FTDeviceListInfoNode[] info)
        {
            uint devNum = 0;

            status = DllWraper.FT_CreateDeviceInfoList(ref devNum);
            if (status != FTStatus.OK)
            {
                throw new FTDIException(status);
            }
            if (devNum == 0)
            {
                info = null;
                return(devNum);
            }
            // Allocate the memory for unmanaged data
            IntPtr ptrInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FTDeviceListInfoNode)) * (int)devNum);

            // Allocate memory for managed data
            info   = new FTDeviceListInfoNode[devNum];
            status = DllWraper.FT_GetDeviceInfoList(ptrInfo, ref devNum);
            if (status != FTStatus.OK)
            {
                throw new FTDIException(status);
            }
            for (int i = 0; i < devNum; i++)
            {
                IntPtr ptrElement         = new IntPtr(ptrInfo.ToInt64() + Marshal.SizeOf(typeof(FTDeviceListInfoNode)) * i);
                FTDeviceListInfoNode node = (FTDeviceListInfoNode)Marshal.PtrToStructure(ptrElement, typeof(FTDeviceListInfoNode));
                info[i] = node;
            }
            Marshal.FreeHGlobal(ptrInfo);
            return(devNum);
        }
Exemple #2
0
        /// <summary>
        /// Get the Information of Channel
        /// </summary>
        /// <param name="channel">The index of channel</param>
        /// <exception cref="FTDIException">When Get channel information failed</exception>
        /// <returns>The Device Info Class</returns>
        public DeviceInfo GetChannelInfo(uint channel)
        {
            FTDeviceListInfoNode node = new FTDeviceListInfoNode();

            status = SPIDllDriver.SPI_GetChannelInfo(channel, ref node);
            if (status != FTStatus.OK)
            {
                throw new FTDIException(status);
            }
            return(node);
        }
Exemple #3
0
 public static extern FTStatus SPI_GetChannelInfo(uint index, ref FTDeviceListInfoNode chanInfo);