Menu

Device class

Miso kopera

Device class:

__init__()

__init__(serial_string, description, index = 0, baudrate = None, 
         interface = None, read_buffer_size = 4096, write_buffer_size = 4096)

Internaly init device, sets and allocate read/write buffers. Device is referenced by serial_string, description (and index) parameters. They are returned by Ftdi.list_devices() (sourceforge.net).
If something goes wrong DeviceInitError exception is raised. And if interface is invalid DeviceInterfaceError is raised.

serial_string
Ftdi serial byte string of device.

description
Description byte string.

index
If is more devices with same serial_string and description, device can be selected by index. Indexes starts from 0 what is also a default value.

baudrate
Desired communication baudrate. If None default value from libFTDI is used.

interface
Desired device channel. If None default value from libFTDI is used.

read_buffer_size
Size of read buffer. Default value is 4096

write_buffer_size
Size of write buffer. Default value is 4096

open()

open()

Opens device. This must be called before any other functions. Raise DeviceOpenError when device can't be opened.

close()

close()

Close (and deinit) opened device.

reset()

reset()

Reset device.

read()

read(size, timeout = None, expected_time = 0)

Reads and returns size of bytes from device. Function pools for data until desired size or timeout is reached. When timeout is reached, function returns all bytes that were obtained until than. Raise DeviceReadError exception if reading fail for some reason.

size
Number of desired or expected bytes.

timeout
Time in ms. After that function returns whatever it has. If None, read_timeout from set_timeout() is used.

expected_time
Time in ms. Function will sleep expected_time before it first reads (and starts pooling for) data. This can be very usefull for pooling optimalization. Default value is 0.

write()

write(data)

Write data to device. Data should be a bytes() object. Returns number of written bytes. Raise DeviceWriteError exception.

data
bytes that should be send to device. E.g. b"hello"

flush()

flush(flush_input = False, flush_output = False)

Flush devices input and/or output buffer.

flush_input
If True flush input (read or RX) buffer.

flush_output
If True flush output (write or TX) buffer.

get_baudrate()

get_baudrate()

Returns device baudrate.

set_baudrate()

set_baudrate(baudrate)

Sets device baudrate.

baudrate
Desired baudrate.

set_latency_timer()

set_latency_timer(latency)

Sets device latency timer. Or raise DeviceLatencyTimerError exception.

latency
Time in ms.

get_latency_timer()

get_latency_timer()

Returns device latency timer. Or raise DeviceLatencyTimerError exception.

set_line_property()

set_line_property(bits_type, stopbits_type, parity_type, break_type = BREAK_OFF)

Sets RS232 line characteristics or raise DeviceLinePropertyError exception.

bits_type
Should be one of BITS_7, BITS_8 constants.

stopbits_type
Number of stopbites. One of STOP_BIT_1, STOP_BIT_15, STOP_BIT_2 constants.

parity_type
One of PARITY_NONE, PARITY_ODD, PARITY_EVEN, PARITY_MARK, PARITY_SPACE constants.

break_type
One of BREAK_OFF or BREAK_ON

set_timeout()

set_timeout(read_timeout, write_timeout)

Sets device read and write timeout.

read_timeout
Read timeout in ms.

write_timeout
Write timeout in ms.

set_flow_control()

set_flow_control(flow_ctrl = SIO_DISABLE_FLOW_CTRL)

Sets flow control or raises DeviceFlowCtrlError exception

flow_ctrl
Should be one of SIO_DISABLE_FLOW_CTRL, SIO_RTS_CTS_HS, SIO_DTR_DSR_HS or SIO_XON_XOFF_HS

get_serial_string()

get_serial_string()

Return device ftdi serial string. It is the same string that was passed to __init__()

get_error_string()

get_error_string()

Returns internal string of last error from libFTDI.

get_modem_status()

get_modem_status()

Returns poll modem status information or raises DeviceModemStatusError exception.

read_pins()

read_pins()

Returns pins state or raises DeviceReadPinsError exception.


Related

Wiki: API Documentation

MongoDB Logo MongoDB