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); }
/// <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 unique, 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); }
static void showOne() { FTDI ftdi_handle = new FTDI(); FTDI.FT_STATUS ft_status; uint devcount = 0; ft_status = ftdi_handle.GetNumberOfDevices(ref devcount); if (ft_status != FTDI.FT_STATUS.FT_OK) { Console.WriteLine("Error getting number of devices."); Console.ReadKey(); return; } Console.WriteLine("FTDI devices connected: {0}", devcount); if (devcount == 0) { return; } FTDI.FT_DEVICE_INFO_NODE[] ft_dev_list = new FTDI.FT_DEVICE_INFO_NODE[devcount]; ft_status = ftdi_handle.GetDeviceList(ft_dev_list); var serial_numbers = ft_dev_list.Select(h => h.SerialNumber); foreach (string st in serial_numbers) { if (st != null && st.CompareTo("") != 0) { Console.WriteLine("Serial: {0}", st); } } string def_serial = serial_numbers.FirstOrDefault(); if (def_serial == null || def_serial.CompareTo("") == 0) { Console.WriteLine("Error getting device serial"); Console.ReadKey(); return; } ft_status = ftdi_handle.OpenBySerialNumber(def_serial); ft_status = ftdi_handle.SetBaudRate(1); ft_status = ftdi_handle.SetBitMode(0x07, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG); uint buf = 0; int numberOfBytes; byte[] outb = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; int idx = 0; do { idx = (int)Char.GetNumericValue(Console.ReadKey().KeyChar); ftdi_handle.Write(outb, idx + 1, ref buf); } while (idx < 8); ftdi_handle.Close(); }
/// <summary> /// Returns the index of the first available FTDI 232H device found in the system /// </summary> /// <returns></returns> static public int GetFirstDevIndex() { FTDI ftdi = new FTDI(); int count = 10; FTDI.FT_DEVICE_INFO_NODE[] devlist = new FTDI.FT_DEVICE_INFO_NODE[count]; FTDI.FT_STATUS status = ftdi.GetDeviceList(devlist); if (status != FTDI.FT_STATUS.FT_OK) { throw new FTI2CException("Problem getting FTDI device list"); } int index = -1; for (int i = 0; i < count; i++) { FTDI.FT_DEVICE_INFO_NODE devinfo = devlist[i]; if (devinfo != null) { if (devinfo.Type == FTD2XX_NET.FTDI.FT_DEVICE.FT_DEVICE_232H) { index = i; FTDI.FT_DEVICE device_type = devinfo.Type; break; } } } return(index); }
public MotorControl() { frontFTDI = new FTDI(); rearFTDI = new FTDI(); PropertyManager.i.Load("Hardware"); PropertyManager.i.Load("MotorControl"); frontFTDI.OpenBySerialNumber(PropertyManager.i.GetStringValue("Hardware", "FrontMotorSerialNumber")); rearFTDI.OpenBySerialNumber(PropertyManager.i.GetStringValue("Hardware", "RearMotorSerialNumber")); Lx = (byte)PropertyManager.i.GetIntValue("MotorControl", "Lx"); Ly = (byte)PropertyManager.i.GetIntValue("MotorControl", "Ly"); if (!frontFTDI.IsOpen) { throw new Exception("Could Not Connect to Front Motor Controller"); } if (!rearFTDI.IsOpen) { throw new Exception("Could Not Connect to Rear Motor Controller"); } frontFTDI.SetBaudRate(38400); rearFTDI.SetBaudRate(38400); frontFTDI.SetTimeouts(100, 1000); rearFTDI.SetTimeouts(100, 1000); running = false; }
void UpdatePorts() { FTDI ftdi = new FTDI(); FT_STATUS status; uint numDevices = 0; status = ftdi.GetNumberOfDevices(ref numDevices); // filter valid devices // opened devices can not be displayed List <string> names = new List <string>((int)numDevices); List <FT_DEVICE_INFO_NODE> validDevices = new List <FT_DEVICE_INFO_NODE>((int)numDevices); if (numDevices > 0) { FT_DEVICE_INFO_NODE[] devices = new FT_DEVICE_INFO_NODE[numDevices]; ftdi.GetDeviceList(devices); foreach (var d in devices) { if ((d.Type != FT_DEVICE.FT_DEVICE_UNKNOWN) && (!String.IsNullOrEmpty(d.SerialNumber))) { validDevices.Add(d); names.Add(String.Format("{0} ({1})", d.SerialNumber, d.Description)); } } } _Devices = validDevices.ToArray(); PortNames = names.ToArray(); }
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 static void CheckStatus(object state) { 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 // 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++) { if (ftdiDeviceList[i].SerialNumber == "A99C59XB") { Console.WriteLine("Device detected"); } } } }
private void Disconnect() { lock (FTDILocker) { if (FTDI != null) { try { SendUpdate(0); } catch { } if (FTDI.IsOpen) { try { FTDI.ErrorHandler(FTDI.Close()); } catch (Exception) { Log.Exception("A exception occured when closing the FTDI chip {0}.".Build(SerialNumber)); } } FTDI = null; Log.Write("Connection to FTDI chip {0} closed.".Build(SerialNumber)); } } }
void SetDeviceParameter(FTDI dev) { var ftStatus = dev.SetBaudRate(3000000); if (ftStatus != FTDI.FT_STATUS.FT_OK) { throw new Exception("Failed to open device (error " + ftStatus.ToString() + ")"); } 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) { throw new Exception("Failed to open device (error " + ftStatus.ToString() + ")"); } ftStatus = dev.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0x11, 0x13); if (ftStatus != FTDI.FT_STATUS.FT_OK) { throw new Exception("Failed to open device (error " + ftStatus.ToString() + ")"); } ftStatus = dev.SetTimeouts(5000, 0); if (ftStatus != FTDI.FT_STATUS.FT_OK) { throw new Exception("Failed to open device (error " + ftStatus.ToString() + ")"); } }
public static FTDI.FT_STATUS ftByteRead(ref byte data, FTDI myFtdiDevice) { FTDI.FT_STATUS status = FTDI.FT_STATUS.FT_OK; int bit = 0; int mask = 0x01; status = ftBitWrite(DCLK, 0, myFtdiDevice); if (status != FTDI.FT_STATUS.FT_OK) { return(status); } for (int i = 0; i < 8; i++) { status = ftBitWrite(DCLK, 1, myFtdiDevice); if (status != FTDI.FT_STATUS.FT_OK) { return(status); } status = ftBitRead(DATAOUT, ref bit, myFtdiDevice); if (bit != 0) { data |= (byte)(mask << i); } status = ftBitWrite(DCLK, 0, myFtdiDevice); if (status != FTDI.FT_STATUS.FT_OK) { return(status); } } return(status); }
private int FTDICheckDriver() { //uint driver = 0; try { if (ftdi == null) { ftdi = new FTDI(); } if (ftdi == null) { return(-1); } return(1); /* * if (serial != "") * ftdi.OpenBySerialNumber(serial); * ftStatus = ftdi.GetDriverVersion(ref driver); * ftdi.Close(); * if (ftStatus != FTDI.FT_STATUS.FT_OK) * return 0; * return (int)driver; */ } catch (Exception) { return(-1); } }
public FT2232HardwareOutput(string channelName, uint baudrate, int bufferSize = 10240) { _channelName = channelName; _baudrate = baudrate; _bufferSize = bufferSize; _channel = OpenChannel(_channelName, _baudrate); }
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 RelayBoardDriver() { horn_timer = new Timer(); horn_timer.Interval = 1000; tsk = new TaskFactory(); //try to load relay board usb drivers try{ myFtdiDevice = new FTDI(); if (myFtdiDevice != null) { RelayBoardMessage = "Online"; log.Debug("USB board found and ready."); } else { RelayBoardMessage = "Offline"; log.Debug("USB board not found or not ready"); } } catch (Exception ex) { log.Error(ex); RelayBoardMessage = ex.Message; } RelayConnection = ConnectToRelayBoard(); }
public override void Close() { isInitialized = false; if (ftdi != null && ftdi.IsOpen) { // バッファをクリア ClearBuffer(); // ポートを閉じる FT_STATUS ret = ftdi.ResetPort(); if (ret == FT_STATUS.FT_OK) { ret = ftdi.Close(); if (ret != FT_STATUS.FT_OK) { throw new InvalidOperationException("close failure."); } } else { throw new InvalidOperationException("reset failure."); } ftdi = null; } }
public Device() // выполнять базовый констр в спец констре. { data = new byte[8]; buffer = new byte[200]; ftdi = new FTDI(); devCount = 0; locker = new object(); }
public static void WriteEEPROMLong(FTDI dev, uint address, uint data) { ushort eevalh = (ushort)(data >> 16); ushort eevall = (ushort)(data & 0xffff); dev.WriteEEPROMLocation(address, eevalh); dev.WriteEEPROMLocation(address + 0x02, eevall); }
public static FTDI.FT_DEVICE_INFO_NODE[] GetDevices() { FTDI ftdi = new FTDI(); UInt32 deviceCnt = GetNumberOfDevices(ftdi); FTDI.FT_DEVICE_INFO_NODE[] deviceList = GetDeviceList(ftdi, deviceCnt); return(deviceList); }
public CommunicationInterface() { mFTDIDevice = new FTDI(this.DisplayFTDIErrorMessage, this.DisplayFTDIWarningMessage); mConsumeTransmitEcho = true; mQueuedEvents = new Queue <EventHolder>(); mQueuedEventTriggerMutex = new Object(); }
public static String DeviceListInfo() { FTDI ftdi = new FTDI(); UInt32 deviceCnt = GetNumberOfDevices(ftdi); FTDI.FT_DEVICE_INFO_NODE[] deviceList = GetDeviceList(ftdi, deviceCnt); return(DeviceListDebugOut(deviceList)); }
public void readRom() { keyProMap.Clear(); content.Clear(); 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) { content.Append("Number of FTDI devices: " + ftdiDeviceCount.ToString() + "\n"); } else { content.Append("Failed to get number of devices (error " + ftStatus.ToString() + ")" + "\n"); return; } // If no devices available, return if (ftdiDeviceCount == 0) { // Wait for a key press content.Append("Failed to get number of devices (error " + ftStatus.ToString() + ")" + "\n"); 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); int numDevices = 0, ChipID = 0; FTChipID.ChipID.GetNumDevices(ref numDevices); if (ftStatus == FTDI.FT_STATUS.FT_OK) { for (int i = 0; i < ftdiDeviceCount; i++) { FTChipID.ChipID.GetDeviceChipID(i, ref ChipID); keyProMap.Add("0x" + ChipID.ToString("X"), ftdiDeviceList[i]); content.Append("Device Index: " + i.ToString() + "\n"); content.Append("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags) + "\n"); content.Append("Type: " + ftdiDeviceList[i].Type.ToString() + "\n"); content.Append("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID) + "\n"); content.Append("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId) + "\n"); content.Append("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString() + "\n"); content.Append("Description: " + ftdiDeviceList[i].Description.ToString() + "\n"); content.Append("\n"); } } }
public FlowMeter() { _flowmeter = new FTDI(); if (_flowmeter.IsOpen) { _flowmeter.Close(); } _calibrationMode = false; }
public FTDIDevice() { bufferIn = new List <byte>(); incomingMessages = new List <Message>(); COMPortMutex = new Mutex(); serialDataMutex = new Mutex(); valuesMutex = new Mutex(); FtdiDevice = new FTDI(); }
public Dmx512Controller() { _shouldBeRunning = false; _buffer = new byte[513]; // 513 is not a typo, all the examples show using a 513 length. Maybe the first byte is reserved in the spec? _ftdi = new FTDI(); DataRefreshInterval = TimeSpan.FromMilliseconds(1); }
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("CAM86")) { 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; }
public FTDIInterface(int readTimeout, int writeTimeout, SemaphoreSlim locker) { Locker = locker; _ftdi = new FTDI(); _portUpdater = new TaskHolder(); _portUpdater.RegisterAsync(c => updateAwailablePortsLoop(c)).GetAwaiter().GetResult(); Pipe = new FTDIPipe(_ftdi, readTimeout, writeTimeout); openStateCheckingAsyncLoop(); }
private static void Read(FTDI source, byte[] bytes) { var numBytesAvailable = 0u; var result = source.Read(bytes, (uint)bytes.Length, ref numBytesAvailable); if (result != FTDI.FT_STATUS.FT_OK) { throw new InvalidOperationException("Failed to read data frame from the FTDI device."); } }
private static void Write(FTDI source, string command) { var bytesWritten = 0u; var result = source.Write(command, command.Length, ref bytesWritten); if (result != FTDI.FT_STATUS.FT_OK) { throw new InvalidOperationException("Unable to write command to the FTDI device."); } }
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."); } }
static void Main(string[] args) { FTDI device = new FTDI(); IntPtr FThandle ; int return_val = 0; uint channels = 0; uint i2c_status = 0; bool is_connected = false; int num_channels = 10; byte interrupt = 0; UInt32 size_transfered =0; num_channels = device.Init(channels); byte[] buffer = {0,0,0,0,0,1,0,0}; device.setGPIOdir(1, 0); //Pin C1 // 1 will write //device.setGPIOdir(0, 0); // 0 will read //init code // channels = device.readGPIO( ref interrupt); i2c_status = device.I2Cwrite(0x34, 8,buffer , ref size_transfered,I2C_TRANSFER_OPTIONS_START_BIT); while(true) { //i2c_status = device.I2Cwrite(0x34, 8, buffer, ref size_transfered, I2C_TRANSFER_OPTIONS_START_BIT); device.I2Cread(0x34, 8, buffer, ref size_transfered, I2C_TRANSFER_OPTIONS_START_BIT); Thread.Sleep(1); channels = device.readGPIO(ref interrupt); //Thread.Sleep(1); //channels = device.clearGPIO(1); //Thread.Sleep(1); if (interrupt == 0) { //i2c_status = device.I2Cwrite(0x34, 8, buffer, ref size_transfered, I2C_TRANSFER_OPTIONS_START_BIT); //Thread.Sleep(10); device.I2Cread(0x34, 8, buffer, ref size_transfered, I2C_TRANSFER_OPTIONS_START_BIT); // Thread.Sleep(10); } } Console.ReadLine(); }