コード例 #1
0
ファイル: FTDIDevice.cs プロジェクト: x154152/SmartTokens
        public string[] getDevicesNames()
        {
            uint nbDevices = 0;

            ftStatus = FtdiDevice.GetNumberOfDevices(ref nbDevices);
            if (nbDevices == 0)
            {
                return(null);
            }
            else
            {
                // Allocate storage for device info list
                FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[nbDevices];
                // Populate our device list
                ftStatus = FtdiDevice.GetDeviceList(ftdiDeviceList);

                if (ftStatus == FTDI.FT_STATUS.FT_OK)
                {
                    string[] deviceList = new string[nbDevices];
                    for (int i = 0; i < nbDevices; i++)
                    {
                        deviceList[i] = ftdiDeviceList[i].Description.ToString();
                    }
                    return(deviceList);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #2
0
        public ControllerFTDI(string description, string serialNumber)
        {
            this.dataOut       = new byte[8];
            this.dataInBuf     = new byte[200];
            this.DESCRIPTION   = description;
            this.SERIAL_NUMBER = serialNumber;
            this.SensorsList   = new List <Sensor>();

            ftdi   = new FTDI();
            status = ftdi.GetNumberOfDevices(ref this.devCount);
            CheckStatus(status);
            if (this.devCount == 0)
            {
                throw new Exception($"Devices not connected!");
            }
            this.deviceList = new FTDI.FT_DEVICE_INFO_NODE[this.devCount];
            status          = ftdi.OpenByDescription(DESCRIPTION);
            CheckStatus(status);
            Initialization();
            Purge();
            if (ResetAVR() != 80)
            {
                throw new FTDI.FT_EXCEPTION("Error: Reset AVR");
            }
            UpdateConnectedSensors(10, SensorsList);
        }
コード例 #3
0
        //------------------------------------------------ open()
        public void open(uint idx)
        {
            uint num_device = 0;

            ftdi.GetNumberOfDevices(ref num_device);
            Debug.WriteLine("Number of FTDI devices : " + num_device);
            FTDI.FT_DEVICE_INFO_NODE[] device_list = new FTDI.FT_DEVICE_INFO_NODE[num_device];
            ftdi.GetDeviceList(device_list);

            foreach (FTDI.FT_DEVICE_INFO_NODE device in device_list)
            {
                Debug.WriteLine("--");
                Debug.WriteLine("Flags  : " + device.Flags);
                Debug.WriteLine("Type   : " + device.Type);
                Debug.WriteLine("ID	    : " + device.ID);
                Debug.WriteLine("LocID  : " + device.LocId);
                Debug.WriteLine("Serial : " + device.SerialNumber);
                Debug.WriteLine("Info   : " + device.Description);
            }

            ftdi.OpenByIndex(idx);
            if (!ftdi.IsOpen)
            {
                throw (new SASEBO_G_Exception("Failed to open device."));
            }
            ftdi.SetTimeouts(500, 500);
        }
コード例 #4
0
        //ftdiデバイスを読み込んで、コンボボックスに挿入
        //初期読み込みに利用
        internal void ftdiDeviceEnumulate(System.Windows.Forms.ComboBox ftdiDeviceList)
        {
            ftdiDeviceList.Items.Clear();

            FTDI.FT_STATUS ftStatus = m_ftdiDevice.GetNumberOfDevices(ref m_ftdiDeviceCount);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }
            if (m_ftdiDeviceCount == 0)
            {
                return;
            }

            m_ftdiDeviceMap = new int[m_ftdiDeviceCount];
            for (int i = 0; i < m_ftdiDeviceCount; i++)
            {
                m_ftdiDeviceMap[i] = -1;
            }
            m_ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[m_ftdiDeviceCount];
            ftStatus         = m_ftdiDevice.GetDeviceList(m_ftdiDeviceList);
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (int i = 0; i < m_ftdiDeviceCount; i++)
                {
                    if (m_ftdiDeviceList[i].Type == FTDI.FT_DEVICE.FT_DEVICE_2232)
                    {
                        m_ftdiDeviceMap[ftdiDeviceList.Items.Count] = i;
                        string devName = string.Format("{0}: {1} ({2})", i, m_ftdiDeviceList[i].Description.ToString(), m_ftdiDeviceList[i].SerialNumber.ToString());
                        ftdiDeviceList.Items.Add(devName);
                    }
                }
                ftdiDeviceList.SelectedIndex = 0;
            }
        }
コード例 #5
0
        static void showOne()
        {
            FTDI ftdi_handle = new FTDI();

            FTDI.FT_STATUS ft_status;
            uint           devcount = 0;

            ft_status = ftdi_handle.GetNumberOfDevices(ref devcount);
            if (ft_status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Error getting number of devices.");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("FTDI devices connected: {0}", devcount);
            if (devcount == 0)
            {
                return;
            }
            FTDI.FT_DEVICE_INFO_NODE[] ft_dev_list = new FTDI.FT_DEVICE_INFO_NODE[devcount];
            ft_status = ftdi_handle.GetDeviceList(ft_dev_list);
            var serial_numbers = ft_dev_list.Select(h => h.SerialNumber);

            foreach (string st in serial_numbers)
            {
                if (st != null && st.CompareTo("") != 0)
                {
                    Console.WriteLine("Serial: {0}", st);
                }
            }

            string def_serial = serial_numbers.FirstOrDefault();

            if (def_serial == null || def_serial.CompareTo("") == 0)
            {
                Console.WriteLine("Error getting device serial");
                Console.ReadKey();
                return;
            }
            ft_status = ftdi_handle.OpenBySerialNumber(def_serial);

            ft_status = ftdi_handle.SetBaudRate(1);
            ft_status = ftdi_handle.SetBitMode(0x07, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG);

            uint buf = 0;

            int numberOfBytes;

            byte[] outb = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };

            int idx = 0;

            do
            {
                idx = (int)Char.GetNumericValue(Console.ReadKey().KeyChar);
                ftdi_handle.Write(outb, idx + 1, ref buf);
            } while (idx < 8);

            ftdi_handle.Close();
        }
コード例 #6
0
        void UpdatePorts()
        {
            FTDI      ftdi = new FTDI();
            FT_STATUS status;
            uint      numDevices = 0;

            status = ftdi.GetNumberOfDevices(ref numDevices);

            // filter valid devices
            // opened devices can not be displayed
            List <string> names = new List <string>((int)numDevices);
            List <FT_DEVICE_INFO_NODE> validDevices = new List <FT_DEVICE_INFO_NODE>((int)numDevices);

            if (numDevices > 0)
            {
                FT_DEVICE_INFO_NODE[] devices = new FT_DEVICE_INFO_NODE[numDevices];
                ftdi.GetDeviceList(devices);
                foreach (var d in devices)
                {
                    if ((d.Type != FT_DEVICE.FT_DEVICE_UNKNOWN) &&
                        (!String.IsNullOrEmpty(d.SerialNumber)))
                    {
                        validDevices.Add(d);
                        names.Add(String.Format("{0} ({1})", d.SerialNumber, d.Description));
                    }
                }
            }

            _Devices  = validDevices.ToArray();
            PortNames = names.ToArray();
        }
コード例 #7
0
ファイル: Controller.cs プロジェクト: Virtnv/ftdicomm
        // показать информацию о подключенном оборудовании
        public string ShowDeviceInfo()
        {
            uint devCount = 0;

            status = ftdi.GetNumberOfDevices(ref devCount);
            CheckStatus(status);
            if (devCount == 0)
            {
                throw new Exception($"Devices not connected!");
            }
            this.deviceList = new FTDI.FT_DEVICE_INFO_NODE[devCount];
            if (this.deviceList == null)
            {
                throw new Exception("Device List is empty!");
            }
            status = ftdi.GetDeviceList(this.deviceList);
            CheckStatus(status);
            string info = "";

            foreach (var device in this.deviceList)
            {
                info += $"\n\nDescription: {device.Description}\n" +
                        $"Flags: {device.Flags}\n" +
                        $"ftHandle: {device.ftHandle}\n" +
                        $"ID: {device.ID}\n" +
                        $"LocID: {device.LocId}\n" +
                        $"Serial Number: {device.SerialNumber}\n" +
                        $"Type: {device.Type}\n";
            }
            return(info);
        }
コード例 #8
0
        public static void CheckStatus(object state)
        {
            UInt32 ftdiDeviceCount = 0;

            FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;

            // Create new instance of the FTDI device class
            FTDI myFtdiDevice = new FTDI();

            // Determine the number of FTDI devices connected to the machine
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status

            // Allocate storage for device info list
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (UInt32 i = 0; i < ftdiDeviceCount; i++)
                {
                    if (ftdiDeviceList[i].SerialNumber == "A99C59XB")
                    {
                        Console.WriteLine("Device detected");
                    }
                }
            }
        }
コード例 #9
0
ファイル: GPIO.cs プロジェクト: Experica/Command
        public FTDIGPIO()
        {
            FTD2XX       = new FTDI();
            outputbuffer = new byte[8];
            inputbuffer  = new byte[8];

            if (FTD2XX.GetNumberOfDevices(ref ndevice) == FTDI.FT_STATUS.FT_OK)
            {
                if (ndevice > 0)
                {
                    devices  = new FTDI.FT_DEVICE_INFO_NODE[ndevice];
                    FTSTATUS = FTD2XX.GetDeviceList(devices);
                    if (FTD2XX.OpenByDescription(devices[0].Description) == FTDI.FT_STATUS.FT_OK)
                    {
                        Config();
                        Found = true;
                    }
                    else
                    {
                        Debug.LogWarning($"Can Not Open Device: {devices[0].Description}.");
                    }
                }
                else
                {
                    Debug.LogWarning("No FTDI Device Detected.");
                }
            }
            else
            {
                Debug.LogWarning("Can Not Detect FTDI Devices.");
            }
        }
コード例 #10
0
        public bool Connect()
        {
            FT_STATUS status;
            bool      result;
            uint      numberOfDevices = 0;

            ftdi.GetNumberOfDevices(ref numberOfDevices);

            if (numberOfDevices == 0)
            {
                result = false;
            }
            else if ((status = ftdi.OpenByIndex(0)) != FT_STATUS.FT_OK)
            {
                result = false;
            }
            else if ((status = ftdi.SetBaudRate(250000)) != FT_STATUS.FT_OK)
            {
                result = false;
            }
            else if ((status = ftdi.SetDataCharacteristics(FT_DATA_BITS.FT_BITS_8, FT_STOP_BITS.FT_STOP_BITS_2, FT_PARITY.FT_PARITY_NONE)) != FT_STATUS.FT_OK)
            {
                result = false;
            }
            else
            {
                status      = ftdi.Purge(FT_PURGE.FT_PURGE_TX | FT_PURGE.FT_PURGE_RX);
                IsConnected = true;
                result      = true;
            }

            return(result);
        }
コード例 #11
0
    private uint getFTDIdevicesWindows()
    {
        //based on: http://www.ftdichip.com/Support/SoftwareExamples/CodeExamples/CSharp/EEPROM.zip

        //UInt32 ftdiDeviceCount = 0;
        uint ftdiDeviceCount = 0;

        FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;

        // Determine the number of FTDI devices connected to the machine
        ftStatus = ftdiDeviceWin.GetNumberOfDevices(ref ftdiDeviceCount);
        // Check status
        if (ftStatus != FTDI.FT_STATUS.FT_OK)
        {
            LogB.Error("FTDI GetNumberOfDevices failed");
            return(0);
        }
        if (ftdiDeviceCount == 0)
        {
            LogB.Information("FTDI GetNumberOfDevices 0");
            return(0);
        }

        return(ftdiDeviceCount);
    }
コード例 #12
0
 public Class1()
 {
     device.GetNumberOfDevices(ref _ftdiDeviceCount);
     if (FtdiDeviceCount != 0)
     {
         ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[FtdiDeviceCount];
     }
 }
コード例 #13
0
        public void readRom()
        {
            keyProMap.Clear();
            content.Clear();
            UInt32 ftdiDeviceCount = 0;

            FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;

            // Create new instance of the FTDI device class
            FTDI myFtdiDevice = new FTDI();

            // Determine the number of FTDI devices connected to the machine
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                content.Append("Number of FTDI devices: " + ftdiDeviceCount.ToString() + "\n");
            }
            else
            {
                content.Append("Failed to get number of devices (error " + ftStatus.ToString() + ")" + "\n");
                return;
            }

            // If no devices available, return
            if (ftdiDeviceCount == 0)
            {
                // Wait for a key press
                content.Append("Failed to get number of devices (error " + ftStatus.ToString() + ")" + "\n");
                return;
            }

            // Allocate storage for device info list
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
            int numDevices = 0, ChipID = 0;

            FTChipID.ChipID.GetNumDevices(ref numDevices);
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (int i = 0; i < ftdiDeviceCount; i++)
                {
                    FTChipID.ChipID.GetDeviceChipID(i, ref ChipID);

                    keyProMap.Add("0x" + ChipID.ToString("X"), ftdiDeviceList[i]);
                    content.Append("Device Index: " + i.ToString() + "\n");
                    content.Append("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags) + "\n");
                    content.Append("Type: " + ftdiDeviceList[i].Type.ToString() + "\n");
                    content.Append("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID) + "\n");
                    content.Append("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId) + "\n");
                    content.Append("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString() + "\n");
                    content.Append("Description: " + ftdiDeviceList[i].Description.ToString() + "\n");
                    content.Append("\n");
                }
            }
        }
コード例 #14
0
        private void FT232_Init()
        {
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                MessageBox.Show("Failed to get number of devices (error " + ftStatus.ToString() + ")");
            }
            if (ftdiDeviceCount == 0)
            {
                MessageBox.Show("无可用的FTDI设备 (error " + ftStatus.ToString() + ")");
            }
            // Allocate storage for device info list
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                label1.Text = "Type:" + ftdiDeviceList[0].Type.ToString();
                label2.Text = "Location ID: " + String.Format("{0:x}", ftdiDeviceList[0].LocId);
                label3.Text = "Serial Number: " + ftdiDeviceList[0].SerialNumber.ToString();
                label4.Text = "Description: " + ftdiDeviceList[0].Description.ToString();
            }
            ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
            OpenFlag = ftStatus;
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                MessageBox.Show("打开设备失败 (error " + ftStatus.ToString() + ")");
            }
            ftStatus = myFtdiDevice.SetBaudRate(921600);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                MessageBox.Show("波特率设置失败 (error " + ftStatus.ToString() + ")");
            }
            ftStatus = myFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                MessageBox.Show("数据特征设置失败 (error " + ftStatus.ToString() + ")");
            }
            ftStatus = myFtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0x11, 0x13);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                MessageBox.Show("流控制设置失败 (error " + ftStatus.ToString() + ")");
            }
            ftStatus = myFtdiDevice.SetTimeouts(5000, 0);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                MessageBox.Show("超时时间设置失败 (error " + ftStatus.ToString() + ")");
            }
            uint dwEventMask = FTDI.FT_EVENTS.FT_EVENT_RXCHAR;

            ftStatus = myFtdiDevice.SetEventNotification(dwEventMask, eventWait);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                MessageBox.Show("事件响应器设置失败 (error " + ftStatus.ToString() + ")");
            }
        }
コード例 #15
0
        public SetupDialogForm()
        {
            InitializeComponent();

            UInt32 ftdiDeviceCount = 0;

            FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
            // Create new instance of the FTDI device class
            FTDI tempFtdiDevice = new FTDI();

            // Determine the number of FTDI devices connected to the machine
            ftStatus = tempFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                AvailableDevicesListBox.Items.Add("# of FTDI devices = " + ftdiDeviceCount.ToString());
            }
            else
            {
                throw new ASCOM.InvalidValueException("Error getting count FTDI devices");
            }
            if (ftdiDeviceCount > 0)
            {
                // Allocate storage for device info list
                FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
                // Populate our device list
                ftStatus = tempFtdiDevice.GetDeviceList(ftdiDeviceList);
                //Show device properties
                if (ftStatus == FTDI.FT_STATUS.FT_OK)
                {
                    for (UInt32 i = 0; i < ftdiDeviceCount; i++)
                    {
                        if (ftdiDeviceList[i].SerialNumber.Contains("CAM86"))
                        {
                            AvailableDevicesListBox.Items.Add("Device Index: " + i.ToString());
                            AvailableDevicesListBox.Items.Add("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
                            AvailableDevicesListBox.Items.Add("Type: " + ftdiDeviceList[i].Type.ToString());
                            AvailableDevicesListBox.Items.Add("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
                            AvailableDevicesListBox.Items.Add("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
                            AvailableDevicesListBox.Items.Add("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
                            AvailableDevicesListBox.Items.Add("Description: " + ftdiDeviceList[i].Description.ToString());
                            AvailableDevicesListBox.Items.Add("");
                        }
                    }
                }
                else
                {
                    throw new ASCOM.InvalidValueException("Error getting parameters from FTDI devices");
                }
            }
            //Close device
            ftStatus = tempFtdiDevice.Close();

            // Initialise current values of user settings from the ASCOM Profile
            chkTrace.Checked = Camera.traceState;
        }
コード例 #16
0
ファイル: FTDIInterface.cs プロジェクト: GataullinRR/EX1
        FT_DEVICE_INFO_NODE[] getAllDevices()
        {
            uint numOfDevices = 0;
            var  status       = _ftdi.GetNumberOfDevices(ref numOfDevices);
            var  devices      = new FT_DEVICE_INFO_NODE[numOfDevices];

            status = status == FT_STATUS.FT_OK ? _ftdi.GetDeviceList(devices) : status;

            return(status == FT_STATUS.FT_OK ? devices : new FT_DEVICE_INFO_NODE[0]);
        }
コード例 #17
0
        public IEnumerable <string> GetAvailableSerialNumbers()
        {
            UInt32 deviceCount = 0;

            FTDI.FT_STATUS status = _ftdi.GetNumberOfDevices(ref deviceCount);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception("Unable to get the number of FTDI devices.");
            }

            FTDI.FT_DEVICE_INFO_NODE[] list = new FTDI.FT_DEVICE_INFO_NODE[deviceCount];
            status = _ftdi.GetDeviceList(list);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception("Unable to obtain the device list.");
            }

            return(list.Select(x => x.SerialNumber));
        }
コード例 #18
0
        public static List <FDTIPort> FindFdtiUsbDevices()
        {
            ///////////////////////
            // Requires
            // FTD2XX_NET.dll
            ///////////////////////

            List <FDTIPort> ports = new List <FDTIPort>();

            FTDI _ftdi = new FTDI();


            UInt32 count = 0;

            FTDI.FT_STATUS status = _ftdi.GetNumberOfDevices(ref count);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("log.Warn: Unable to access FTDI");
                return(ports);
            }

            FTDI.FT_DEVICE_INFO_NODE[] list = new FTDI.FT_DEVICE_INFO_NODE[count];
            status = _ftdi.GetDeviceList(list);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("log.Warn: Unable to access FTDI");
                return(ports);
            }


            foreach (FTDI.FT_DEVICE_INFO_NODE node in list)
            {
                if ((status = _ftdi.OpenByLocation(node.LocId)) == FTDI.FT_STATUS.FT_OK)
                {
                    try
                    {
                        string comport;
                        _ftdi.GetCOMPort(out comport);

                        if (comport != null && comport.Length > 0)
                        {
                            //Console.WriteLine(node.Type);
                            ports.Add(new FDTIPort(comport, node.Description.ToString(), node.SerialNumber.ToString()));
                        }
                    }
                    finally
                    {
                        _ftdi.Close();
                    }
                }
            }

            //_ftdi.Dispose();
            return(ports);
        }
コード例 #19
0
 public void OpenDevice()
 {
     ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
     FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
     ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
     ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber.ToString());
     ftStatus = myFtdiDevice.SetLatency(2);    // SetLatencyTimer(2);
     ftStatus = myFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE);
     ftStatus = myFtdiDevice.SetTimeouts(10, 0);
 }
コード例 #20
0
        /// <summary>
        /// Return the device count
        /// </summary>
        /// <returns>Number of devices</returns>
        private int GetDeviceCount()
        {
            uint count = 0;

            _status = _device.GetNumberOfDevices(ref count);
            if (_status != FTDI.FT_STATUS.FT_OK)
            {
                throw new UsbRelayStatusException();
            }

            return((int)count);
        }
コード例 #21
0
        public FtdiCommunicationTests(ITestOutputHelper output)
        {
            this.output = output;
            var ftdi        = new FTDI();
            var deviceCount = 0u;

            ftdi.GetNumberOfDevices(ref deviceCount);
            var deviceArray = new FTDI.FT_DEVICE_INFO_NODE[deviceCount];

            ftdi.GetDeviceList(deviceArray);
            box = AmpsBoxFactory.CreateAmpsBox(deviceArray[0].SerialNumber);
        }
コード例 #22
0
        // Determine the number of FTDI devices connected to the machine
        private static uint GetNumberOfDevices(FTDI ftdi)
        {
            uint ftdiDeviceCount = 0;
            var  ftStatus        = ftdi.GetNumberOfDevices(ref ftdiDeviceCount);

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                return(ftdiDeviceCount);
            }

            var errMsg = "Failed to get number of devices (error " + ftStatus + ")";

            throw new FtdiException(errMsg);
        }
コード例 #23
0
        // Determine the number of FTDI devices connected to the machine
        private static UInt32 GetNumberOfDevices(FTDI ftdi)
        {
            UInt32 ftdiDeviceCount = 0;

            FTDI.FT_STATUS ftStatus = ftdi.GetNumberOfDevices(ref ftdiDeviceCount);
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                return(ftdiDeviceCount);
            }

            String errMsg = "Failed to get number of devices (error " + ftStatus.ToString() + ")";

            throw new FtdiException(errMsg);
        }
コード例 #24
0
        /// <summary>
        /// Find the FDTI chip, connect, set baud to 9600, set sync bit-bang mode
        /// </summary>
        /// <returns></returns>
        public bool connect()
        {
            // Determine the number of FTDI devices connected to the machine
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Number of FTDI devices: " + ftdiDeviceCount.ToString());
                Console.WriteLine("");
            }
            else
            {
                Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
                return(false);
            }

            if (ftdiDeviceCount == 0)
            {
                Console.WriteLine("Relay board not found, please try again");
                return(false);
            }
            else
            {
                // Allocate storage for device info list
                FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

                // Populate our device list
                ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);

                // Open first device in our list by serial number
                ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);

                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    Console.WriteLine("Error connecting to relay board");
                    return(false);
                }

                // Set Baud rate to 9600
                ftStatus = myFtdiDevice.SetBaudRate(9600);

                // Set FT245RL to synchronous bit-bang mode, used on sainsmart relay board
                myFtdiDevice.SetBitMode(0xFF, FTD2XX_NET.FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG);
                // Switch off all the relays
                myFtdiDevice.Write(startup, 1, ref bytesToSend);

                return(true);
            }
        }
コード例 #25
0
        void RefreshDevice()
        {
            FTDI_combo.Items.Clear();
            FTDISerialNumber = null;
            UInt32 ftdiDeviceCount = 0;

            FTDI.FT_STATUS ftStatus     = FTDI.FT_STATUS.FT_OK;
            FTDI           myFtdiDevice = new FTDI();

            // Determine the number of FTDI devices connected to the machine
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
            }
            else
            {
                // Wait for a key press
                MessageBox.Show("error :" + ftStatus.ToString());
                return;
            }
            if (ftdiDeviceCount == 0)
            {
                // Wait for a key press
                return;
            }
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                FTDISerialNumber = new string[ftdiDeviceCount];
                comboBox1.Items.Clear();
                for (UInt32 i = 0; i < ftdiDeviceCount; i++)
                {
                    FTDI_combo.Items.Add(ftdiDeviceList[i].Description.ToString());
                    FTDISerialNumber[i] = ftdiDeviceList[i].SerialNumber.ToString();
                    comboBox1.Items.Add(FTDISerialNumber[i]);
                }
            }
            else
            {
                MessageBox.Show("error :" + ftStatus.ToString());
                return;
            }
            FTDI_combo.SelectedIndex = 0;
        }
コード例 #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            // Determine the number of FTDI devices connected to the machine
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                textBox1.Text += "Number of FTDI devices: " + ftdiDeviceCount.ToString() + "\r\n";
            }
            else
            {
                // Wait for a key press
                textBox1.Text += "Failed to get number of devices (error " + ftStatus.ToString() + ")\r\n";
                return;
            }

            // If no devices available, return
            if (ftdiDeviceCount == 0)
            {
                // Wait for a key press
                textBox1.Text += "Failed to get number of devices (error " + ftStatus.ToString() + ")\r\n";
                return;
            }

            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (UInt32 i = 0; i < ftdiDeviceCount; i++)
                {
                    string tempDescription = ftdiDeviceList[i].Description.ToString();
                    string tempSerial      = ftdiDeviceList[i].SerialNumber.ToString();
                    if (tempDescription.Contains(textBox4.Text) && tempSerial.Contains(textBox3.Text))
                    {
                        deviceIndex    = (int)i;
                        textBox1.Text += "Device Index: " + i.ToString() + "\r\n";
                        textBox1.Text += "Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags) + "\r\n";
                        textBox1.Text += "Type: " + ftdiDeviceList[i].Type.ToString() + "\r\n";
                        textBox1.Text += "ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID) + "\r\n";
                        textBox1.Text += "Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId) + "\r\n";
                        textBox1.Text += "Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString() + "\r\n";
                        textBox1.Text += "Description: " + ftdiDeviceList[i].Description.ToString() + "\r\n\r\n";
                    }
                }
            }
        }
コード例 #27
0
ファイル: Reader.cs プロジェクト: JiMin-Temprecord/Templite
        public FTDIInfo FindFTDI()
        {
            var ft = new FTDI();

            uint deviceCount = 0;
            uint deviceID    = 0;

            var stat = ft.GetNumberOfDevices(ref deviceCount);

            FTDI.FT_DEVICE_INFO_NODE[] devices = new FTDI.FT_DEVICE_INFO_NODE[deviceCount];
            stat = ft.GetDeviceList(devices);

            foreach (var dev in devices)
            {
                try
                {
                    stat = ft.OpenByLocation(dev.LocId);
                    if (stat == FTDI.FT_STATUS.FT_OK)
                    {
                        ft.GetDeviceID(ref deviceID);
                        if (deviceID != 67330049)
                        {
                            ft.GetCOMPort(out var portName);
                            ft.Close();
                            return(new FTDIInfo(portName, deviceID));
                        }
                    }
                }
                catch
                {
                    try
                    {
                        if (ft.IsOpen)
                        {
                            ft.Close();
                        }
                    }
                    finally
                    {
                        if (ft.IsOpen)
                        {
                            ft.Close();
                        }
                    }
                }
            }
            return(null);
        }
コード例 #28
0
        public mainForm()
        {
            InitializeComponent();
            label1.Text = "Searching for Devices...";


            EasyTimer.SetInterval(() =>
            {
                // start FTDI communication
                UInt32 ftdiDeviceCount  = 0;
                FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;

                // Create new instance of the FTDI device class
                FTDI myFtdiDevice = new FTDI();

                // Determine the number of FTDI devices connected to the machine
                ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);

                if (ftStatus == FTDI.FT_STATUS.FT_OK)
                {
                    label1.Text = "Number of FTDI devices: " + ftdiDeviceCount.ToString();
                }
                else
                {
                    // Wait for a key press
                    label1.Text = "Failed to get number of devices (error: " + ftStatus.ToString() + ")";
                    return;
                }

                // If no devices available, return
                if (ftdiDeviceCount == 0)
                {
                    label1.Text = "No Devices Found (error " + ftStatus.ToString() + ")";
                    return;
                }
                else
                {
                    label1.Text = "Got Devices! (Mssg: " + ftStatus.ToString() + ")";
                }

                // Allocate storage for device info list
                FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

                // --- You code here ---
                // This piece of code will once after 1000 ms delay
            }, 1000);
        }
コード例 #29
0
        /// <summary>
        /// Find the FDTI chip, connect, set baud to 9600, set sync bit-bang mode
        /// </summary>
        /// <returns></returns>
        public static void Initialize(bool force = false)
        {
            if (initialized && !force)
            {
                return;
            }

            // Determine the number of FTDI devices connected to the machine
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Number of FTDI devices: " + ftdiDeviceCount);
            }
            else
            {
                throw new RelayBoardException("Failed to get number of devices (error " + ftStatus + ")");
            }

            if (ftdiDeviceCount == 0)
            {
                throw new RelayBoardException("Relay board not found, try:\r\nchecking connections\r\nusing without a USB hub\r\nusing a powered USB hub");
            }

            // Allocate storage for device info list
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);

            // Open first device in our list by serial number
            ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);

            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                throw new RelayBoardException("The relay board is reporting an error: " + Enum.GetName(typeof(FTDI.FT_STATUS), ftStatus));
            }

            // Set Baud rate to 9600
            ftStatus = myFtdiDevice.SetBaudRate(9600);

            // Set FT245RL to synchronous bit-bang mode, used on sainsmart relay board
            myFtdiDevice.SetBitMode(0xFF, FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG);
            // Switch off all the relays
            myFtdiDevice.Write(startup, bytesToSend, ref bytesToSend);
            initialized = true;
        }
コード例 #30
0
ファイル: FT232.cs プロジェクト: sclurb/DataCollection
        }/// <summary>

        /// This method finds the FTDI device opens the device, writes all the pertinanlt information
        /// in a string[], closes the connection so that it may be opened in a MS SerialPort instance
        /// and returns that string array to the caller.
        /// </summary>
        /// <returns></returns>
        public string[] InitFTDI()
        {
            //FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;     // static
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);  //instance, method changes uint by reference
            if (ftdiDeviceCount > 0)
            {
                FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
                // Populate our device list
                ftStatus      = myFtdiDevice.GetDeviceList(ftdiDeviceList);
                deviceList[0] = ftdiDeviceList[0].Type.ToString();
                deviceList[1] = ftdiDeviceList[0].ID.ToString();
                deviceList[2] = ftdiDeviceList[0].LocId.ToString();
                deviceList[3] = ftdiDeviceList[0].SerialNumber.ToString();
                deviceList[4] = ftdiDeviceList[0].Description.ToString();
                ftStatus      = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
                string COMnumber;
                ftStatus = myFtdiDevice.GetCOMPort(out (COMnumber));    // passes result by reference
                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    deviceList[5] = "No Com Port";
                }
                else
                {
                    deviceList[5] = COMnumber;
                }
                ftStatus = myFtdiDevice.SetBaudRate(9600);
                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    deviceList[6] = "BaudRate not Set";
                }
                else
                {
                    deviceList[6] = "9600";
                }
            }
            ftStatus = myFtdiDevice.Close();
            if (deviceList[5] != null)
            {
                PortSetUp();
            }
            if (deviceList[5] == null)
            {
                MessageBox.Show("FTDI Chip not Found.   Have you connected the USB from the computer to the Temperature Board?");
            }
            return(deviceList);
        }