[−][src]Struct libftd2xx::FTDI
FTDI device. Start here!
Implementations
impl FTDI
[src]
pub fn open_by_serial_number(serial_number: &str) -> Result<FTDI, Ftd2xxError>
[src]
Open the device by its serial number and initialize the handle.
Example
use libftd2xx::FTDI; FTDI::open_by_serial_number("FT59UO4C")?;
pub fn reset(&mut self) -> Result<(), Ftd2xxError>
[src]
This function sends a reset command to the device.
Example
use libftd2xx::FTDI; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.reset()?;
pub fn set_usb_parameters(
&mut self,
in_transfer_size: DWORD
) -> Result<(), Ftd2xxError>
[src]
&mut self,
in_transfer_size: DWORD
) -> Result<(), Ftd2xxError>
Set the USB request transfer size.
This function can be used to change the transfer sizes from the default
transfer size of 4096 bytes to better suit the application requirements.
Transfer sizes must be set to a multiple of 64 bytes between 64 bytes
and 64k bytes.
When [set_usb_parameters
] is called, the change comes into effect
immediately and any data that was held in the driver at the time of the
change is lost.
Example
use libftd2xx::FTDI; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.set_usb_parameters(16384)?;
[set_usb_parameters
]: : #method.set_usb_parameters
pub fn set_chars(
&mut self,
event_char: u8,
event_enable: bool,
error_char: u8,
error_enable: bool
) -> Result<(), Ftd2xxError>
[src]
&mut self,
event_char: u8,
event_enable: bool,
error_char: u8,
error_enable: bool
) -> Result<(), Ftd2xxError>
This function sets the special characters for the device.
This function allows for inserting specified characters in the data stream to represent events firing or errors occurring.
pub fn set_timeouts(
&mut self,
read_timeout: Duration,
write_timeout: Duration
) -> Result<(), Ftd2xxError>
[src]
&mut self,
read_timeout: Duration,
write_timeout: Duration
) -> Result<(), Ftd2xxError>
This function sets the read and write timeouts for the device.
Example
use libftd2xx::FTDI; use std::time::Duration; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; // Set read timeout of 5sec, write timeout of 1sec ft.set_timeouts(Duration::from_millis(5000), Duration::from_millis(1000))?;
pub fn set_latency_timer(&mut self, timer: Duration) -> Result<(), Ftd2xxError>
[src]
Set the latency timer value.
In the FT8U232AM and FT8U245AM devices, the receive buffer timeout that is used to flush remaining data from the receive buffer was fixed at 16 ms. In all other FTDI devices, this timeout is programmable and can be set at 1 ms intervals between 2ms and 255 ms. This allows the device to be better optimized for protocols requiring faster response times from short data packets.
The valid range for the latency timer is 2 to 255 milliseconds.
Example
use libftd2xx::FTDI; use std::time::Duration; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; // Set latency timer to 10 milliseconds ft.set_latency_timer(Duration::from_millis(10))?;
pub fn set_flow_control_none(&mut self) -> Result<(), Ftd2xxError>
[src]
This function disables flow control for the device.
Example
use libftd2xx::FTDI; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.set_flow_control_none()?;
pub fn set_flow_control_rts_cts(&mut self) -> Result<(), Ftd2xxError>
[src]
This function sets RTS/CTS flow control for the device.
pub fn set_flow_control_dtr_dsr(&mut self) -> Result<(), Ftd2xxError>
[src]
This function sets DTS/DSR flow control for the device.
pub fn set_flow_control_xon_xoff(
&mut self,
xon: u8,
xoff: u8
) -> Result<(), Ftd2xxError>
[src]
&mut self,
xon: u8,
xoff: u8
) -> Result<(), Ftd2xxError>
This function sets XON/XOFF flow control for the device.
Arguments
xon
- Character used to signal Xon.xoff
- Character used to signal Xoff.
pub fn set_bit_mode(
&mut self,
mask: u8,
mode: BitMode
) -> Result<(), Ftd2xxError>
[src]
&mut self,
mask: u8,
mode: BitMode
) -> Result<(), Ftd2xxError>
Enables different chip modes.
Arguments
mask
- This bit mask sets up which bits are inputs and outputs. A bit value of 0 sets the corresponding pin to an input, a bit value of 1 sets the corresponding pin to an output. In the case of CBUS Bit Bang, the upper nibble of this value controls which pins are inputs and outputs, while the lower nibble controls which of the outputs are high and low.mode
- Bitmode, see theBitMode
struct for more details.
For a description of available bit modes for the FT232R, see the application note Bit Bang Modes for the FT232R and FT245R.
For a description of available bit modes for the FT2232, see the applicationnote Bit Mode Functions for the FT2232.
For a description of Bit Bang Mode for the FT232B and FT245B, see the application note FT232B/FT245B Bit Bang Mode.
Application notes are available for download from the FTDI website.
Note that to use CBUS Bit Bang for the FT232R, the CBUS must be configured for CBUS Bit Bang in the EEPROM.
Note that to use Single Channel Synchronous 245 FIFO mode for the FT2232H, channel A must be configured for FT245 FIFO mode in the EEPROM.
Example
use libftd2xx::{FTDI, BitMode}; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.set_bit_mode(0xFF, BitMode::AsyncBitbang)?;
pub fn queue_status(&mut self) -> Result<DWORD, Ftd2xxError>
[src]
Gets the number of bytes in the receive queue.
Example
use libftd2xx::FTDI; let mut buf: [u8; 4096] = [0; 4096]; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; let rx_bytes = ft.queue_status()? as usize; if (rx_bytes > 0) { ft.read(&mut buf[0..rx_bytes])?; }
pub fn read(&mut self, buf: &mut [u8]) -> Result<DWORD, Ftd2xxError>
[src]
Read data from the device.
This function does not return until the the buffer has been filled.
The number of bytes in the receive queue can be determined by calling
queue_status
, and then an buffer equal to the length of that
value can be passed to read
so that the function reads the device
and returns immediately.
When a read timeout value has been specified in a previous call to
set_timeouts
, read
returns when the timer expires or when the
buffer has been filled, whichever occurs first.
If the timeout occurred, read
reads available data into the buffer
and returns the number of bytes read.
If the return value of read
is equal to the length of the buffer
then read
has completed normally.
If the return value of read
is less than the length of the buffer
then a timeout has occurred and the read has been partially completed.
Examples
Read all avliable data
use libftd2xx::FTDI; let mut buf: [u8; 4096] = [0; 4096]; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; let rx_bytes = ft.queue_status()? as usize; if rx_bytes > 0 { ft.read(&mut buf[0..rx_bytes])?; }
Read with a timeout of 5 seconds
use libftd2xx::FTDI; use std::time::Duration; const BUF_LEN: usize = 4096; let mut buf: [u8; BUF_LEN] = [0; BUF_LEN]; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.set_timeouts(Duration::from_millis(5000), Duration::from_millis(0))?; let bytes_read = ft.read(&mut buf)? as usize; if bytes_read == BUF_LEN { println!("no read timeout") } else { println!("read timeout") }
pub fn write(&mut self, buf: &[u8]) -> Result<DWORD, Ftd2xxError>
[src]
Write data to the device.
Returns the number of bytes written.
Example
use libftd2xx::FTDI; const BUF_SIZE: usize = 256; let buf: [u8; BUF_SIZE] = [0; BUF_SIZE]; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; let num_bytes_written = ft.write(&buf)? as usize; if num_bytes_written == BUF_SIZE { println!("no write timeout") } else { println!("write timeout") }
pub fn purge_tx(&mut self) -> Result<(), Ftd2xxError>
[src]
This function purges the transmit buffers in the device.
Example
use libftd2xx::FTDI; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.purge_tx()?;
pub fn purge_rx(&mut self) -> Result<(), Ftd2xxError>
[src]
This function purges the receive buffers in the device.
Example
use libftd2xx::FTDI; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.purge_rx()?;
pub fn purge_all(&mut self) -> Result<(), Ftd2xxError>
[src]
This function purges the transmit and receive buffers in the device.
Example
use libftd2xx::FTDI; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.purge_all()?;
pub fn close(&mut self) -> Result<(), Ftd2xxError>
[src]
Close an open device.
Example
use libftd2xx::FTDI; let mut ft = FTDI::open_by_serial_number("FT59UO4C")?; ft.close()?;
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for FTDI
impl !Send for FTDI
impl !Sync for FTDI
impl Unpin for FTDI
impl UnwindSafe for FTDI
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,