public void OpenDevice() { ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount); FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList); ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber.ToString()); 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); }
private void button2_Click(object sender, EventArgs e) { if (deviceIndex >= 0) { ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[deviceIndex].SerialNumber); if (ftStatus != FTDI.FT_STATUS.FT_OK) { // Wait for a key press textBox1.Text += "Failed to open device (error " + ftStatus.ToString() + ")\r\n"; return; } else { textBox1.Text += "Device opened !!!\r\n"; } } ftStatus = myFtdiDevice.SetBitMode(0x00, 0x40); if (ftStatus != FTDI.FT_STATUS.FT_OK) { // Wait for a key press textBox1.Text += "Failed to set bit mode (error " + ftStatus.ToString() + ")\r\n"; return; } else { textBox1.Text += "Bit mode = 0x40 !!!\r\n"; } }
private void _connect_Click(object sender, EventArgs e) { if (deviceList == null) { ShowError("No device to open"); return; } if (deviceList.Length == 0) { ShowError("No device to open"); return; } if (ftdi.IsOpen) { ShowWarning("Device is connected"); return; } var ftStatus = ftdi.OpenBySerialNumber(deviceList[_device.SelectedIndex].SerialNumber); if (ftStatus != FTDI.FT_STATUS.FT_OK) { ShowError("Failed to open device (error " + ftStatus.ToString() + ")"); return; } _statusInfo.Text = string.Format("Connected to {0}", deviceList[_device.SelectedIndex].SerialNumber); }
public FtdiDevice(string portName) { var ftStatus = ftdi.OpenBySerialNumber(portName); if (ftStatus != FTDI.FT_STATUS.FT_OK) { throw new Exception("Failed to open device (error " + ftStatus.ToString() + ")"); } if (!ftdi.IsOpen) { throw new Exception("Device is not open"); } ftStatus = SetDeviceProperty(62500 , FTDI.FT_DATA_BITS.FT_BITS_8 , FTDI.FT_STOP_BITS.FT_STOP_BITS_1 , FTDI.FT_PARITY.FT_PARITY_NONE , FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE , 0 , 0 , 1000 , 0 , false , false); if (ftStatus != FTDI.FT_STATUS.FT_OK) { throw new Exception("Failed to set data characteristics (error " + ftStatus.ToString() + ")"); } }
public void Open() { Console.WriteLine("Open Port"); FT_STATUS status; status = _Ftdi.OpenBySerialNumber(_PortName); if (status == FT_STATUS.FT_OK) { status = _Ftdi.SetLatency(4); } if (status == FT_STATUS.FT_OK) { status = _Ftdi.SetBaudRate(3000000); } if (status == FT_STATUS.FT_OK) { status = _Ftdi.InTransferSize(64); } if (status == FT_STATUS.FT_OK) { status = _Ftdi.SetEventNotification(FT_EVENTS.FT_EVENT_RXCHAR, _WaitHandle); } if (status != FT_STATUS.FT_OK) { throw new Exception("Error opening device " + _PortName); } }
/// <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); }
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; }
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(); }
private void FT232_Init() { ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount); if (ftStatus != FTDI.FT_STATUS.FT_OK) { MessageBox.Show("Failed to get number of devices (error " + ftStatus.ToString() + ")"); } if (ftdiDeviceCount == 0) { MessageBox.Show("无可用的FTDI设备 (error " + ftStatus.ToString() + ")"); } // 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) { label1.Text = "Type:" + ftdiDeviceList[0].Type.ToString(); label2.Text = "Location ID: " + String.Format("{0:x}", ftdiDeviceList[0].LocId); label3.Text = "Serial Number: " + ftdiDeviceList[0].SerialNumber.ToString(); label4.Text = "Description: " + ftdiDeviceList[0].Description.ToString(); } ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber); OpenFlag = ftStatus; if (ftStatus != FTDI.FT_STATUS.FT_OK) { MessageBox.Show("打开设备失败 (error " + ftStatus.ToString() + ")"); } ftStatus = myFtdiDevice.SetBaudRate(921600); if (ftStatus != FTDI.FT_STATUS.FT_OK) { MessageBox.Show("波特率设置失败 (error " + ftStatus.ToString() + ")"); } ftStatus = myFtdiDevice.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) { MessageBox.Show("数据特征设置失败 (error " + ftStatus.ToString() + ")"); } ftStatus = myFtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0x11, 0x13); if (ftStatus != FTDI.FT_STATUS.FT_OK) { MessageBox.Show("流控制设置失败 (error " + ftStatus.ToString() + ")"); } ftStatus = myFtdiDevice.SetTimeouts(5000, 0); if (ftStatus != FTDI.FT_STATUS.FT_OK) { MessageBox.Show("超时时间设置失败 (error " + ftStatus.ToString() + ")"); } uint dwEventMask = FTDI.FT_EVENTS.FT_EVENT_RXCHAR; ftStatus = myFtdiDevice.SetEventNotification(dwEventMask, eventWait); if (ftStatus != FTDI.FT_STATUS.FT_OK) { MessageBox.Show("事件响应器设置失败 (error " + ftStatus.ToString() + ")"); } }
private void open(string serialNumber) { lock (_lock) { var ftStatus = ftdi.OpenBySerialNumber(serialNumber); if (ftStatus == FTDI.FT_STATUS.FT_OK) { return; } var errMsg = "Failed to open device using serial " + serialNumber + "(error " + ftStatus + ")"; throw new FtdiException(errMsg); } }
private void open(string serialNumber) { lock (_lock) { FTDI.FT_STATUS ftStatus = ftdi.OpenBySerialNumber(serialNumber); if (ftStatus == FTDI.FT_STATUS.FT_OK) { return; } String errMsg = "Failed to open device (error " + ftStatus.ToString() + ")"; throw new FtdiException(errMsg); } }
/// <summary> /// Find the FDTI chip, connect, set baud to 9600, set sync bit-bang mode /// </summary> /// <returns></returns> public bool connect() { // 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 { Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")"); return(false); } if (ftdiDeviceCount == 0) { Console.WriteLine("Relay board not found, please try again"); return(false); } else { // 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); // Open first device in our list by serial number ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber); if (ftStatus != FTDI.FT_STATUS.FT_OK) { Console.WriteLine("Error connecting to relay board"); return(false); } // Set Baud rate to 9600 ftStatus = myFtdiDevice.SetBaudRate(9600); // Set FT245RL to synchronous bit-bang mode, used on sainsmart relay board myFtdiDevice.SetBitMode(0xFF, FTD2XX_NET.FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG); // Switch off all the relays myFtdiDevice.Write(startup, 1, ref bytesToSend); return(true); } }
// returns true on success static bool openSerialPort(TcpClient conn, string snToConnect) { NetworkStream ns = conn.GetStream(); ns.WriteTimeout = 10; ns.ReadTimeout = 10; byte[] msg; FTDI clientDevice = new FTDI(); FTDI.FT_STATUS ftdiRet = clientDevice.OpenBySerialNumber(snToConnect); ftdiRet |= clientDevice.SetBaudRate(1250000); ftdiRet |= clientDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_2, FTDI.FT_PARITY.FT_PARITY_ODD); ftdiRet |= clientDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); ftdiRet |= clientDevice.SetTimeouts(8000, 100); ftdiRet |= clientDevice.InTransferSize(65536); ftdiRet |= clientDevice.SetDTR(true); if (ftdiRet != FTDI.FT_STATUS.FT_OK) { //throw new IOException("Failed to open FTDI device"); Console.WriteLine("ERR: Failed to open FTDI device\n"); msg = ASCIIEncoding.ASCII.GetBytes("ERR: Failed to open FTDI device\n"); ns.Write(msg, 0, msg.Length); ns.Close(); conn.Close(); return(false); } string desc = "X", sn = "X"; clientDevice.GetDescription(out desc); clientDevice.GetSerialNumber(out sn); Console.WriteLine("OK: Opened FTDI device {0}-{1}", desc, sn); msg = ASCIIEncoding.ASCII.GetBytes("OK: Opened:" + snToConnect + "\n"); ns.Write(msg, 0, msg.Length); CancellationTokenSource ct = new CancellationTokenSource(); Thread deviceThread = new Thread((ParameterizedThreadStart)doServer); deviceThreads[snToConnect] = new Tuple <Thread, CancellationTokenSource>(deviceThread, ct); Tuple <FTDI, TcpClient, CancellationToken> threadArg = new Tuple <FTDI, TcpClient, CancellationToken>(clientDevice, conn, ct.Token); deviceThread.IsBackground = true; deviceThread.Start(threadArg); return(true); }
public void connect(String serialNo) { if (!isOpen()) { ftStatus = _modbusMaster.OpenBySerialNumber(serialNo); ftStatus |= _modbusMaster.SetBaudRate(Constants.modbus_baudrate); ftStatus |= _modbusMaster.SetDataCharacteristics(Constants.modbus_databit, Constants.modbus_stopbit, Constants.modbus_parity); ftStatus |= _modbusMaster.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); ftStatus |= _modbusMaster.SetTimeouts(1000, 1000); if (ftStatus != FTDI.FT_STATUS.FT_OK) { _modbusMaster.Close(); throw new System.Exception("Could not open ModBus device with serial number " + Constants.modbus_serial); } } }
/// <summary> /// Find the FDTI chip, connect, set baud to 9600, set sync bit-bang mode /// </summary> /// <returns></returns> public static void Initialize(bool force = false) { if (initialized && !force) { return; } // 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); } else { throw new RelayBoardException("Failed to get number of devices (error " + ftStatus + ")"); } if (ftdiDeviceCount == 0) { throw new RelayBoardException("Relay board not found, try:\r\nchecking connections\r\nusing without a USB hub\r\nusing a powered USB hub"); } // 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); // Open first device in our list by serial number ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber); if (ftStatus != FTDI.FT_STATUS.FT_OK) { throw new RelayBoardException("The relay board is reporting an error: " + Enum.GetName(typeof(FTDI.FT_STATUS), ftStatus)); } // Set Baud rate to 9600 ftStatus = myFtdiDevice.SetBaudRate(9600); // Set FT245RL to synchronous bit-bang mode, used on sainsmart relay board myFtdiDevice.SetBitMode(0xFF, FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG); // Switch off all the relays myFtdiDevice.Write(startup, bytesToSend, ref bytesToSend); initialized = true; }
}/// <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 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"); }
private void Connect() { lock (FTDILocker) { if (FTDI != null) { Disconnect(); } if (SerialNumber.IsNullOrWhiteSpace()) { Log.Exception("The SerialNumber has not been set for the FT245RBitbangController named {0}. Cant connect to device.".Build(Name)); return; } FTDI = new FTDI(); //Try to open the device try { FTDI.ErrorHandler(FTDI.OpenBySerialNumber(SerialNumber)); } catch (Exception E) { Log.Exception("Could not open the connection to FTDI chip with serial number {0}.".Build(SerialNumber), E); FTDI = null; return; } // Set FT245RL to synchronous bit-bang mode, used on sainsmart relay board try { FTDI.ErrorHandler(FTDI.SetBitMode(0xFF, FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG)); } catch (Exception E) { Log.Exception("Could set the bitmode to bitbang for FTDI chip with serial number {0}.".Build(SerialNumber), E); Disconnect(); FTDI = null; return; } Log.Write("Connection to FTDI chip {0} established.".Build(SerialNumber)); } }
private void GetDeviceThread() { while (_shouldBeRunning) { while (_shouldBeRunning && !_ftdi.IsOpen) { UInt32 deviceCount = 0; FTDI.FT_STATUS status = _ftdi.GetNumberOfDevices(ref deviceCount); if (status != FTDI.FT_STATUS.FT_OK) { throw new Exception("Unable to get the number of FTDI devices."); } else { FTDI.FT_DEVICE_INFO_NODE[] list = new FTDI.FT_DEVICE_INFO_NODE[deviceCount]; status = _ftdi.GetDeviceList(list); if (status != FTDI.FT_STATUS.FT_OK) { throw new Exception("Unable to obtain the device list."); } else { FTDI.FT_DEVICE_INFO_NODE match = list.FirstOrDefault(x => x.SerialNumber == SerialNumber); if (match != null) { status = _ftdi.OpenBySerialNumber(match.SerialNumber); if (status != FTDI.FT_STATUS.FT_OK) { throw new Exception("Unable to open the FTDI device!"); } InitializeDMX(); if (OnDeviceConnected != null) { OnDeviceConnected(); } } } } Thread.Sleep(TRY_TO_FIND_DEVICE_DELAY_IN_MILLISECONDS); } } }
public void loadDevice(string serialNumber) { if (!_pressureDevice.IsOpen) { try { _pressureDevice.OpenBySerialNumber(serialNumber); _pressureDevice.SetBaudRate(Constants.pressure_baudrate); _pressureDevice.SetDataCharacteristics(Constants.pressure_databits, Constants.pressure_stopbits, Constants.pressure_parity); _pressureDevice.SetTimeouts(5000, 0); _pressureDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); } catch (Exception e) { Console.WriteLine(e.Message); } } }
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 void connect_btn_Click(object sender, EventArgs e) { try { uint devices = 0; //liczba urzadzen device = new FTDI(); //nowy obiekt typu FIDI device.GetNumberOfDevices(ref devices); FTDI.FT_DEVICE_INFO_NODE[] ftdi_devices = new FTDI.FT_DEVICE_INFO_NODE[devices]; device.GetDeviceList(ftdi_devices); device.OpenBySerialNumber(ftdi_devices[0].SerialNumber); device.SetBitMode(0xff, 1); console.AppendText("Connection successful\n"); n_steps_left.Enabled = true; n_steps_right.Enabled = true; eeprom_btn.Enabled = true; }catch { console.AppendText("Connection failure!\n"); } }
public static bool OpenDevice() //by default open device zero { if (bUSBPortIsOpen) { CloseDevice(); } FTDI.FT_STATUS S = USBPort.OpenBySerialNumber("FTF5YLE8"); if (S != FTDI.FT_STATUS.FT_OK) { return(false); } S = USBPort.SetBaudRate(500000); if (S != FTDI.FT_STATUS.FT_OK) { return(false); } S = USBPort.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0, 0); if (S != FTDI.FT_STATUS.FT_OK) { return(false); } S = USBPort.SetRTS(true); if (S != FTDI.FT_STATUS.FT_OK) { return(false); } S = USBPort.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_2, FTDI.FT_PARITY.FT_PARITY_NONE); if (S != FTDI.FT_STATUS.FT_OK) { return(false); } bUSBPortIsOpen = true; //ResetDevice(0); return(true); }
public void Open() { lock (sync) { if (messageSources == null) { messageSources = ToDecodedMessage(ToMessage(Read)).Publish(); // Only create one connection. } if (connection == null) { connection = messageSources.Connect(); } var status = ftdi.OpenBySerialNumber(serialNumber); status = this.ftdi.SetBaudRate(19200 * 2); //status = this.ftdi.SetRTS(true); status = this.ftdi.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_EVEN); status = this.ftdi.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_XON_XOFF, 17, 19); } }
public FtdiBoard(string serial) { _ftdi = new FTDI(); Serial = serial; if (_ftdi.OpenBySerialNumber(serial) != FTDI.FT_STATUS.FT_OK || _ftdi.SetBaudRate(921600) != FTDI.FT_STATUS.FT_OK || _ftdi.SetBitMode(255, 4) != FTDI.FT_STATUS.FT_OK) { throw new Exception("Can't set device params"); } WriteToDevice(0); _relays = new List <IRelay>() { new FtdiRelay(this, 0), new FtdiRelay(this, 1), new FtdiRelay(this, 2), new FtdiRelay(this, 3), }; }
private void enablebtn_Click(object sender, EventArgs e) { try { UInt32 ftdiDeviceCount = 0; device.GetNumberOfDevices(ref ftdiDeviceCount); FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[] devicelist = new FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; device.GetDeviceList(devicelist); ftstatus = device.OpenBySerialNumber(devicelist[0].SerialNumber); ftstatus = device.SetBitMode(0xff, 1); Console.WriteLine("Urzadzenie: " + ftstatus.ToString()); stepLeftbtn.Enabled = true; stepRightbtn.Enabled = true; } catch (Exception ee) { Console.WriteLine("Urzadzenie nie zostalo podlaczone!\nNacisnij [ENTER] aby zamknac program"); Console.ReadLine(); Environment.Exit(0); } }
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 void connectFTDI(string serialNumber) { FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; if (!_flowmeter.IsOpen) { ftStatus = _flowmeter.OpenBySerialNumber(serialNumber); //ftStatus |= _flowmeter.OpenByDescription("FT232R USB UART"); ftStatus |= _flowmeter.SetBaudRate(115200); _flowmeter.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE); System.Threading.Thread.Sleep(delayMsec); ftStatus |= _flowmeter.SetTimeouts(5000, 0); System.Threading.Thread.Sleep(delayMsec); ftStatus |= _flowmeter.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); if (ftStatus != FTDI.FT_STATUS.FT_OK) { if (_flowmeter.IsOpen) { _flowmeter.Close(); } throw new Exception("Could not open ProFlow"); } } }
public ReadFTDI(int deviceNumber) { myFtdiDevice = new FTDI(); // Determine the number of FTDI devices connected to the machine status |= myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount); if (ftdiDeviceCount != 0) { Thread.CurrentThread.Priority = ThreadPriority.Highest; // Get the information of the device FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; status |= myFtdiDevice.GetDeviceList(ftdiDeviceList); // Open device //status |= myFtdiDevice.OpenByDescription(ftdiDeviceList[deviceNumber].Description); status |= myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[deviceNumber].SerialNumber); status |= myFtdiDevice.ResetDevice(); deviceNo = deviceNumber.ToString(); // Set communication settings status |= myFtdiDevice.SetTimeouts(2000, 2000); status |= myFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE); status |= myFtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0); status |= myFtdiDevice.SetBaudRate(1250000); //// Stop acquiring data //wBuffer[0] = 254; //wBuffer[1] = 0; //status |= myFtdiDevice.Write(wBuffer, 2, ref writenValues); //status |= myFtdiDevice.Purge(FTDI.FT_PURGE.FT_PURGE_TX | FTDI.FT_PURGE.FT_PURGE_RX); //// Start acquiring data //wBuffer[0] = 255; //wBuffer[1] = 0; //status |= myFtdiDevice.Write(wBuffer, 2, ref writenValues); toStart = false; } else { status = FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND; } }
/// <summary> /// Attempts to open the serial port, reset the device, and set the configuration /// </summary> /// <param name="serial"></param> /// <returns></returns> private bool InitializeDevice(string serial = "") { FTDI.FT_STATUS deviceStatus; if (serial != "") { // Open the device based on serial number deviceStatus = FTDIDevice.OpenBySerialNumber(serial); if (deviceStatus != FTDI.FT_STATUS.FT_OK) { return(false); } } else { // Grab the first FTDI device found deviceStatus = FTDIDevice.OpenByIndex(0); if (deviceStatus != FTDI.FT_STATUS.FT_OK) { return(false); } } // Reset the device and check status again deviceStatus = FTDIDevice.ResetDevice(); if (deviceStatus != FTDI.FT_STATUS.FT_OK) { return(false); } // Set Baud Rate deviceStatus = FTDIDevice.SetBaudRate(921600); if (deviceStatus != FTDI.FT_STATUS.FT_OK) { return(false); } // Set Bit Bang deviceStatus = FTDIDevice.SetBitMode(255, FTDI.FT_BIT_MODES.FT_BIT_MODE_SYNC_BITBANG); if (deviceStatus != FTDI.FT_STATUS.FT_OK) { return(false); } //Read Relays Status deviceStatus = FTDIDevice.GetPinStates(ref sentBytes[0]); if ((sentBytes[0] & 2) == 0) { currentRelayStates[0] = true; } if ((sentBytes[0] & 8) == 0) { currentRelayStates[1] = true; } if ((sentBytes[0] & 32) == 0) { currentRelayStates[2] = true; } if ((sentBytes[0] & 128) == 0) { currentRelayStates[3] = true; } return(true); }