Example #1
0
 public void Dispose()
 {
     if (_pinDmd1Device != null)
     {
         _ftdi.SetBitMode(0x00, 0x0);
         _ftdi.Close();
         _pinDmd1Device = null;
         IsAvailable    = false;
     }
 }
Example #2
0
 public void OpenDeviceByIndex(uint i)
 {
     ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
     FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
     ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
     ftStatus = myFtdiDevice.OpenByIndex(i);
     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);
 }
Example #3
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);
        }
Example #4
0
        public string GetDescription(UInt32 i)
        {//Get the Description of the specified device// Not tested
            // Check status
            string myDescription;

            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            ftStatus      = myFtdiDevice.GetDeviceList(ftdiDeviceList);
            myDescription = ftdiDeviceList[i].Description.ToString();
            return(myDescription);
        }
        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);
        }
Example #6
0
        private static FTDI.FT_DEVICE_INFO_NODE[] GetDeviceList(FTDI ftdi, UInt32 ftdiDeviceCount)
        {
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            FTDI.FT_STATUS             ftStatus       = ftdi.GetDeviceList(ftdiDeviceList);
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                return(ftdiDeviceList);
            }

            String errMsg = "Failed to get device list (error " + ftStatus.ToString() + ")";

            throw new FtdiException(errMsg);
        }
Example #7
0
        public FTDIDeviceInfo(FTDI.FT_DEVICE_INFO_NODE node, uint index, uint chipID)
        {
            Description  = node.Description;
            Flags        = node.Flags;
            ftHandle     = IntPtr.Zero;
            ID           = node.ID;
            LocId        = node.LocId;
            SerialNumber = node.SerialNumber;
            Type         = node.Type;

            Index  = index;
            ChipID = chipID;
        }
Example #8
0
        public static List <Device> GetDeviceList()
        {
            List <Device> devices         = new List <Device>();
            UInt32        ftdiDeviceCount = 0;
            // Create new instance of the FTDI device class
            FTDI tempFtdiDevice = new FTDI();

            Logging.Info("Interogating FTDI for devices.");
            // Determine the number of FTDI devices connected to the machine
            FTDI.FT_STATUS ftStatus = tempFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                Logging.Error($"An error occured getting FTDI devices. {ftStatus.ToString()}");
                return(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 (var i = 0; i < ftdiDeviceCount; i++)
                    {
                        Device d = new Device
                        {
                            Index        = i,
                            Type         = ftdiDeviceList[i].Type.ToString(),
                            Id           = ftdiDeviceList[i].ID.ToString(),
                            Description  = ftdiDeviceList[i].Description,
                            SerialNumber = ftdiDeviceList[i].SerialNumber
                        };
                        devices.Add(d);
                    }
                }
                else
                {
                    Logging.Error($"Error getting FTDI device list {ftStatus.ToString()}");
                }
            }

            //Close device
            ftStatus = tempFtdiDevice.Close();
            Logging.Info("Closing FTDI device interogation.");

            return(devices);
        }
Example #9
0
        public SetupDialogForm()
        {
            InitializeComponent();
            //Initialize components;

            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++)
                    {
                        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();
        }
Example #10
0
        private void RefreshDevices()
        {
            FTDIDevices.Clear();

            var newDevices = mFTDILibrary.EnumerateFTDIDevices();

            uint index = 0;

            foreach (var node in newDevices)
            {
                if (node.Type != FTDI.FT_DEVICE.FT_DEVICE_UNKNOWN)
                {
                    uint chipID = 0;
                    if (FTDI.IsFTDChipIDDLLLoaded())
                    {
                        mFTDILibrary.GetChipIDFromDeviceIndex(index, out chipID);
                    }

                    FTDIDevices.Add(new FTDIDeviceInfo(node, index, chipID));
                    index++;
                }
            }

            #region fakeDevices
#if ENABLE_FAKE_USB_DEVICES
            if ((FTDIDevices.Count == 0) && (DateTime.Now.Second % 3 == 0))
            {
                FTDI.FT_DEVICE_INFO_NODE tempInfo0 = new FTDI.FT_DEVICE_INFO_NODE();
                tempInfo0.Description  = "Debug Placeholder FTDI Device 0";
                tempInfo0.ID           = 1000;
                tempInfo0.SerialNumber = "SerialNum 1000";
                tempInfo0.Type         = FTDI.FT_DEVICE.FT_DEVICE_232R;
                FTDIDevices.Add(new FTDIDeviceInfo(tempInfo0, index++, 0x01010101));

                FTDI.FT_DEVICE_INFO_NODE tempInfo1 = new FTDI.FT_DEVICE_INFO_NODE();
                tempInfo1.Description  = "Debug Placeholder FTDI Device 1";
                tempInfo1.ID           = 1001;
                tempInfo1.SerialNumber = "SerialNum 1001";
                tempInfo1.Type         = FTDI.FT_DEVICE.FT_DEVICE_UNKNOWN;
                FTDIDevices.Add(new FTDIDeviceInfo(tempInfo1, index++, 0x00000000));

                FTDI.FT_DEVICE_INFO_NODE tempInfo2 = new FTDI.FT_DEVICE_INFO_NODE();
                tempInfo2.Description  = "Debug Placeholder FTDI Device 2";
                tempInfo2.ID           = 1002;
                tempInfo2.SerialNumber = "SerialNum 1002";
                tempInfo2.Type         = FTDI.FT_DEVICE.FT_DEVICE_BM;
                FTDIDevices.Add(new FTDIDeviceInfo(tempInfo2, index++, 0x01010101));
            }
#endif
            #endregion
        }
Example #11
0
        static void Main(string[] args)
        {
            byte[] currentTesterAddresses = new byte[] { 0x40, 0x41, 0x44, 0x45 };

            FTDI ftdi  = new FTDI();
            int  count = 10;

            FTDI.FT_DEVICE_INFO_NODE[] devlist = new FTDI.FT_DEVICE_INFO_NODE[count];
            FTDI.FT_STATUS             status  = ftdi.GetDeviceList(devlist);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception("Problem getting FTDI device list");
            }

            for (int i = 0; i < count; i++)
            {
                FTDI.FT_DEVICE_INFO_NODE devinfo = devlist[i];
                if (devinfo != null)
                {
                    if (devinfo.Type == FTDI.FT_DEVICE.FT_DEVICE_232H)
                    {
                        string msg = string.Format("{0}. {1}", i + 1, devinfo.Description);
                        Console.WriteLine(msg);

                        FTI2C currentController = new FTI2C();
                        currentController.Init(i);

                        Cina219 cina = new Cina219(currentController);
                        foreach (var currentTesterAddress in currentTesterAddresses)
                        {
                            var cina219 = new Cina219(currentController, currentTesterAddress);

                            try
                            {
                                cina219.Init();
                                Console.WriteLine(string.Format("0x{0:X} => Sensor found", currentTesterAddress));
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(string.Format("0x{0:X} => {1}", currentTesterAddress, ex.Message));
                                continue;
                            };
                        }
                        Console.WriteLine();
                    }
                }
            }

            Console.ReadLine();
        }
Example #12
0
        private static FTDI.FT_DEVICE_INFO_NODE[] GetDeviceList(FTDI ftdi, uint ftdiDeviceCount)
        {
            var ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            var ftStatus       = ftdi.GetDeviceList(ftdiDeviceList);

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

            var errMsg = "Failed to get device list (error " + ftStatus + ")";

            throw new FtdiException(errMsg);
        }
Example #13
0
        public virtual List <FTDI.FT_DEVICE_INFO_NODE> GetDevicesList()
        {
            var dList       = new FTDI.FT_DEVICE_INFO_NODE[10];
            var devicesList = new List <FTDI.FT_DEVICE_INFO_NODE>();
            var result      = ftdi.GetDeviceList(dList);

            if (result != FTDI.FT_STATUS.FT_OK)
            {
                return(devicesList);
            }

            devicesList.AddRange(dList.Where(device => device != null).AsEnumerable());
            return(devicesList);
        }
Example #14
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);
            }
        }
Example #15
0
        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);
        }
Example #16
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;
        }
Example #17
0
        private Dictionary <string, string> BuildProperties(FTDI.FT_DEVICE_INFO_NODE deviceNode)
        {
            var result = new Dictionary <string, string>();

            var allFlags = new[] { FTDI.FT_FLAGS.FT_FLAGS_OPENED, FTDI.FT_FLAGS.FT_FLAGS_OPENED };
            var flagText = String.Join(" | ", allFlags.Where(f => (deviceNode.Flags & f) == f).Select(f => f.ToString().Substring(9)));

            result.Add(FlagsProperty, flagText);
            result.Add(TypeProperty, deviceNode.Type.ToString());
            result.Add(IdProperty, String.Format("{0:x}", deviceNode.ID));
            result.Add(LocationIdProperty, String.Format("{0:x}", deviceNode.LocId));
            result.Add(SerialNumberProperty, deviceNode.SerialNumber);
            result.Add(DescriptionProperty, deviceNode.Description);

            return(result);
        }
Example #18
0
        private void refreshFTDIDevicesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            // Check status
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                // MessageBox.Show("Number of FTDI devices: " + ftdiDeviceCount.ToString());
                //  richTextBox1.AppendText("Number of FTDI devices: " + ftdiDeviceCount.ToString());
            }
            else
            {
                // Wait for a key press

                MessageBox.Show("Failed to get number of devices (error " + ftStatus.ToString() + ")");
            }

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

            // Allocate storage for device info list
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            NuberOFFTDIDevieces.Text = "number of FT Devices :" + ftdiDeviceCount + "";
            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                //for (UInt32 i = 0; i < ftdiDeviceCount; i++)
                //{
                //    // + Environment.NewLine
                //    richTextBox1.Text += ("Device Index: " + i.ToString());
                //    richTextBox1.Text += ("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
                //    richTextBox1.Text += ("Type: " + ftdiDeviceList[i].Type.ToString());
                //    richTextBox1.Text += ("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
                //    richTextBox1.Text += ("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
                //    richTextBox1.Text += ("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
                //    richTextBox1.Text += ("Description: " + ftdiDeviceList[i].Description.ToString());
                //    richTextBox1.Text += ("");
                //}
                //toolStripStatusLabel2.Text += "FT_OK";
                statusLed.Value = true;
            }
        }
        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);
        }
Example #20
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;
        }
Example #21
0
        }/// <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);
        }
Example #22
0
        public static int CountDevices()
        {
            FTDI.FT_DEVICE_INFO_NODE[] Devices = new FTDI.FT_DEVICE_INFO_NODE[5] {
                null, null, null, null, null
            };
            USBPort.GetDeviceList(Devices);
            int numDevices = 0;

            foreach (FTDI.FT_DEVICE_INFO_NODE Device in Devices)
            {
                if (Device != null)
                {
                    numDevices++;
                }
            }
            return(numDevices);
        }
Example #23
0
    private string getComPort(FTDI.FT_DEVICE_INFO_NODE node)
    {
        string comport = "";

        //http://stackoverflow.com/questions/2279646/finding-usb-serial-ports-from-a-net-application-under-windows-7
        if (ftdiDeviceWin.OpenByLocation(node.LocId) == FTDI.FT_STATUS.FT_OK)
        {
            try {
                ftdiDeviceWin.GetCOMPort(out comport);
            }
            finally {
                ftdiDeviceWin.Close();
            }
        }

        return(comport);
    }
Example #24
0
        private void button5_Click(object sender, EventArgs e)
        {
            UInt32 ftdiDeviceCount = 0;


            // Create new instance of the FTDI device class
            myFtdiDevice = new FTDI();
            myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            myFtdiDevice.GetDeviceList(ftdiDeviceList);
            myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
            myFtdiDevice.SetBaudRate(9600);
            myFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE);
            myFtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0x11, 0x13);
            myFtdiDevice.SetTimeouts(5000, 0);
            richTextBox1.AppendText("polaczono");
        }
Example #25
0
        private void GetDeviceThread()
        {
            while (_shouldBeRunning)
            {
                while (_shouldBeRunning && !_ftdi.IsOpen)
                {
                    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.");
                    }
                    else
                    {
                        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.");
                        }
                        else
                        {
                            FTDI.FT_DEVICE_INFO_NODE match = list.FirstOrDefault(x => x.SerialNumber == SerialNumber);
                            if (match != null)
                            {
                                status = _ftdi.OpenBySerialNumber(match.SerialNumber);
                                if (status != FTDI.FT_STATUS.FT_OK)
                                {
                                    throw new Exception("Unable to open the FTDI device!");
                                }

                                InitializeDMX();

                                if (OnDeviceConnected != null)
                                {
                                    OnDeviceConnected();
                                }
                            }
                        }
                    }

                    Thread.Sleep(TRY_TO_FIND_DEVICE_DELAY_IN_MILLISECONDS);
                }
            }
        }
Example #26
0
        public uint[] getListLocIdPlacas()
        {
            FTD2XX_NET.FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
            uint ftdiDeviceCount = 0;
            FTDI acesso          = new FTDI();

            acesso.GetNumberOfDevices(ref ftdiDeviceCount);
            FTDI.FT_DEVICE_INFO_NODE[] infos = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            acesso.GetDeviceList(infos);
            uint[] placas = new uint[ftdiDeviceCount];
            for (int c = 0; c < infos.Length; c++)
            {
                placas[c] = infos[c].LocId;
                executaComando(infos[c].LocId, Tipos.Inicia, Codigos.Inicia);
            }

            return(placas);
        }
Example #27
0
        public string GetDescription()
        {//Get the Description of the first device// Not tested
            // Check status
            string myDescription;

            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
            try
            {
                myDescription = ftdiDeviceList[0].Description.ToString();
            }
            catch
            {
                myDescription = "No device";
            }
            return(myDescription);
        }
Example #28
0
        public string GetSerialNum(UInt32 i)
        {//Get the SerialNum of the specified device// Not tested
            // Check status
            string mySerialNum;

            ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
            try
            {
                mySerialNum = ftdiDeviceList[i].SerialNumber.ToString();
            }
            catch
            {
                mySerialNum = "No Device";
            }
            return(mySerialNum);
        }
Example #29
0
        static void sendIqpList(TcpClient conn)
        {
            NetworkStream ns    = conn.GetStream();
            StreamWriter  nsOut = new StreamWriter(ns);

            nsOut.NewLine = "\n";
            nsOut.WriteLine("IQPs found:");
            Console.WriteLine("IQPs found:");

            FTDI masterDevice = new FTDI();

            FTDI.FT_STATUS ret;

            uint devCount = 0;

            masterDevice.GetNumberOfDevices(ref devCount);

            FTDI.FT_DEVICE_INFO_NODE[] devList = new FTDI.FT_DEVICE_INFO_NODE[devCount];
            masterDevice.GetDeviceList(devList);

            foreach (FTDI.FT_DEVICE_INFO_NODE info in devList)
            {
                string portName = "?";
                ret = masterDevice.OpenBySerialNumber(info.SerialNumber);
                if (ret != FTDI.FT_STATUS.FT_OK)
                {
                    portName = "!";
                }
                else
                {
                    masterDevice.GetCOMPort(out portName);
                    masterDevice.Close();
                }

                nsOut.WriteLine("{0},{1},{2},{3}", info.Description, info.Type.ToString(), info.SerialNumber, portName);
                Console.WriteLine("{0},{1},{2},{3}", info.Description, info.Type.ToString(), info.SerialNumber, portName);
            }
            nsOut.WriteLine("");
            Console.WriteLine("");

            nsOut.Flush();
            ns.Close();
            conn.Close();
        }
Example #30
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));
        }