public static void Main() { IntPtr[] devices = FTDIContext.GetDeviceList(0x0403, 0x4003); if (devices.Length == 0) { Console.WriteLine("No devices found, exiting"); return; } Console.WriteLine("{0} devices found", devices.Length); FTDIContext ftdi = new FTDIContext(devices[0]); ftdi.Baudrate = 57600; ftdi.PurgeBuffers(); Console.WriteLine(ftdi); byte[] b; int ret; do { b = new byte[1]; ret = ftdi.ReadData(b, 1); Console.WriteLine("{0}", ret); Console.WriteLine("{0}", b[0].ToString()); } while (ret > 0); b = new byte[] { 0x1 }; ftdi.WriteData(b, b.Length); Console.WriteLine(ftdi); ftdi.Close(); }
/// <summary> /// init FTDI device /// </summary> public void init() { device = new FTDIContext(0x0403, 0x6001); if (device == null) { Console.WriteLine(" FTDI devive not found "); return; } device.SetBitMode(255, 4); // setting bit bang mode }
private int LibftdiCheckLibrary() { try { FTDIContext _ftdi = new FTDIContext(null); // todo remove _ftdi.Close(); return(0); } catch (FileNotFoundException) { return(-1); } catch (TypeLoadException) { return(-1); } catch (Exception) { return(-2); } }
public override void CommOpen(Bsl430NetDevice device) { try { Bsl430NetDevice _device = device; if (device == null) { _device = DefaultDevice; } if (_device == null || _device.Name == "") { throw new Bsl430NetException(461); } if (!devices.ContainsKey(_device.Name.ToLower())) { Status stat = Scan <Libftdi_Device>(out _); if (!stat.OK) { throw new Bsl430NetException(stat.Error); } } if (!devices.TryGetValue(_device.Name.ToLower(), out Libftdi_Device dev)) { throw new Bsl430NetException(462); } ftdi = new FTDIContext(dev.Vid, dev.Pid); if (ftdi == null) { throw new Bsl430NetException(510); } } catch (Exception ex) { throw new Bsl430NetException(511, ex); } }