public void OpenByDescription(string s) { //Get the SerialNum of the specified device// Not tested ftStatus = myFtdiDevice.OpenByDescription(s); //OpenBySerialNumber(s); 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); }
public FTDIGPIO() { FTD2XX = new FTDI(); outputbuffer = new byte[8]; inputbuffer = new byte[8]; if (FTD2XX.GetNumberOfDevices(ref ndevice) == FTDI.FT_STATUS.FT_OK) { if (ndevice > 0) { devices = new FTDI.FT_DEVICE_INFO_NODE[ndevice]; FTSTATUS = FTD2XX.GetDeviceList(devices); if (FTD2XX.OpenByDescription(devices[0].Description) == FTDI.FT_STATUS.FT_OK) { Config(); Found = true; } else { Debug.LogWarning($"Can Not Open Device: {devices[0].Description}."); } } else { Debug.LogWarning("No FTDI Device Detected."); } } else { Debug.LogWarning("Can Not Detect FTDI Devices."); } }
public ControllerFTDI(string description, string serialNumber) { this.dataOut = new byte[8]; this.dataInBuf = new byte[200]; this.DESCRIPTION = description; this.SERIAL_NUMBER = serialNumber; this.SensorsList = new List <Sensor>(); ftdi = new FTDI(); status = ftdi.GetNumberOfDevices(ref this.devCount); CheckStatus(status); if (this.devCount == 0) { throw new Exception($"Devices not connected!"); } this.deviceList = new FTDI.FT_DEVICE_INFO_NODE[this.devCount]; status = ftdi.OpenByDescription(DESCRIPTION); CheckStatus(status); Initialization(); Purge(); if (ResetAVR() != 80) { throw new FTDI.FT_EXCEPTION("Error: Reset AVR"); } UpdateConnectedSensors(10, SensorsList); }
private void btnOpen_Click(object sender, EventArgs e) { #if USE_FTD_DRIVER status = esp.OpenByDescription(FTDI_Description); esp.SetBaudRate(ESP_BOOTLOADER_BAUD); Console.WriteLine(status); if (status == FTDI.FT_STATUS.FT_OK) { log.AppendText("Port open success!\r\n"); esp.SetTimeouts(250, 250); timer1.Enabled = true; } else { log.AppendText("Error opening port: " + status + "\r\n"); } #else //creating the com port object opens it immediately, so it will fail if the com port is not available (not connected or opened in another program) //so lets catch the failure. try { esp_programmer = new COMPort(cboPorts.SelectedItem.ToString(), ESP_BOOTLOADER_BAUD); log.AppendText("COM Port Opened"); btnOpen.Enabled = false; } catch { log.AppendText("Failed to open COM Port Opened. Another application is using it."); } #endif }
private void btnOpen_Click(object sender, EventArgs e) { status = esp.OpenByDescription(FTDI_Description); esp.SetBaudRate(ESP_BOOTLOADER_BAUD); Console.WriteLine(status); if (status == FTDI.FT_STATUS.FT_OK) { log.AppendText("Port open success!\r\n"); esp.SetTimeouts(250, 250); timer1.Enabled = true; } else { log.AppendText("Error opening port: " + status + "\r\n"); } }
public void Connect() { ftstatus = device.GetDeviceList(devicelist); try { //sprawdzenie czy urzadzenie zostalo podlaczone ftstatus = device.OpenByDescription(devicelist[0].Description); ftstatus = device.SetBitMode(0xff, 1); //pozwala na przesylanie danych do ukladu Console.WriteLine("Status: " + ftstatus.ToString()); } catch (Exception e) { Console.WriteLine("Urzadzenie nie zostao podlaczone!\nNacisnij [ENTER] aby zamknac program"); Console.ReadLine(); Environment.Exit(0); } }
public void Open() { status = ftdi.GetNumberOfDevices(ref this.devCount); CheckStatus(status); if (this.devCount == 0) { throw new Exception($"No connected devices!"); } this.deviceList = new FTDI.FT_DEVICE_INFO_NODE[this.devCount]; status = ftdi.OpenByDescription(DESCRIPTION); CheckStatus(status); Initialization(); Purge(); if (ResetAVR() != 80) { throw new FTDI.FT_EXCEPTION("Error: Reset AVR"); } }
public bool connect(string s_description, uint u32_baudrate, bool flowCtrl) { logFile = new System.IO.StreamWriter(@".\log.txt", false); ftStatus = FtdiDevice.OpenByDescription(s_description); if (ftStatus == FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND || ftStatus == FTDI.FT_STATUS.FT_INVALID_HANDLE || ftStatus == FTDI.FT_STATUS.FT_DEVICE_NOT_OPENED) { isValid = false; logFile.Close(); return(false); } ftStatus = FtdiDevice.SetBaudRate(u32_baudrate); ftStatus = FtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE); if (flowCtrl) { ftStatus = FtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0, 0); } else { ftStatus = FtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); } ftStatus = FtdiDevice.SetTimeouts(5000, 5000); byte oldBitMode = 0; ftStatus = FtdiDevice.GetPinStates(ref oldBitMode); receivingThread = new Thread(new ThreadStart(USBReceivingRoutine)); receivingThread.IsBackground = true; processingThread = new Thread(new ThreadStart(processIncomingData)); processingThread.IsBackground = true; receivingThread.Start(); processingThread.Start(); waitForNewSerialData = new AutoResetEvent(false); return(true); }
public FtdiStream(string sensorDescription) { device = new FTDI(); UInt32 deviceCount = 0; var status = device.GetNumberOfDevices(ref deviceCount); if (status != FTDI.FT_STATUS.FT_OK) { throw new FtdiException("Failed to get number of devices", status); } Console.WriteLine("Number of FTDI devices: {0}", deviceCount); if (deviceCount == 0) { throw new NoFtdiDevicesAvailableException(); } status = device.OpenByDescription(sensorDescription); //if (status != FTDI.FT_STATUS.FT_OK) // throw new FtdiDeviceNotFoundException(sensorDescription, status); }
// public methods /// <summary> /// Attempt to open RHA2000-EVAL board connected to USB port. /// </summary> /// <param name="firmwareID1">Board ID number (1 of 3)</param> /// <param name="firmwareID2">Board ID number (2 of 3)</param> /// <param name="firmwareID3">Board ID number (3 of 3)</param> public void Open(ref int firmwareID1, ref int firmwareID2, ref int firmwareID3) { // Open FTDI USB device. UInt32 ftdiDeviceCount = 0; FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; // Create new instance of the FTDI device class. myFtdiDeviceA = new FTDI(); // Determine the number of FTDI devices connected to the machine. ftStatus = myFtdiDeviceA.GetNumberOfDevices(ref ftdiDeviceCount); // Check status. if (!(ftStatus == FTDI.FT_STATUS.FT_OK)) { UsbException e = new UsbException("USB Setup Error: Failed to get number devices"); throw e; } // If no devices available, return. if (ftdiDeviceCount == 0) { UsbException e = new UsbException("No valid USB devices detected"); throw e; } // Allocate storage for device info list. FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; // Populate our device list. ftStatus = myFtdiDeviceA.GetDeviceList(ftdiDeviceList); // There could be a status error here, but we're not checking for it... // The Intan Technologies RHA2000-EVAL board uses an FTDI FT2232H chip to provide a USB // interface to a PC. Detailed information on this chip may be found at: // // http://www.ftdichip.com/Products/ICs/FT2232H.htm // // The FT2232H supports two independent FIFO channels. The channel used by the RHA2000-EVAL // board is factory-configured with the name "Intan I/O board 1.0 A". (FTDI provides software // routines to open device by its name.) ftStatus = myFtdiDeviceA.OpenByDescription("Intan I/O Board 1.0 A"); if (ftStatus != FTDI.FT_STATUS.FT_OK) { UsbException e = new UsbException("Intan USB device A not found"); throw e; } // Set read timeout to 5 seconds, write timeout to infinite ftStatus = myFtdiDeviceA.SetTimeouts(5000, 0); // There could be status error here, but we're not checking for it... this.Stop(); // Purge receive buffer myFtdiDeviceA.Purge(FTDI.FT_PURGE.FT_PURGE_RX); // Check board ID and version number // // The RHA2000-EVAL board is controlled by sending one-byte ASCII command characters over // the USB interface. The 'I' character commands the board to return a 3-byte ID/version // number. UInt32 numBytesWritten = 0; Byte[] myChars = { 73 }; // 'I' = request board ID and version number ftStatus = myFtdiDeviceA.Write(myChars, 1, ref numBytesWritten); if (ftStatus != FTDI.FT_STATUS.FT_OK) { UsbException e = new UsbException("Could not write to Intan USB device"); throw e; } const UInt32 numBytesToRead = 3; // Wait until the desired number of bytes have been received. UInt32 numBytesAvailable = 0; while (numBytesAvailable < numBytesToRead) { ftStatus = myFtdiDeviceA.GetRxBytesAvailable(ref numBytesAvailable); if (ftStatus != FTDI.FT_STATUS.FT_OK) { UsbException e = new UsbException("Failed to get number of USB bytes available to read"); throw e; } } // Now that we have the amount of data we want available, read it. UInt32 numBytesRead = 0; ftStatus = myFtdiDeviceA.Read(readDataBufferA, numBytesToRead, ref numBytesRead); if (ftStatus != FTDI.FT_STATUS.FT_OK) { UsbException e = new UsbException("USB read error"); throw e; } firmwareID1 = Convert.ToInt32(readDataBufferA[0]); firmwareID2 = Convert.ToInt32(readDataBufferA[1]); firmwareID3 = Convert.ToInt32(readDataBufferA[2]); Debug.WriteLine("Board ID: " + readDataBufferA[0] + " " + (Convert.ToInt32(readDataBufferA[1])).ToString() + " " + (Convert.ToInt32(readDataBufferA[2])).ToString()); this.ZCheckOff(); this.SettleOff(); // Purge receive buffer. myFtdiDeviceA.Purge(FTDI.FT_PURGE.FT_PURGE_RX); dataJustStarted = true; }
public void Open(string description) { status = ftdi.OpenByDescription(description); CheckStatus(status); }
private void Polacz() { ftstatus = device.GetDeviceList(devicelist); ftstatus = device.OpenByDescription(devicelist[0].Description); ftstatus = device.SetBitMode(0xff, 1); }
private static bool FT232H_Initial() { UInt32 ftdiDeviceCount = 0; FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; // 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: " + ftdiDeviceCount.ToString()); Console.WriteLine(""); } else { // Wait for a key press Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")"); Console.ReadKey(); return(false); } // 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(false); } // 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.OpenByDescription("FT232H"); if (ftStatus != FTDI.FT_STATUS.FT_OK) { // Wait for a key press Console.WriteLine("Failed to open device (error " + ftStatus.ToString() + ")"); Console.ReadKey(); return(false); } return(true); }
internal DeviceConnectionState Connect(bool Emulation, out string Message) { m_Emulation = Emulation; DeviceConnectionState state; Message = ""; m_Stop = false; if (m_Emulation) { IsConnected = true; state = DeviceConnectionState.ConnectionSuccess; return(state); } if (!m_MyFtdiDevice.IsOpen) { IsConnected = false; m_FtStatus = m_MyFtdiDevice.OpenByDescription(DESCRIPTION_NAME); if (m_FtStatus == FTDI.FT_STATUS.FT_OK) { m_FtStatus = m_MyFtdiDevice.SetBaudRate(115200); } if (m_FtStatus == FTDI.FT_STATUS.FT_OK) { m_FtStatus = m_MyFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE); } if (m_FtStatus == FTDI.FT_STATUS.FT_OK) { m_FtStatus = m_MyFtdiDevice.SetBitMode(DIR_MASK, FTDI.FT_BIT_MODES.FT_BIT_MODE_MPSSE); } if (m_FtStatus == FTDI.FT_STATUS.FT_OK) { LedRedSwitch(false); LedGreenSwitch(false); IsConnected = true; m_FtStatus = m_MyFtdiDevice.GetPinStates(ref m_BitMode); if (m_FtStatus == FTDI.FT_STATUS.FT_OK) { if ((m_BitMode & B2_MASK) == 0 && !m_Buttons[1]) { m_Buttons[1] = true; IsStopButtonPressed = m_Buttons[1]; Cache.Net.CallbackManager.GatewayButtonPressHandler(ComplexButtons.ButtonStopFTDI, m_Buttons[1]); } else if ((m_BitMode & B2_MASK) != 0 && m_Buttons[1]) { m_Buttons[1] = false; IsStopButtonPressed = m_Buttons[1]; Cache.Net.CallbackManager.GatewayButtonPressHandler(ComplexButtons.ButtonStopFTDI, m_Buttons[1]); } } state = DeviceConnectionState.ConnectionSuccess; ThreadPool.QueueUserWorkItem(PoolingRoutine); } else { m_MyFtdiDevice.Close(); Message = "FT status " + m_FtStatus; state = DeviceConnectionState.ConnectionFailed; } } else { state = DeviceConnectionState.ConnectionSuccess; } return(state); }
public Enttec() { dmx512Pro.OpenByDescription("DMX USB PRO"); this.dmx_get_serial(); }