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); }
public string GetComPort() { string rv; FTDI.FT_STATUS ftStatus = ftdi.GetCOMPort(out rv); if (ftStatus != FTDI.FT_STATUS.FT_OK) { String errMsg = "failed to get ComPort (error " + ftStatus.ToString() + ")"; throw new FtdiException(errMsg); } return(rv); }
}/// <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); }
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); }
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(); }
private DX() { FTDI ftdi = new FTDI(); PropertyManager.i.Load("Hardware"); PropertyManager.i.Load("Dynamixel"); ftdi.OpenBySerialNumber(PropertyManager.i.GetStringValue("Hardware", "DynamixelSerialNumber")); if (!ftdi.IsOpen) { throw new Exception("Could not connect to Dynamixel"); } ftdi.GetCOMPort(out COMPort); ftdi.Close(); portHandle = dynamixel.portHandler(COMPort); dynamixel.openPort(portHandle); dynamixel.setBaudRate(portHandle, 1000000); dynamixel.packetHandler(); SetSpeed(Actuator.ArmPlate, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "ArmPlateSpeed")); SetSpeed(Actuator.ArmMiddle1, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "ArmMiddle1Speed")); SetSpeed(Actuator.ArmMiddle2, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "ArmMiddle2Speed")); SetSpeed(Actuator.ArmMiddle3, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "ArmMiddle3Speed")); SetSpeed(Actuator.GripperRotate, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "GripperRotateSpeed")); SetSpeed(Actuator.Gripper1, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "Gripper1Speed")); SetSpeed(Actuator.Gripper2, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "Gripper2Speed")); SetSpeed(Actuator.LeftLaser, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "LeftLaserSpeed")); SetSpeed(Actuator.RightLaser, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "RightLaserSpeed")); SetTorqueLimit(Actuator.Gripper1, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "Gripper1TorqueLimit")); SetTorqueLimit(Actuator.Gripper2, (ushort)PropertyManager.i.GetIntValue("Dynamixel", "Gripper2TorqueLimit")); PositionTofFactor = PropertyManager.i.GetIntValue("Dynamixel", "PositionTofFactor"); }
public static void AutoIdentifyPorts() { Dictionary <string, string> ftdi_ports_detected = new Dictionary <string, string>(); //clear out ports that don't exist first: ValidatePorts(); UInt32 ftdiDeviceCount = 0; FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; FTDI myFtdiDevice = new FTDI(); ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount); // Check status if (ftStatus != FTDI.FT_STATUS.FT_OK) { return; } if (ftdiDeviceCount == 0) { return; } FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList); if (ftStatus != FTDI.FT_STATUS.FT_OK) { return; } for (UInt32 i = 0; i < ftdiDeviceCount; i++) { ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[i].SerialNumber); if (ftStatus != FTDI.FT_STATUS.FT_OK) { return; } string port = ""; ftStatus = myFtdiDevice.GetCOMPort(out port); if (ftStatus != FTDI.FT_STATUS.FT_OK) { return; } myFtdiDevice.Close(); string serial_number = ftdiDeviceList[i].SerialNumber.ToString(); Console.WriteLine("FTDI detected. Serial Number: " + serial_number + " Port: " + port); ftdi_ports_detected.Add(ftdiDeviceList[i].SerialNumber.ToString(), port); } string motor_serial = "MOTORCOM"; string bms_serial = "BMSCOM"; string led_serial = "LEDCOM"; string autopilot_serial = "NMEACOM"; ValidatePorts(); if (ftdi_ports_detected.ContainsKey(motor_serial)) { Properties.Settings.Default.MotorComPort = ftdi_ports_detected[motor_serial]; } if (ftdi_ports_detected.ContainsKey(bms_serial)) { Properties.Settings.Default.BmsComPort = ftdi_ports_detected[bms_serial]; } if (ftdi_ports_detected.ContainsKey(led_serial)) { Properties.Settings.Default.LedComPort = ftdi_ports_detected[led_serial]; } if (ftdi_ports_detected.ContainsKey(autopilot_serial)) { Properties.Settings.Default.NmeaComPort = ftdi_ports_detected[autopilot_serial]; } Properties.Settings.Default.Save(); ValidatePorts(); //just in case something went wrong. }
public override void Open() { if (IsOpen()) { return; } ftdi = new FTDI(); // ポートの数 uint portNum = 0; FT_STATUS ret = ftdi.GetNumberOfDevices(ref portNum); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("Could not get port size. FT_STATUS=" + ret); } for (uint i = 0; i < portNum; i++) { ret = ftdi.OpenByIndex(i); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("Could not get a port. FT_STATUS=" + ret + ",portIndex=" + i); } string tmp; ret = ftdi.GetCOMPort(out tmp); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("Could not get port name. FT_STATUS=" + ret + ",portIndex=" + i); } if (tmp == port.PortName) { // Baudrate ret = FT_STATUS.FT_OK; ret = ftdi.SetBaudRate((uint)port.BaudRate); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("Could not set BaudRate. FT_STATUS=" + ret + ",BaudRate=" + port.BaudRate); } // DataBits byte dataBits = FTDI.FT_DATA_BITS.FT_BITS_7; if (port.DataBits == 8) { dataBits = FTDI.FT_DATA_BITS.FT_BITS_8; } // StopBits byte stopBits = FTDI.FT_STOP_BITS.FT_STOP_BITS_1; if (port.StopBits == StopBits.Two) { stopBits = FTDI.FT_STOP_BITS.FT_STOP_BITS_2; } // Parity byte parity = FTDI.FT_PARITY.FT_PARITY_EVEN; if (port.Parity == Parity.Odd) { parity = FTDI.FT_PARITY.FT_PARITY_ODD; } else if (port.Parity == Parity.None) { parity = FTDI.FT_PARITY.FT_PARITY_NONE; } // DataBits, StopBits, Parity ret = ftdi.SetDataCharacteristics(dataBits, stopBits, parity); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("Could not set DataCharacteristcs. FT_STATUS=" + ret + ",DataBits=FT_BITS_8,StopBits=FT_STOP_BITS_8,Parity=" + parity); } // ReadTimeout, WriteTimeout ret = ftdi.SetTimeouts((uint)port.ReadTimeout, (uint)port.WriteTimeout); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("Could not set Timeouts. FT_STATUS=" + ret + ",ReadTimeout=" + port.ReadTimeout + ",WriteTimeout=" + port.WriteTimeout); } // LatencyTimeout ret = ftdi.SetLatency((byte)this.latencyTime); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("Could not set LatencyTimeout. FT_STATUS=" + ret + ",LatencyTime=" + latencyTime); } break; } else { ftdi.Close(); } } if (!ftdi.IsOpen) { throw new InvalidOperationException("Could not found the port. portName=" + port.PortName); } }
private void AttemptConnect() { connected = false; UInt32 DeviceCount = 0; FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; // Create new instance of the FTDI device class ftdi = new FTDI(); // Determine the number of FTDI devices connected to the machine ftStatus = ftdi.GetNumberOfDevices(ref DeviceCount); // Check status if (ftStatus != FTDI.FT_STATUS.FT_OK || DeviceCount == 0) { commStat = CommStatus.NoDevice; return; } commStat = CommStatus.NoElev8; // Allocate storage for device info list FTDI.FT_DEVICE_INFO_NODE[] DeviceList = new FTDI.FT_DEVICE_INFO_NODE[DeviceCount]; try { // Populate our device list ftStatus = ftdi.GetDeviceList(DeviceList); bool FoundElev8 = false; for (int i = 0; i < DeviceCount && FoundElev8 == false; i++) { if (DeviceList[i].Type != FTDI.FT_DEVICE.FT_DEVICE_X_SERIES) { continue; } ftStatus = ftdi.OpenBySerialNumber(DeviceList[i].SerialNumber); if (ftStatus == FTDI.FT_STATUS.FT_OK) { string portName; ftdi.GetCOMPort(out portName); if (portName == null || portName == "") { ftdi.Close(); continue; } ftdi.SetBaudRate(115200); ftdi.SetDataCharacteristics(8, 1, 0); ftdi.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); txBuffer[0] = (byte)0; // Set it to MODE_None to stop it writing (reset in case it was disconnected) txBuffer[1] = (byte)0xff; // Send 0xff to the Prop to see if it replies uint written = 0; for (int j = 0; j < 10 && FoundElev8 == false; j++) // Keep pinging until it replies, or we give up { ftdi.Write(txBuffer, 2, ref written); System.Threading.Thread.Sleep(50); uint bytesAvail = 0; ftdi.GetRxBytesAvailable(ref bytesAvail); // How much data is available from the serial port? if (bytesAvail > 0) { uint bytesRead = 0; ftdi.Read(rxBuffer, 1, ref bytesRead); // If it comes back with 0xE8 it's the one we want if (bytesRead == 1 && rxBuffer[0] == 0xE8) { FoundElev8 = true; commStat = CommStatus.Connected; break; } } } if (FoundElev8) { connected = true; txBuffer[0] = 2; // MODE_Sensors written = 0; ftdi.Write(txBuffer, 1, ref written); if (ConnectionStarted != null) { ConnectionStarted(); } break; } else { ftdi.Close(); } } } } catch (Exception) { return; } }
public override bool Connect() { var foundDevices = new Dictionary <string, ArccDevice>(); try { var myFtdiDevice = new FTDI(); uint ftdiDeviceCount = 0; var ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount); if (ftStatus != FTDI.FT_STATUS.FT_OK) { return(false); } var ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList); if (ftStatus != FTDI.FT_STATUS.FT_OK) { return(false); } for (var i = 0; i < ftdiDeviceList.Length; i++) { const string descriptionPattern = "ARCC"; if (!ftdiDeviceList[i].Description.StartsWith(descriptionPattern)) { continue; } ftStatus = myFtdiDevice.OpenByIndex((uint)i); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } string comPort; var chipId = 0; ftStatus = myFtdiDevice.GetCOMPort(out comPort); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } myFtdiDevice.Close(); FTChipID.ChipID.GetDeviceChipID(i, ref chipId); var id = DevicePrefix + ":" + chipId.ToString("X"); var device = new ArccDevice(id, comPort); foundDevices.Add(id, device); } } catch (Exception) { return(false); } foreach (var arccDevice in foundDevices) { if (arccDevice.Value.Connect()) { Devices.Add(arccDevice.Key, arccDevice.Value); } } return(true); }
private void AttemptConnect() { connected = false; UInt32 DeviceCount = 0; FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; // Create new instance of the FTDI device class ftdi = new FTDI(); // Determine the number of FTDI devices connected to the machine ftStatus = ftdi.GetNumberOfDevices(ref DeviceCount); // Check status if (ftStatus != FTDI.FT_STATUS.FT_OK || DeviceCount == 0) { commStat = CommStatus.NoDevice; return; } commStat = CommStatus.NoElev8; // Allocate storage for device info list FTDI.FT_DEVICE_INFO_NODE[] DeviceList = new FTDI.FT_DEVICE_INFO_NODE[DeviceCount]; try { // Populate our device list ftStatus = ftdi.GetDeviceList(DeviceList); bool FoundElev8 = false; for (int i = 0; i < DeviceCount && FoundElev8 == false; i++) { if (DeviceList[i].Type != FTDI.FT_DEVICE.FT_DEVICE_X_SERIES) { continue; } for (int baud = 0; baud < 2; baud++) { ftStatus = ftdi.OpenBySerialNumber(DeviceList[i].SerialNumber); if (ftStatus == FTDI.FT_STATUS.FT_OK) { string portName; ftdi.GetCOMPort(out portName); if (portName == null || portName == "") { ftdi.Close(); continue; } if (baud == 0) { ftdi.SetBaudRate(115200); // try this first } else { ftdi.SetBaudRate(57600); // then try this (xbee) } ftdi.SetDataCharacteristics(8, 1, 0); ftdi.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); txBuffer[0] = (byte)'E'; txBuffer[1] = (byte)'l'; txBuffer[2] = (byte)'v'; txBuffer[3] = (byte)'8'; uint written = 0; for (int j = 0; j < 10 && FoundElev8 == false && !quit; j++) // Keep pinging until it replies, or we give up { ftdi.Write(txBuffer, 4, ref written); System.Threading.Thread.Sleep(50); uint bytesAvail = 0; ftdi.GetRxBytesAvailable(ref bytesAvail); // How much data is available from the serial port? if (bytesAvail > 0) { int TestVal = 0; while (bytesAvail > 0 && !quit) { uint bytesRead = 0; ftdi.Read(rxBuffer, 1, ref bytesRead); if (bytesRead == 1) { TestVal = (TestVal << 8) | rxBuffer[0]; if (TestVal == (int)(('E' << 0) | ('l' << 8) | ('v' << 16) | ('8' << 24))) { FoundElev8 = true; commStat = CommStatus.Connected; break; } } if (bytesRead == 0) { break; } } } } if (FoundElev8) { connected = true; if (ConnectionStarted != null) { ConnectionStarted(); } break; } else { ftdi.Close(); } } } } } catch (Exception) { return; } }
static void Main(string[] args) { FTDI ftdi = new FTDI(); MAX7219 Display; uint devcount = 0; ftdi.GetNumberOfDevices(ref devcount); if (devcount > 0) { byte[] TransferBuffer = new byte[88]; uint NumBytesToTransfer; uint NumBytesTransfered = 0; Display = new MAX7219(TransferBuffer, WriteOut); //FTDI AN_108 3.8 Clock Divisor uint dwClockDivisor = 29; //Value of clock divisor, SCL Frequency = 60/((1+29)*2) (MHz) = 1Mhz FTDI.FT_DEVICE_INFO_NODE[] devices = new FTDI.FT_DEVICE_INFO_NODE[devcount]; string Buffer; FTDI.FT_STATUS s = ftdi.GetDeviceList(devices); for (uint ix = 0; ix < devcount; ix++) { ftdi.OpenBySerialNumber(devices[ix].SerialNumber); ftdi.GetCOMPort(out Buffer); Console.WriteLine(Buffer); ftdi.GetDescription(out Buffer); Console.WriteLine(Buffer); //FTDI Set Mode MPSSE s = ftdi.SetBitMode(0, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET); s |= ftdi.SetBitMode(0, FTDI.FT_BIT_MODES.FT_BIT_MODE_MPSSE); if (s != FTDI.FT_STATUS.FT_OK) { Console.WriteLine("Fehler SetBitMode"); ftdi.Close(); return; } //FTDI Sync MPSSE (Check) FTDI_AN114 Page 10 if (Sync_MPSSE(ref ftdi, TransferBuffer) != FTDI.FT_STATUS.FT_OK) { Console.WriteLine("Fehler Sync MPSSE"); ftdi.Close(); return; } //Init FTDI SPI See FTDI AN_108 NumBytesToTransfer = 0; TransferBuffer[NumBytesToTransfer++] = 0x8a; // Disable Clock divide /5 TransferBuffer[NumBytesToTransfer++] = 0x97; // Disable adaptiv clockink TransferBuffer[NumBytesToTransfer++] = 0x8d; // Disables 3 phase data clocking // I think is not nesacery //TransferBuffer[NumBytesToTransfer++] = 0x80; //TransferBuffer[NumBytesToTransfer++] = 0x08; //TransferBuffer[NumBytesToTransfer++] = 0x0b; TransferBuffer[NumBytesToTransfer++] = 0x86; //3.8 Clock Divisor TransferBuffer[NumBytesToTransfer++] = (byte)(dwClockDivisor & 0xff); TransferBuffer[NumBytesToTransfer++] = (byte)(dwClockDivisor >> 8); s = ftdi.Write(TransferBuffer, NumBytesToTransfer, ref NumBytesTransfered); NumBytesToTransfer = 0; Thread.Sleep(20); TransferBuffer[NumBytesToTransfer++] = 0x85; // Disable loopback s |= ftdi.Write(TransferBuffer, NumBytesToTransfer, ref NumBytesTransfered); NumBytesToTransfer = 0; if (s != FTDI.FT_STATUS.FT_OK) { Console.WriteLine("SPI Init Fehler"); ftdi.Close(); return; } Console.WriteLine("SPI Init OK"); Console.WriteLine("Press ESC to Exit"); //Init 7219 s = ftdi.Write(TransferBuffer, Display.Init(8), ref NumBytesTransfered); UInt32 count = 0; while (true) { //Data s |= ftdi.Write(TransferBuffer, Display.WriteDec(count, (byte)(1 << ((byte)(count++ % 8)))), ref NumBytesTransfered); Console.WriteLine("SPI {0} Bytes Write", NumBytesTransfered); Thread.Sleep(100); if (Console.KeyAvailable && (Console.ReadKey(true)).Key == ConsoleKey.Escape) { break; } } s |= ftdi.Write(TransferBuffer, Display.Clr(), ref NumBytesTransfered); if (s != FTDI.FT_STATUS.FT_OK) { Console.WriteLine("SPI Fehler Write Data"); ftdi.Close(); return; } ftdi.Close(); } } else { Console.WriteLine("Kein FTDI gefunden :-("); } }
//finds the ftdi port private string getFTDIPort() { FTDI ftdi = new FTDI(); FTDI.FT_STATUS state; uint deviceCount = 0; state = ftdi.GetNumberOfDevices(ref deviceCount); if (state != FTDI.FT_STATUS.FT_OK) { return(null); } FTDI.FT_DEVICE_INFO_NODE[] deviceNodes = new FTDI.FT_DEVICE_INFO_NODE[deviceCount]; state = ftdi.GetDeviceList(deviceNodes); if (state != FTDI.FT_STATUS.FT_OK) { return(null); } string port = null; foreach (FTDI.FT_DEVICE_INFO_NODE node in deviceNodes) { if (node.Type == FTDI.FT_DEVICE.FT_DEVICE_2232) { //Dieses Gerät hat 2 serielle Anschlüsse. Wir brauchen den Typ B. if (node.Description.EndsWith("B")) { state = ftdi.OpenBySerialNumber(node.SerialNumber); if (state != FTDI.FT_STATUS.FT_OK) { continue; } String tmpPort; state = ftdi.GetCOMPort(out tmpPort); if (state != FTDI.FT_STATUS.FT_OK) { Trace.WriteLine("Failed to get COM-Port (error " + state.ToString() + ")"); ftdi.Close(); continue; } if (tmpPort == null || tmpPort.Length == 0) { Trace.WriteLine(string.Format("Failed to get COM-Port for device {0}.", node.SerialNumber)); ftdi.Close(); continue; } FTDI.FT2232_EEPROM_STRUCTURE eepromData = new FTDI.FT2232_EEPROM_STRUCTURE(); try { state = ftdi.ReadFT2232EEPROM(eepromData); } catch (Exception) { Trace.WriteLine("Exception thrown when calling ReadFT2232EEPROM"); } if (state != FTDI.FT_STATUS.FT_OK) { Trace.WriteLine("Failed to read device EEPROM (error " + state.ToString() + ")"); ftdi.Close(); continue; } Debug.WriteLine(port); ftdi.Close(); if (!eepromData.Manufacturer.Equals("EnOcean GmbH") && !eepromData.Manufacturer.Equals("Viessmann") && !eepromData.Manufacturer.Equals("Eltako GmbH")) { Trace.WriteLine(String.Format("Wrong Manufacturer {0}", eepromData.Manufacturer)); continue; } if (tmpPort != null) { port = tmpPort; break; } } } else if (node.Type == FTDI.FT_DEVICE.FT_DEVICE_232R) { state = ftdi.OpenBySerialNumber(node.SerialNumber); if (state != FTDI.FT_STATUS.FT_OK) { continue; } String tmpPort; state = ftdi.GetCOMPort(out tmpPort); if (state != FTDI.FT_STATUS.FT_OK) { Trace.WriteLine("Failed to get COM-Port (error " + state.ToString() + ")"); ftdi.Close(); continue; } if (tmpPort == null || tmpPort.Length == 0) { Trace.WriteLine(string.Format("Failed to get COM-Port for device {0}.", node.SerialNumber)); ftdi.Close(); continue; } FTDI.FT232R_EEPROM_STRUCTURE eepromData = new FTDI.FT232R_EEPROM_STRUCTURE(); try { state = ftdi.ReadFT232REEPROM(eepromData); } catch (Exception) { Trace.WriteLine("Exception thrown when calling ReadFT232REEPROM"); } if (state != FTDI.FT_STATUS.FT_OK) { Trace.WriteLine("Failed to read device EEPROM (error " + state.ToString() + ")"); ftdi.Close(); continue; } ftdi.Close(); if (!eepromData.Manufacturer.Equals("EnOcean GmbH") && !eepromData.Manufacturer.Equals("Viessmann") && !eepromData.Manufacturer.Equals("Eltako GmbH")) { Trace.WriteLine(String.Format("Wrong Manufacturer {0}", eepromData.Manufacturer)); continue; } if (tmpPort != null) { port = tmpPort; break; } } } return(port); }