Exemple #1
0
 /// <summary>
 /// open the FTDI device, sweep frequency forever
 /// </summary>
 public static void FrequencySweep(uint ftdiDevice = 0)
 {
     ft_status = ftdi.OpenByIndex(ftdiDevice);
     ft_status = ftdi.SetBaudRate(9600);
     ft_status = ftdi.SetBitMode(255, 1);
     while (true)
     {
         for (int i = 1; i <= 500; i++)
         {
             FrequencySet(i * 1_000_00);
             System.Threading.Thread.Sleep(10);
         }
     }
 }
        //------------------------------------------------ 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);
        }
Exemple #3
0
        /// <summary>
        /// Open the FTDI device
        /// </summary>
        /// <param name="index"></param>
        public void Open(uint index)
        {
            if (_ftdi.IsOpen)
            {
                //_ftdi.Close();
                throw new Exception(string.Format("Device at index {0} already opened", index));
            }

            FTDI.FT_STATUS status = _ftdi.OpenByIndex(index);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception(string.Format("Problem opening FTDI device at index {0}", index));
            }

            // Reset pins
            status = _ftdi.SetBitMode(0xFF, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception(string.Format("Unable to set bit mode reset to device at index {0}", index));
            }
            status = _ftdi.SetBitMode(0xFF, FTDI.FT_BIT_MODES.FT_BIT_MODE_MPSSE);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception(string.Format("Unable to set bit mode MPSEE to device at index {0}", index));
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            FTDI ftdi = new FTDI();

            FTDI.FT_DEVICE_INFO_NODE[] devicelist = new FTDI.FT_DEVICE_INFO_NODE[2];
            FTDI.FT_STATUS             ftStatus   = ftdi.GetDeviceList(devicelist);
            Debug.Assert(ftStatus == FTDI.FT_STATUS.FT_OK);
            ftStatus = ftdi.OpenByIndex(1);
            Debug.Assert(ftStatus == FTDI.FT_STATUS.FT_OK);
            if (ftdi.IsOpen)
            {
                FTDI.FT_DEVICE type = FTDI.FT_DEVICE.FT_DEVICE_UNKNOWN;
                ftStatus = ftdi.GetDeviceType(ref type);
                Debug.Assert(ftStatus == FTDI.FT_STATUS.FT_OK);
                Debug.Assert(type == FTDI.FT_DEVICE.FT_DEVICE_2232H);
                //ftdi.
                FTD2XX_NET.FTDI.FT2232H_EEPROM_STRUCTURE ee2232h = new FTDI.FT2232H_EEPROM_STRUCTURE();
                ftStatus = ftdi.ReadFT2232HEEPROM(ee2232h);
                Debug.Assert(ftStatus == FTDI.FT_STATUS.FT_OK);
            }
            else
            {
                throw new Exception();
            }
            ftStatus = ftdi.Close();
            Debug.Assert(ftStatus == FTDI.FT_STATUS.FT_OK);
        }
Exemple #5
0
 private void initialiseBoard_Click(object sender, EventArgs e)
 {
     ftStatus     = myFtdiDevice.OpenByIndex(0);
     ftStatus     = myFtdiDevice.SetBaudRate(921600);
     ftStatus     = myFtdiDevice.SetBitMode(255, 4);
     sentBytes[0] = 0;
 }
Exemple #6
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);
        }
        public static List <byte> data = new List <byte>(); // bytes to send


        static void Main(string[] args)
        {
            ftdi.OpenByIndex(0);
            ftdi.SetBitMode(0, 0);
            byte mask = PIN_CLK | PIN_CS | PIN_DATA; // output pins

            ftdi.SetBitMode(mask, 0x01);             // Asynchronous Bit Bang Mode
            ftdi.SetBaudRate(3_000_000 / 16);
            //ftdi.SetBaudRate(300);

            DisplayClear();
            SendCommand(0x0C, 0x01); // shutdown mode: normal operation
            SendCommand(0x09, 0xff); // decode mode: BCD for all digits
            SendCommand(0x0A, 0x0f); // intensity: brightest (last byte)
            SendCommand(0x0B, 0x07); // scan limit (number of rows in matrix)

            DisplayClear();

            System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();

            System.Console.WriteLine("displaying time...");
            while (true)
            {
                double timeMS = stopwatch.ElapsedTicks * 1000.0 / System.Diagnostics.Stopwatch.Frequency;
                System.Console.WriteLine(string.Format("{0:0.000}", timeMS / 100));
                DisplayNumber((long)timeMS, -3);
            }

            //ftdi.Close();
            //System.Console.WriteLine("DONE");
        }
Exemple #8
0
        public static byte pin_enable = 0b00001000; // CTS (active low)

        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBaudRate(9600);
            ft_status = ftdi.SetBitMode(255, 1); // all output, bit-bang

            int count      = 0;
            int freqTarget = 12_345_678; // Hz

            while (true)
            {
                List <byte> bytesToSend = new List <byte>();

                freqTarget += 1;
                ulong freqCode    = (ulong)(freqTarget) * (ulong)4_294_967_296;
                ulong freqCrystal = 125_000_000;
                freqCode = freqCode / freqCrystal;

                // load the target frequency
                bytesToSend.Add(ReverseBits((byte)((freqCode >> 00) & 0xFF))); // 1 LSB
                bytesToSend.Add(ReverseBits((byte)((freqCode >> 08) & 0xFF))); // 2
                bytesToSend.Add(ReverseBits((byte)((freqCode >> 16) & 0xFF))); // 3
                bytesToSend.Add(ReverseBits((byte)((freqCode >> 24) & 0xFF))); // 4 MSB
                bytesToSend.Add(0);

                BitBangBytes(bytesToSend.ToArray());
                System.Console.WriteLine($"{count++} {ft_status} {freqTarget}");
                System.Threading.Thread.Sleep(20);
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBaudRate(9600);
            string data = "a";

            ft_status = ftdi.Write(data, data.Length, ref bytesWritten);
        }
Exemple #10
0
        //relay1,2ともに動作させるための初期値
        internal void ftdiRelayInit(System.Windows.Forms.ComboBox ftdiDeviceList)
        {
            byte mask = 0;

            mask |= 0x14;

            m_ftdiDevice.OpenByIndex((uint)m_ftdiDeviceMap[ftdiDeviceList.SelectedIndex]);
            m_ftdiDevice.SetBitMode(mask, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG);
        }
Exemple #11
0
        public Relay()
        {
            try
            {
                ftdi.SetBaudRate(9600);
                ftdi.GetNumberOfDevices(ref devcount);
                if (devcount == 0)
                {
                    errMsg = "No devices found";
                    return;
                }
                FT_DEVICE_INFO_NODE[] nodes  = new FT_DEVICE_INFO_NODE[devcount];
                FT_STATUS             status = ftdi.GetDeviceList(nodes);
                uint index   = 0;
                uint nRelays = 0;
                foreach (FT_DEVICE_INFO_NODE node in nodes)
                {
                    string description = node.Type.ToString();
                    //string description = "";
                    if (description.Contains("_245R") || description.Contains("_232R"))
                    //if (true)
                    {
                        nRelays++;
                        ftdi.OpenByIndex(index);
                        //Nothing unique in the EEPROM to show 4 or 8 channel
                        //FT232R_EEPROM_STRUCTURE ee232r = new FT232R_EEPROM_STRUCTURE();
                        //ftdi.ReadFT232REEPROM(ee232r);
                        ftdi.GetCOMPort(out string comport);
                        //Close();
                        comList.Add(description);
                        comIndex.Add(index);
                        serialNums.Add(node.SerialNumber);
                    }
                    ++index;
                }
                devcount = nRelays;
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                errMsg = ex.Message;
            }
        }
Exemple #12
0
        public RelayBoard()
        {
            //Get serial number of device with index 0
            ftStatus = myFtdiDevice.OpenByIndex(0);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }
            //Reset device
            ftStatus = myFtdiDevice.ResetDevice();
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }
            //Set Baud Rate
            ftStatus = myFtdiDevice.SetBaudRate(921600);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }
            //Set Bit Bang
            ftStatus = myFtdiDevice.SetBitMode(255, FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }


            for (int i = 0; i <= 8; i++)
            {
                DisableRelay(i);
            }


            //int x = 1;
            //while (true)
            //{

            //    while(x <= 8)
            //    {
            //        EnableRelay(x);
            //        x++;
            //    }
            //    x = 1;
            //    Thread.Sleep(250);

            //    while (x <= 8)
            //    {
            //    DisableRelay(x);
            //        x++;
            //    }

            //    x = 1;
            //    Thread.Sleep(250);
            //}
        }
Exemple #13
0
 static void OpenDevice()
 {
     FTDI.FT_STATUS status = FTDI.FT_STATUS.FT_OK;
     _device = new FTDI();
     status  = _device.OpenByIndex(0);
     if (status != FTDI.FT_STATUS.FT_OK)
     {
         throw new Exception("Couldn't open device.");
     }
 }
Exemple #14
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);
 }
        /// <summary>
        /// Открыть соединение с устройством.
        /// </summary>
        public void Open()
        {
            _device.OpenByIndex(DeviceIndex);
            IsDeviceOpen = _device.IsOpen;
            _device.GetDescription(out _description);
            _device.SetTimeouts(100, 100);
#if DEBUG
            Console.WriteLine($"Device[{DeviceIndex}] Open: {_device.IsOpen}");
#endif
        }
Exemple #16
0
        private void open_connection(uint index)
        {
            ftdi.OpenByIndex(index);
            //ftdi.SetBaudRate(460800);
            //ftdi.SetBaudRate(3000000);

            //FTDI.FT_STATUS ftStatus = ftdi.SetBitMode(0xFF, 0x40); //Sync FIFO mode // disconnects vivado!

            exchanger = new Thread(exchange_process);
            exchanger.Start();
        }
Exemple #17
0
        public virtual bool OpenDevice()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(ftdi.OpenByIndex(0) == FTDI.FT_STATUS.FT_OK);
            }

            var deviceList      = GetDevicesList();
            var dmxUsbProDevice = deviceList.FirstOrDefault(d => d.Description != null && d.Description.Equals("DMX USB PRO"));

            return(ftdi.OpenByLocation(dmxUsbProDevice.LocId) == FTDI.FT_STATUS.FT_OK);
        }
Exemple #18
0
 public Relay()
 {
     try
     {
         ftdi.SetBaudRate(9600);
         ftdi.GetNumberOfDevices(ref devcount);
         if (devcount == 0)
         {
             errMsg = "No devices found";
             return;
         }
         FT_DEVICE_INFO_NODE[] nodes  = new FT_DEVICE_INFO_NODE[devcount];
         FT_STATUS             status = ftdi.GetDeviceList(nodes);
         uint index   = 0;
         uint nRelays = 0;
         foreach (FT_DEVICE_INFO_NODE node in nodes)
         {
             if (node.Description.Contains("FT245R"))
             {
                 nRelays++;
                 ftdi.OpenByIndex(index);
                 //Nothing unique in the EEPROM to show 4 or 8 channel
                 //FT232R_EEPROM_STRUCTURE ee232r = new FT232R_EEPROM_STRUCTURE();
                 //ftdi.ReadFT232REEPROM(ee232r);
                 ftdi.GetCOMPort(out string comport);
                 //Close();
                 comList.Add(comport);
                 comIndex.Add(index);
                 serialNums.Add(node.SerialNumber);
             }
             ++index;
         }
         devcount = nRelays;
     }
     catch (Exception ex)
     {
         errMsg = ex.Message;
     }
 }
Exemple #19
0
        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBitMode(255, 1);
            ft_status = ftdi.SetBaudRate(9600);

            while (true)
            {
                byte[] data = { 0b00000001, 0b00000010, 0b00000001, 0b00000010, 0b00000000 };
                ft_status = ftdi.Write(data, data.Length, ref bytesWritten);
                Console.WriteLine($"FT_STATUS: {ft_status}");
                System.Threading.Thread.Sleep(100);
            }
        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBitMode(255, 1);
            ft_status = ftdi.SetBaudRate(9600);
            int count = 0;

            while (true)
            {
                byte[] data = { (byte)(count++ % 2) };
                ft_status = ftdi.Write(data, data.Length, ref bytesWritten);
                System.Threading.Thread.Sleep(100);
            }
        }
Exemple #21
0
        FTDI.FT_STATUS OpenRFIDDevice()
        {
            FTDI.FT_STATUS Status = FTDI.FT_STATUS.FT_OTHER_ERROR;

            Thread.Sleep(100);

            if (RFIDFtdiDevice.IsOpen)
            {
                Status = RFIDFtdiDevice.Close();
                if (Status != FTDI.FT_STATUS.FT_OK)
                {
                    return(Status);
                }
            }

            // One can modify the device descriptor to open by Description
            // Placed here for reference only
            //Status = RFIDFtdiDevice.OpenByDescription("FT232R USB UART RFID Reader");

            //Asume that we are the only FTDI device
            Status = RFIDFtdiDevice.OpenByIndex(0);
            if (Status != FTDI.FT_STATUS.FT_OK)
            {
                return(Status);
            }

            Status = RFIDFtdiDevice.SetBaudRate(2400);
            if (Status != FTDI.FT_STATUS.FT_OK)
            {
                return(Status);
            }

            Status = RFIDFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE);
            if (Status != FTDI.FT_STATUS.FT_OK)
            {
                return(Status);
            }

            Status = RFIDFtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0x0, 00);
            if (Status != FTDI.FT_STATUS.FT_OK)
            {
                return(Status);
            }

            // Enable RFID Device
            Status = RFIDFtdiDevice.SetDTR(true);

            return(Status);
        }
Exemple #22
0
        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBaudRate(9600);
            string data  = "hello, world";
            int    count = 0;

            while (true)
            {
                ft_status = ftdi.Write(data, data.Length, ref bytesWritten);
                System.Console.WriteLine($"{count++} FTDI STATUS: {ft_status}");
                System.Threading.Thread.Sleep(200);
            }
            //System.Console.ReadLine();
        }
        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBitMode(255, 1);
            ft_status = ftdi.SetBaudRate(9600);

            // RIN, DCD, DSR, DTR, CTS, RTS, RXD, TXD
            //                ^^^  ^^^       ^^^  ^^^
            byte[] data = { 0b00011011 };
            ft_status = ftdi.Write(data, data.Length, ref bytesWritten);

            Console.WriteLine($"FT_STATUS: {ft_status}");
            ft_status = ftdi.Close();
            Console.WriteLine("press ENTER to exit ...");
            Console.ReadLine();
        }
        public static byte pin_enable = 0b00001000; // CTS (active low)

        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBaudRate(9600);
            ft_status = ftdi.SetBitMode(255, 1); // all output, bit-bang

            int count = 0;

            while (true)
            {
                byte[] bytesToSend = { 222, 234, 246 };
                bytesToSend = Encoding.ASCII.GetBytes("Hello, World!");
                BitBangBytes(bytesToSend);
                System.Console.WriteLine($"{count++} {ft_status}");
                System.Threading.Thread.Sleep(100);
            }
        }
 public FtdiModule()
 {
     if (IsDriverInstalled())
     {
         _ftdi = new FTDI();
         if (_ftdi.OpenByIndex(0) != FTDI.FT_STATUS.FT_OK ||
             _ftdi.SetBaudRate(921600) != FTDI.FT_STATUS.FT_OK ||
             _ftdi.SetBitMode(255, 4) != FTDI.FT_STATUS.FT_OK)
         {
             _ftdi = null;
         }
         else
         {
             _ftdi.Write(new byte[1] {
                 0
             }, 1, ref _recievedBytes);
         }
     }
 }
Exemple #26
0
        static void Main(string[] args)
        {
            //Get serial number of device with index 0
            ftStatus = myFtdiDevice.OpenByIndex(0);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }
            //Reset device
            ftStatus = myFtdiDevice.ResetDevice();
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }
            //Set Baud Rate
            ftStatus = myFtdiDevice.SetBaudRate(921600);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }
            //Set Bit Bang
            ftStatus = myFtdiDevice.SetBitMode(255, FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return;
            }

            int x = 1;

            while (true)
            {
                EnableRelay(x);
                Thread.Sleep(250);
                DisableRelay(x);

                x++;
                if (x > 8)
                {
                    x = 1;
                }
            }
        }
Exemple #27
0
 private void SetFifoMode()
 {
     FTDI.FT_STATUS status;
     //status = ftHandle.OpenBySerialNumber(serialNumber);
     status = ftHandle.OpenByIndex(0);
     if (status != FTDI.FT_STATUS.FT_OK)
     {
         MessageBox.Show("Cannot open device");
         return;
     }
     ftHandle.SetBitMode(0xff, 0x00);
     System.Threading.Thread.Sleep(10);
     status = ftHandle.SetBitMode(0xff, 0x40);
     if (status != FTDI.FT_STATUS.FT_OK)
     {
         MessageBox.Show("Cannot set status");
         return;
     }
     ftHandle.SetLatency(16);
     ftHandle.InTransferSize(0x10000);
     ftHandle.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0, 0);
 }
Exemple #28
0
        public DenkoviRelays(uint deviceIndex)
        {
            this.myFtdiDevice = new FTDI();
            this.deviceIndex  = deviceIndex;

            relayState[0] = 0;

            var status = myFtdiDevice.OpenByIndex(deviceIndex); // TODO: Consider by serial number or something more... sticky

            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new ApplicationException($"Error opening device: {status.ToString()}");
            }

            status = myFtdiDevice.ResetDevice();
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new ApplicationException($"Error resetting device: {status.ToString()}");
            }

            //Set Baud Rate
            status = myFtdiDevice.SetBaudRate(921600);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new ApplicationException($"Error configuring device baud rate: {status.ToString()}");
            }

            //Set Bit Bang
            status = myFtdiDevice.SetBitMode(255, FTD2XX_NET.FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                throw new ApplicationException($"Error configuring device bit bang: {status.ToString()}");
            }

            uint receivedBytes = 0;

            myFtdiDevice.Write(relayState, 1, ref receivedBytes);
        }
        //public static byte pin_select = 0b00000001;

        static void Main(string[] args)
        {
            ft_status = ftdi.OpenByIndex(0);
            ft_status = ftdi.SetBaudRate(9600);
            ft_status = ftdi.SetBitMode(0b11111111, 1);

            // RIN, DCD, DSR, DTR, CTS, RTS, RXD, TXD
            List <byte> data = new List <byte>();

            for (int i = 0; i < 1000; i++)
            {
                data.Add((byte)(i % 4));
            }

            int count = 0;

            while (true)
            {
                ft_status = ftdi.Write(data.ToArray(), data.Count, ref bytesWritten);
                System.Console.WriteLine($"{count++} {ft_status}");
                System.Threading.Thread.Sleep(100);
            }
        }
Exemple #30
0
        public void open()
        {
            FTDI.FT_STATUS st;

            /*
             * uint devcount = 0;
             * ftdi.GetNumberOfDevices(ref devcount);
             * if (devcount == 0)
             * {
             *  throw new SystemException("Device not found");
             * }
             */
            st = ftdi.OpenByIndex(index);
            if (st != FTDI.FT_STATUS.FT_OK)
            {
                throw new SystemException(string.Format("Failed to open device {0}. ({1})", index, st.ToString()));
            }

            ftdi.ResetDevice();
            ftdi.Purge(FTDI.FT_PURGE.FT_PURGE_RX | FTDI.FT_PURGE.FT_PURGE_TX);
            ftdi.SetTimeouts(ReadTimeoutMilliseconds, WriteTimeoutMilliseconds);
            ftdi.SetLatency(LatencyMilliseconds);
        }