Class wrapper for FTD2XX.DLL
コード例 #1
1
        /// <summary>
        /// Create a USB Relay Device and open it by the serial number
        /// </summary>
        /// <param name="serialNumber">Device serial number</param>
        public UsbRelay8( String serialNumber )
        {
            // Open the relay device by serial number
            //  The serial number is always uniques, so the safest
            _device = new FTDI();
            _status = _device.OpenBySerialNumber(serialNumber);
            if (_status != FTDI.FT_STATUS.FT_OK)
            {
                throw new UsbRelayDeviceNotFoundException();
            }

            // Set the baud rate
            _status = _device.SetBaudRate(BaudRate);
            if (_status != FTDI.FT_STATUS.FT_OK)
            {
                throw new UsbRelayConfigurationException();
            }

            // Set the bit mode
            _status = _device.SetBitMode(BitMask, BitMode);
            if (_status != FTDI.FT_STATUS.FT_OK)
            {
                throw new UsbRelayConfigurationException();
            }

            // Clear all the relays
            // Note: From the Data Sheet, when in Sync Mode you can
            //  only read the interface pins when writing.  So start
            //  start out with all the values cleared.
            _values = 0x00;
            SetRelays(_values);
        }
コード例 #2
1
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            FTD2XX_NET.FTDI dev = new FTDI();
            UInt32 numDevices = 0;
            dev.GetNumberOfDevices(ref numDevices);

            var pDest = new FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[numDevices];
            dev.GetDeviceList(pDest);

            VIDPIDList = string.Empty;
            for (int i = 0; i < numDevices; i++ )
            {
                VIDPIDList += string.Format("{0} \n", pDest[i].ID);
            }
        }
コード例 #3
1
        //-------------------------------------------------------------------------------------------------
        public FTDI.FT_STATUS InitializeFTDI()
        {
            // Create new instance of the FTDI device class
             SPI_Device= new FTDI();
            uint ftdiDeviceCount = 0;

            int i;

            Initialize_SPI_Constants();

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

            // Check status
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // If no devices available, return
            if (ftdiDeviceCount == 0)
            {
                ftStatus = FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND;
                return (ftStatus);
            }

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

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

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (i = 0; i < ftdiDeviceCount; i++)
                {
                    //MessageBox.Show("Device Index: " + i.ToString());
                    //MessageBox.Show("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
                    //MessageBox.Show("Type: " + ftdiDeviceList[i].Type.ToString());
                    //MessageBox.Show("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
                    //MessageBox.Show("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
                    //MessageBox.Show("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
                    //MessageBox.Show("Description: " + ftdiDeviceList[i].Description.ToString());
                    //MessageBox.Show("");
                }
            }


            // Open first device in our list by serial number
            ftStatus = SPI_Device.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }
            // Set latency timer
            ftStatus = SPI_Device.SetLatency(2);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // Reset the controller
            ftStatus = SPI_Device.SetBitMode(0, 0);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // Set synchronous bit bang mode
            ftStatus = SPI_Device.SetBitMode(FT232Routputs, 4);  // Set device to mode 4 and sets outputs
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // Set baud rate/bit clock settings
            ftStatus = SPI_Device.SetBaudRate(3000000);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            presetShiftRegisterOutputs();

            return (ftStatus);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: brand7n/FTDIconnect
        static void Main(string[] args)
        {
            program();
            Console.WriteLine("This program contains a software component made available under the GNU Lesser General Public License.  The source code of this component is available here:");
            Console.WriteLine("https://github.com/brand7n/lpc21isp");

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

            attention();
            Console.WriteLine("ATTEMPTING TO CONNECT...");
            subdue();


            while (true)
            {
                try
                {
                    open(myFtdiDevice);
                    Thread.Sleep(1000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    attention();
                    Console.WriteLine("DISCONNECTED.  RESTART OR REATTACH DEVICE.");
                    subdue();
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    myFtdiDevice.CyclePort();
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Called when the window is loaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            int i;
            
            // Configure datagrid
            dataGrid1.Items.Clear();
            dataGrid1.Columns.Clear();
            dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Device Number", Binding = new Binding("Dn") });
            dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Serial Number", Binding = new Binding("Sn") });
            dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Device Description", Binding = new Binding("Dd") });

            // Get FTDI basic data
            FTDI f = new FTDI();
            uint devicecount = 0;
            f.GetNumberOfDevices(ref devicecount);

            // Fill datagrid with device data
            string dd, sn, dn;
            if (devicecount == 0)
            {
                FtErrorReport("GetFTDeviceCount", FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND);
            }
            for (i = 0; i < devicecount; i++)
            {
                f.OpenByIndex((uint)i);
                dn = String.Format("Device {0}", i);
                f.GetSerialNumber(out sn);
                f.GetDescription(out dd);
                f.Close();
                dataGrid1.Items.Add( new SDevice{ Dd = dd, Dn = dn, Sn = sn } );
            }
        }
コード例 #6
0
 /// <summary>
 /// Show error report
 /// </summary>
 /// <param name="errStr">Error description</param>
 /// <param name="portStatus">Error code</param>
 public void FtErrorReport(string errStr, FTDI.FT_STATUS portStatus)
 {
     string str = "";
     if (portStatus == FTDI.FT_STATUS.FT_OK)
         return;
     switch (portStatus)
     {
         case FTDI.FT_STATUS.FT_INVALID_HANDLE:
             str = errStr + " - Invalid Handle...";
             break;
         case FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND:
             str = errStr + " - Device Not Found....";
             break;
         case FTDI.FT_STATUS.FT_DEVICE_NOT_OPENED:
             str = errStr + " - Device Not Opened...";
             break;
         case FTDI.FT_STATUS.FT_IO_ERROR:
             str = errStr + " - General IO Error...";
             break;
         case FTDI.FT_STATUS.FT_INSUFFICIENT_RESOURCES:
             str = errStr + " - Insufficient Resources";
             break;
         case FTDI.FT_STATUS.FT_INVALID_PARAMETER:
             str = errStr + " - Invalid Parameter ...";
             break;
     }
     MessageBox.Show(str, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
 }
コード例 #7
0
ファイル: FTDIComms.cs プロジェクト: suborigin/ftdi-test
        public FTDIComms()
        {
            // Create new instance of the FTDI device class
            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)
            {
                Console.WriteLine("Number of FTDI devices: " + this.ftdiDeviceCount);
                Console.WriteLine("");
            }
            else
            {
                Console.WriteLine("Failed to get number of devices (error " + this.ftStatus + ")");
                return;
            }

            // If no devices available, return
            if (ftdiDeviceCount == 0)
            {
                Console.WriteLine("Failed to get number of devices (error " + this.ftStatus + ")");
            }
        }
コード例 #8
0
        public void Connect(SerialPort port)
        {
            _port = port;
            port.Open();
            _laser = new FTDI();
            //uint devs =0 ;
            //_laser.GetNumberOfDevices(ref devs);
            // FTDI.FT_DEVICE_INFO_NODE[] list = new FTDI.FT_DEVICE_INFO_NODE[devs];
            //_laser.GetDeviceList(list);
               // _laser.OpenBySerialNumber("FT94OEXA");  //cable
               // _laser.OpenBySerialNumber("A602KUPB"); // Dongle
               _laser.OpenBySerialNumber("DEFCON01");  //Joe's

            //_controller.Connect(new SerialPort((string)comboBox2.SelectedItem, 57600));
            _laser.SetBaudRate(4800);
            _laser.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE);
            if (laser_always_on)
            {
                _laser.SetRTS(false);
            }
            else
            {
                _laser.SetRTS(false);
            }
        }
コード例 #9
0
 public FTDIDevice()
 {
     bufferIn = new List<byte>();
     incomingMessages = new List<Message>();
     COMPortMutex = new Mutex();
     serialDataMutex = new Mutex();
     valuesMutex = new Mutex();
     FtdiDevice = new FTDI();
 }
コード例 #10
0
ファイル: mainForm.cs プロジェクト: sinc/DeviceHandler
        public mainForm(FTDI dev)
        {
            InitializeComponent();
            m_graphBuilder = new GraphBuilder();
            m_defectoscope = new CHDDriver(m_graphBuilder, dev, kDevice_Descriptor, 9600u);
            m_defectoscopeCharts = new DefectoscopeApplet(m_graphBuilder, mainChartPanel, dipoleChartPanel, dipoleListBox, this);

            m_graphBuilder.ConnectApplets(m_defectoscope, m_defectoscopeCharts);
        }
コード例 #11
0
        public FTDIDevice(string s_description, uint u32_baudrate, bool flowCtrl)
        {
            bufferIn = new List<byte>();
            incomingMessages = new List<Message>();
            COMPortMutex = new Mutex();
            serialDataMutex = new Mutex();
            valuesMutex = new Mutex();
            FtdiDevice = new FTDI();

            connect(s_description, u32_baudrate, flowCtrl);
        }
コード例 #12
0
ファイル: Ftdi.cs プロジェクト: aemerman/Nevis14
 public Ftdi()
 {
     isOpen = false;
     portA = new FTDI();
     portB = new FTDI();
     portADescription = "Nevis13_tester A";
     portBDescription = "Nevis13_tester B";
     Open(portA, portADescription);
     Open(portB, portBDescription);
     isOpen = true;
 }
コード例 #13
0
 public void checkForOldFWPID(uint numDevices, FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList)
 {
     for (int k = 0; k < numDevices; k++)
     {
         if (ftdiDeviceList[k] != null)
             if (ftdiDeviceList[k].ID.ToString() == parameters.finalOldFWPID.ToString())
             {
                 parameters.reprogramming_oldFW_HW3_SW2 = true;
             }
     }
 }
コード例 #14
0
ファイル: FTDIBulkDriver.cs プロジェクト: sinc/DeviceHandler
 public FTDIBulkDriver(GraphBuilder gb, FTDI device, string deviceDescriptor, uint baudRate)
     : base(gb)
 {
     FTDI.FT_STATUS fs;
     if (device != null)
     {
         m_device = device;
         if ((fs = device.OpenBySerialNumber(deviceDescriptor)) != FTDI.FT_STATUS.FT_OK)
             throw new Exception(string.Format("Невозможно открыть устройство. Устройство не готово. ({0})", fs));
         if ((fs = device.SetBaudRate(baudRate)) != FTDI.FT_STATUS.FT_OK)
             throw new Exception(string.Format("Устройство не поддерживает заданную скорость ({0})", fs));
         m_outputPin = RegisterOutputPin<byte[]>("MainOutPin");
     }
 }
コード例 #15
0
ファイル: mainForm.cs プロジェクト: sinc/DeviceHandler
        public mainForm(FTDI dev)
        {
            InitializeComponent();

            m_graphBuilder = new GraphBuilder();

            m_bulk = new FTDIBulkDriver(m_graphBuilder, dev, kDevice_Descriptor, 9600u);
            m_reader = new AdnsReader(m_graphBuilder);
            m_printer = new Printer(m_graphBuilder, Graphics.FromHwnd(Handle));

            m_graphBuilder.ConnectApplets(m_bulk, m_reader);
            m_graphBuilder.ConnectApplets(m_reader, m_printer);

            m_bulk.start(900);
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: w4-pwr/studia
        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");
        }
コード例 #17
0
 internal TactonicUSB(FTDI ftdiHandle)
 {
     ftdi = ftdiHandle;
     deviceFrameInfo = new TactonicDevice();
     tileFrameInfo = new TactonicDevice();
     frameCallbackList = new TactonicFrameCallback[32];
     frameCallbackLen = 0;
     deviceFrames = new TactonicFrame[2];
     isStopped = false;
     isTiles = false;
     numTiles = 1;
     tileX = new int[16];
     tileY = new int[16];
     tileID = new int[16];
     stackPath = new int[16];
     tileNum = 0;
 }
コード例 #18
0
        public CentralBoard()
        {
            centralBoardCom = new FTD2XX_NET.FTDI();
            propertyManager = PropertyManager.i;
            propertyManager.Load("Hardware");

            string SerialNumber = propertyManager.GetStringValue("Hardware", "CentralBoardSerialNumber");

            centralBoardCom.OpenBySerialNumber(SerialNumber);

            if (!centralBoardCom.IsOpen)
            {
                throw new Exception("Could Not Connect to CentralBoard");
            }

            centralBoardCom.SetBaudRate(38400);
            centralBoardCom.SetTimeouts(100, 1000);
        }
コード例 #19
0
ファイル: GraphicLCD.cs プロジェクト: yuhki50/MINTIA_Display
        /// <summary>
        /// ピンアサインを設定します。
        /// </summary>
        /// <param name="latch">ラッチ</param>
        /// <param name="a0">データ・コマンド切り替え</param>
        /// <param name="enable">イネーブル</param>
        /// <param name="reset">リセット</param>
        /// <param name="d0">データピン0</param>
        /// <param name="d1">データピン1</param>
        /// <param name="d2">データピン2</param>
        /// <param name="d3">データピン3</param>
        public GraphicLCD(int latch, int a0, int enable, int reset, int d0, int d1, int d2, int d3)
        {
            /* 変数に記憶 */
            _latch_pin = (byte)(1 << latch);
            _a0_pin = (byte)(1 << a0);
            _enable_pin = (byte)(1 << enable);
            _reset_pin = (byte)(1 << reset);

            _data_pins = new byte[4];
            _data_pins[0] = (byte)(1 << d0);
            _data_pins[1] = (byte)(1 << d1);
            _data_pins[2] = (byte)(1 << d2);
            _data_pins[3] = (byte)(1 << d3);

            /* FTDIデバイス */
            // インスタンス作成 //
            _FTDI_Device = new FTDI();
        }
コード例 #20
0
ファイル: LedMatrix.cs プロジェクト: yuhki50/MINTIA_Display
        /// <summary>
        /// ピンアサインを設定します。
        /// </summary>
        /// <param name="clock">クロックピン</param>
        /// <param name="enable">イネーブルピン</param>
        /// <param name="d0">データピン0</param>
        /// <param name="d1">データピン1</param>
        /// <param name="d2">データピン2</param>
        /// <param name="d3">データピン3</param>
        /// <param name="d4">データピン4</param>
        /// <param name="d5">データピン5</param>
        public LedMatrix(int clock, int enable, int d0, int d1, int d2, int d3, int d4, int d5)
        {
            /* 変数に記憶 */
            _clock_pin = (byte)(1 << clock);
            _enable_pin = (byte)(1 << enable);

            _data_pins = new byte[6];
            _data_pins[0] = (byte)(1 << d0);
            _data_pins[1] = (byte)(1 << d1);
            _data_pins[2] = (byte)(1 << d2);
            _data_pins[3] = (byte)(1 << d3);
            _data_pins[4] = (byte)(1 << d4);
            _data_pins[5] = (byte)(1 << d5);

            /* FTDIデバイス */
            // インスタンス作成 //
            _FTDI_Device = new FTDI();
        }
コード例 #21
0
ファイル: mainForm.cs プロジェクト: sinc/blackfin
        static void Main(string[] args)
        {
            FTDI dev = new FTDI();
            uint num_of_devices = 0;
            bool device_found = false;

            while (!device_found)
            {
                dev.GetNumberOfDevices(ref num_of_devices);
                if (num_of_devices > 0)
                {
                    FTDI.FT_DEVICE_INFO_NODE[] devList = new FTDI.FT_DEVICE_INFO_NODE[num_of_devices];
                    dev.GetDeviceList(devList);
                    foreach (FTDI.FT_DEVICE_INFO_NODE dev_info in devList)
                    {
                        if (dev_info.SerialNumber == bfmanager.kDevice_Descriptor)
                        {
                            device_found = true;
                            break;
                        }
                    }
                    if (device_found)
                    {
                        try
                        {
                            Application.Run(new MainForm(dev));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                else
                {
                    if (MessageBox.Show("Устройство не обнаружено. Подключите и нажмите ОК.", "Ошибка", MessageBoxButtons.OKCancel) ==
                        DialogResult.Cancel)
                    {
                        break;
                    }
                }
            }
        }
コード例 #22
0
 public bool OpenAny(uint baudRate = 38400)
 {
     try
     {
         this.ftdiPort = new FTD2XX_NET.FTDI();
         uint count = 0;
         this.status = this.ftdiPort.GetNumberOfDevices(ref count);
         if (count == 1)
         {
             status = this.ftdiPort.OpenByIndex(0);
             status = this.ftdiPort.SetBaudRate(baudRate);
             return(true);
         }
     }
     catch
     {
         return(false);
     }
     return(false);
 }
コード例 #23
0
        public void checkForWrongPID(uint numDevices, FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList, uint wrongpid)
        {
            //FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
            //uint numDevices = CountDevices();
            //FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[numDevices]; try
            //{
            //    ftStatus = ftdi.GetDeviceList(ftdiDeviceList);  //the source of the mysterious buffering error!  at long last!
            //}
            //catch (Exception e)
            //{
            //    if (e.Message.Contains("supplied buffer is not big enough")) //retry.
            //    {
            //        System.Threading.Thread.Sleep(80);
            //        numDevices = CountDevices();
            //        ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[numDevices];
            //        ftStatus = ftdi.GetDeviceList(ftdiDeviceList);
            //    }
            //    else throw new Exception(e.Message + "7");
            //}
            //if (ftStatus != FTDI.FT_STATUS.FT_OK) throw new Exception_Yellow("couldn't get device list; no device attached?");

            for (int k = 0; k < numDevices; k++) // look at all devices and get the LocID of the one which has the desired PID
            {
                if (ftdiDeviceList[k] != null)
                    if (ftdiDeviceList[k].ID.ToString() == wrongpid.ToString())
                    {
                        StreamReader testTxt = new StreamReader(Parameters.logfilepath);
                        string allRead = testTxt.ReadToEnd();            //Reads the whole text file to the end
                        testTxt.Close();                                 //Closes the text file after it is fully read.
                        if (Regex.IsMatch(allRead, parameters.MAC))        // and if this MAC address is in the log file as having been loaded already
                            throw new Exception_Red("Wrong board ID number -- this board's firmware has already been successfully loaded.  Remove and set aside.");
                        else
                            throw new Exception_Red("Wrong board ID number -- this USB is corrupted.  Set aside.");
                    }
            }
        }
コード例 #24
0
        //==============================
        //serial port stuff
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public FTDI.FT_STATUS setSerialParams(FTDI dev, uint index)
        {
            FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
            // Set up device data parameters
            // must be opened first

            // Set Baud rate to 9600
            ftStatus = dev.SetBaudRate(9600);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
                return ftStatus;

            // Set data characteristics - Data bits, Stop bits, Parity
            ftStatus = dev.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)
                return ftStatus;

            // Set flow control - set RTS/CTS flow control
            //ftStatus = dev.SetFlowControl(
            //    FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0x11, 0x13);
            //ftStatus = dev.SetRTS(true);
            //Thread.Sleep(5);
            //ftStatus=dev.SetRTS(false);

            ftStatus = dev.SetFlowControl(
                FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0x11, 0x13);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
                return ftStatus;

            // Set read timeout to 5 seconds, write timeout to infinite
            ftStatus = dev.SetTimeouts(5000, 0);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
                return ftStatus;
            return ftStatus;
        }
コード例 #25
0
 //end Properties
 //=======================================
 //Public Methods
 /// <summary>
 /// Read FTDI EEPROM
 /// </summary>
 /// <param name="dev"></param>
 /// <returns></returns>
 public FTDI.FT_STATUS readFtdiEEProm(FTDI dev)
 {
     FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
     ftEeprom = new FTDI.FT232R_EEPROM_STRUCTURE();
     try
     {
         ftStatus = dev.ReadFT232REEPROM(ftEeprom);
     }
     catch (FTDI.FT_EXCEPTION ex)
     {
         throw ex;
     }
     return ftStatus;
 }
コード例 #26
0
 private FTDI.FT_STATUS ftGPIO(FTDI dev, uint index, uint gpBits)
 {
     //note: must set EEPROM bit bang mode first for this to work
     //note: only lower nibble of gpbits does anything
     FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
     byte mask = 0xf0;  //set gpio0-gpio3 as outputs
     gpBits &= 0x0f;
     byte send = (byte)(mask | gpBits);
     ftStatus = dev.SetBitMode(send, FTDI.FT_BIT_MODES.FT_BIT_MODE_CBUS_BITBANG);
     if (ftStatus != FTDI.FT_STATUS.FT_OK)
         return ftStatus;
     return ftStatus;
 }
コード例 #27
0
 /// <summary>
 /// Take the previously read EEPROM_STRUCTURE 
 /// and write it back to the FT EEPROM
 /// after elsewhere checking and modifying the 
 /// product description if necessary
 /// </summary>
 /// <param name="dev"></param>
 /// <returns></returns>
 public FTDI.FT_STATUS writeFtdiEEProm(FTDI dev)
 {
     FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
     try
     {
         ftStatus = dev.WriteFT232REEPROM(ftEeprom);
     }
     catch (FTDI.FT_EXCEPTION ex)
     {
         throw ex;
     }
     return ftStatus;
 }
コード例 #28
0
ファイル: Form1.cs プロジェクト: pa3gsb/RadioBerry
        private void button1_Click(object sender, EventArgs e)
        {
            //http://www.chd.at/blog/electronic/FTDI-in-CS
            //Note: don’t forget to connect the xDBUS1 with xDBUS2(!) = SDA

            Optifert.FTDI.Instance.Init(0);

            //Optifert.FTDI.Instance.close();

            if (Optifert.FTDI.Instance.isConnected())
            {
                Console.WriteLine("connected ");
            } else
            {
                Console.WriteLine("Not connected ");
            }

            Optifert.FTDI.Instance.close();

            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)
            {
                System.Diagnostics.Debug.WriteLine("Number of FTDI devices: " + ftdiDeviceCount.ToString());
                System.Diagnostics.Debug.WriteLine("");
            }
            else
            {
                // Wait for a key press
                System.Diagnostics.Debug.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");

                return;
            }

            // If no devices available, return
            if (ftdiDeviceCount == 0)
            {
                // Wait for a key press
                Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
                Console.ReadKey();
                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);

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (UInt32 i = 0; i < ftdiDeviceCount; i++)
                {
                    Console.WriteLine("Device Index: " + i.ToString());
                    Console.WriteLine("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
                    Console.WriteLine("Type: " + ftdiDeviceList[i].Type.ToString());
                    Console.WriteLine("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
                    Console.WriteLine("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
                    Console.WriteLine("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
                    Console.WriteLine("Description: " + ftdiDeviceList[i].Description.ToString());
                    Console.WriteLine("");
                }
            }

            // Open first device in our list by serial number
            ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                // Wait for a key press
                Console.WriteLine("Failed to open device (error " + ftStatus.ToString() + ")");
                Console.ReadKey();
                return;
            }

            // Create our device EEPROM structure based on the type of device we have open
            if (ftdiDeviceList[0].Type == FTDI.FT_DEVICE.FT_DEVICE_232H)
            {
                Console.WriteLine("is 232 H");

            }

            myFtdiDevice.Close();
        }
コード例 #29
0
ファイル: FTDevice.cs プロジェクト: jjlewando/flicker
 public FTDevice()
 {
     myFtdiDevice = new FTDI();
     opened = false;
 }
コード例 #30
0
ファイル: LedMatrix.cs プロジェクト: yuhki50/MINTIA_Display
        private void checkStatus(FTDI.FT_STATUS status)
        {
            switch (status)
            {
                case FTDI.FT_STATUS.FT_OK:
                    return;

                case FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND:
                    throw new USB_IOException("デバイスが見つかりません。");

                case FTDI.FT_STATUS.FT_DEVICE_NOT_OPENED:
                    throw new USB_IOException("デバイスと接続されていません。");

                case FTDI.FT_STATUS.FT_DEVICE_NOT_OPENED_FOR_ERASE:
                    throw new USB_IOException("削除のためにデバイスと接続されていません。");

                case FTDI.FT_STATUS.FT_DEVICE_NOT_OPENED_FOR_WRITE:
                    throw new USB_IOException("書き込むためにデバイスと接続されていません。");

                case FTDI.FT_STATUS.FT_EEPROM_ERASE_FAILED:
                    throw new USB_IOException("EEPROMの削除に失敗しました。");

                case FTDI.FT_STATUS.FT_EEPROM_NOT_PRESENT:
                    throw new USB_IOException("EEPROMが見つかりません。");

                case FTDI.FT_STATUS.FT_EEPROM_NOT_PROGRAMMED:
                    throw new USB_IOException("EEPROMがプログラムされていません。");

                case FTDI.FT_STATUS.FT_EEPROM_READ_FAILED:
                    throw new USB_IOException("EEPROMの読み込みに失敗しました。");

                case FTDI.FT_STATUS.FT_EEPROM_WRITE_FAILED:
                    throw new USB_IOException("EEPROMの書き込みに失敗しました。");

                case FTDI.FT_STATUS.FT_FAILED_TO_WRITE_DEVICE:
                    throw new USB_IOException("データ転送に失敗しました。");

                case FTDI.FT_STATUS.FT_INSUFFICIENT_RESOURCES:
                    throw new USB_IOException("リソースが不足しています。");

                case FTDI.FT_STATUS.FT_INVALID_ARGS:
                    throw new USB_IOException("引数が無効です。");

                case FTDI.FT_STATUS.FT_INVALID_BAUD_RATE:
                    throw new USB_IOException("ボーレートが無効です。");

                case FTDI.FT_STATUS.FT_INVALID_HANDLE:
                    throw new USB_IOException("ハンドルが無効です。");

                case FTDI.FT_STATUS.FT_INVALID_PARAMETER:
                    throw new USB_IOException("パラメーターが無効です。");

                case FTDI.FT_STATUS.FT_IO_ERROR:
                    throw new USB_IOException("I/Oエラーが発生しました。");

                default:
                    throw new USB_IOException("不明なエラーが発生しました。");
            }
        }
コード例 #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="iSoundChipType"></param>
        /// <param name="clock"></param>
        /// <returns></returns>
        public static VsifClient TryToConnectVSIF(VsifSoundModuleType soundModule, PortId comPort, bool shareOnly)
        {
            lock (lockObject)
            {
                foreach (var c in vsifClients)
                {
                    if (c.SoundModuleType == soundModule)
                    {
                        if (c.DataWriter.PortName.Equals("COM" + (int)(comPort + 1)))
                        {
                            c.ReferencedCount++;
                            return(c);
                        }
                        if (c.DataWriter.PortName.Equals("FTDI_COM" + (int)comPort))
                        {
                            c.ReferencedCount++;
                            return(c);
                        }
                    }
                }
                if (shareOnly)
                {
                    return(null);
                }

                try
                {
                    switch (soundModule)
                    {
                    case VsifSoundModuleType.Generic_UART:
                    {
                        SerialPort sp = null;
                        sp = new SerialPort("COM" + ((int)comPort + 1));
                        sp.WriteTimeout = 100;
                        sp.ReadTimeout  = 100;
                        sp.BaudRate     = 115200;
                        sp.BaudRate     = 1200 * (int)Settings.Default.BitBangWaitAY8910;
                        sp.StopBits     = StopBits.One;
                        sp.DataBits     = 8;
                        sp.Handshake    = Handshake.None;
                        sp.Open();
                        var client = new VsifClient(soundModule, new PortWriterGenericUart(sp));
                        client.Disposed += Client_Disposed;
                        vsifClients.Add(client);
                        return(client);
                    }

                    case VsifSoundModuleType.SMS:
                    {
                        SerialPort sp = null;
                        sp = new SerialPort("COM" + ((int)comPort + 1));
                        sp.WriteTimeout = 100;
                        sp.ReadTimeout  = 100;
                        sp.BaudRate     = 115200;
                        sp.StopBits     = StopBits.Two;
                        //sp.BaudRate = 57600;
                        //sp.StopBits = StopBits.One;
                        sp.Parity    = Parity.None;
                        sp.DataBits  = 8;
                        sp.Handshake = Handshake.None;
                        sp.Open();
                        var client = new VsifClient(soundModule, new PortWriterGenesis(sp));
                        client.Disposed += Client_Disposed;
                        vsifClients.Add(client);
                        return(client);
                    }

                    case VsifSoundModuleType.Genesis:
                    {
                        SerialPort sp = null;
                        sp = new SerialPort("COM" + ((int)comPort + 1));
                        sp.WriteTimeout = 500;
                        sp.ReadTimeout  = 500;
                        //sp.BaudRate = 230400;
                        sp.BaudRate = 163840;
                        sp.StopBits = StopBits.One;
                        sp.Parity   = Parity.None;
                        sp.DataBits = 8;
                        sp.Open();
                        var client = new VsifClient(soundModule, new PortWriterGenesis(sp));
                        client.Disposed += Client_Disposed;
                        vsifClients.Add(client);
                        return(client);
                    }

                    case VsifSoundModuleType.Genesis_Low:
                    {
                        SerialPort sp = null;
                        sp = new SerialPort("COM" + ((int)comPort + 1));
                        sp.WriteTimeout = 500;
                        sp.ReadTimeout  = 500;
                        sp.BaudRate     = 115200;
                        sp.StopBits     = StopBits.One;
                        sp.Parity       = Parity.None;
                        sp.DataBits     = 8;
                        sp.Open();
                        var client = new VsifClient(soundModule, new PortWriterGenesis(sp));
                        client.Disposed += Client_Disposed;
                        vsifClients.Add(client);
                        return(client);
                    }

                    case VsifSoundModuleType.Genesis_FTDI:
                    {
                        var ftdi = new FTD2XX_NET.FTDI();
                        var stat = ftdi.OpenByIndex((uint)comPort);
                        if (stat == FTDI.FT_STATUS.FT_OK)
                        {
                            ftdi.SetBitMode(0x00, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET);
                            ftdi.SetBitMode(0xff, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG);
                            ftdi.SetBaudRate(FTDI_BAUDRATE_GEN * FTDI_BAUDRATE_GEN_MUL);
                            ftdi.SetTimeouts(500, 500);
                            ftdi.SetLatency(0);
                            byte ps = 0;
                            ftdi.GetPinStates(ref ps);
                            if ((ps & 0x40) == 0)
                            {
                                uint dummy = 0;
                                ftdi.Write(new byte[] { 0x40 }, 1, ref dummy);
                            }

                            var client = new VsifClient(soundModule, new PortWriterGenesis(ftdi, comPort));

                            //ftdi.Write(new byte[] { (byte)(((0x07 << 1) & 0xe) | 0) }, 1, ref dummy);
                            //ftdi.Write(new byte[] { (byte)(((0x38 >> 2) & 0xe) | 1) }, 1, ref dummy);
                            //ftdi.Write(new byte[] { (byte)(((0xC0 >> 5) & 0xe) | 0) }, 1, ref dummy);
                            //ftdi.Write(new byte[] { 1 }, 1, ref dummy);

                            client.Disposed += Client_Disposed;
                            vsifClients.Add(client);
                            return(client);
                        }
                    }
                    break;

                    case VsifSoundModuleType.MSX_FTDI:
                    {
                        var ftdi = new FTD2XX_NET.FTDI();
                        var stat = ftdi.OpenByIndex((uint)comPort);
                        if (stat == FTDI.FT_STATUS.FT_OK)
                        {
                            ftdi.SetBitMode(0x00, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET);
                            ftdi.SetBitMode(0xff, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG);
                            ftdi.SetBaudRate(FTDI_BAUDRATE_MSX * FTDI_BAUDRATE_MSX_MUL);
                            ftdi.SetTimeouts(500, 500);
                            ftdi.SetLatency(0);
                            //{
                            //    uint dummy = 0x00;
                            //    ftdi.Write(new byte[] { (byte)dummy }, 1, ref dummy);
                            //}

                            var client = new VsifClient(soundModule, new PortWriterMsx(ftdi, comPort));

                            client.Disposed += Client_Disposed;
                            vsifClients.Add(client);
                            return(client);
                        }
                    }
                    break;

                    case VsifSoundModuleType.NES_FTDI_INDIRECT:
                    case VsifSoundModuleType.NES_FTDI_DIRECT:
                    {
                        var ftdi = new FTD2XX_NET.FTDI();
                        var stat = ftdi.OpenByIndex((uint)comPort);
                        if (stat == FTDI.FT_STATUS.FT_OK)
                        {
                            ftdi.SetBitMode(0x00, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET);
                            ftdi.SetBitMode(0xff, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG);
                            ftdi.SetBaudRate(FTDI_BAUDRATE_NES * FTDI_BAUDRATE_NES_MUL);
                            ftdi.SetTimeouts(500, 500);
                            ftdi.SetLatency(0);
                            byte ps = 0;
                            ftdi.GetPinStates(ref ps);
                            if ((ps & 0x10) == 0x10)
                            {
                                uint dummy = 0;
                                ftdi.Write(new byte[] { 0x00 }, 1, ref dummy);
                            }

                            VsifClient client = null;
                            switch (soundModule)
                            {
                            case VsifSoundModuleType.NES_FTDI_DIRECT:
                                client = new VsifClient(soundModule, new PortWriterNesDirect(ftdi, comPort));
                                break;

                            case VsifSoundModuleType.NES_FTDI_INDIRECT:
                                client = new VsifClient(soundModule, new PortWriterNesIndirect(ftdi, comPort));
                                break;
                            }

                            client.Disposed += Client_Disposed;
                            vsifClients.Add(client);
                            return(client);
                        }
                    }
                    break;
                    }

                    //sp.Write(new byte[] { (byte)'M', (byte)'a', (byte)'M', (byte)'i' }, 0, 4);
                    //sp.BaseStream.WriteByte((byte)soundModule);
                    //Thread.Sleep(100);
                    //var ret = sp.BaseStream.ReadByte();
                    //if (ret == 0x0F)   //OK
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(Exception))
                    {
                        throw;
                    }
                    else if (ex.GetType() == typeof(SystemException))
                    {
                        throw;
                    }
                }
                return(null);
            }
        }
コード例 #32
-2
        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("CAM8"))
                        {
                            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;
            coolerCheckBox.Checked = Camera.coolerEnabledState;
            //find available com ports in system
            string[] comPorts;
            comPorts = SerialPort.GetPortNames();
            int j;
            for (j = 0; j < comPorts.Length; j++)
            {
                coolerComPortComboBox.Items.Add(comPorts[j]);
                if (comPorts[j] == Camera.coolerComPortState) coolerComPortComboBox.SelectedIndex = j;
            }

        }
コード例 #33
-4
        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();
        }