plesty.lib.traffic.apt_d2xx
Reach an APT controller through FTDI’s D2XX driver when it has no COM port.
On a Windows host with Thorlabs Kinesis installed, an APT controller is bound
to the FTDI D2XX driver and exposes no virtual COM port, so
serial.tools.list_ports never lists it. Kinesis itself talks D2XX, and so
can AptTrafficManager: D2xxPort is a
serial-like adapter over FTDI’s D2XX library exposing exactly what the manager
calls on a port.
The library is FTDI’s own ftd2xx.dll, called through ctypes: it is
installed with the driver — by Kinesis, or FTDI’s driver package — on every
host where a controller is bound to D2XX, so nothing extra is installed in
Python (#68). Without it this module reports no devices rather than failing to
import.
Enumerating (list_devices()) reads the driver’s device list and never
opens a controller. Opening one (D2xxPort.open()) needs Kinesis closed:
it holds the device while it runs.
Attributes
Classes
One controller as the D2XX driver lists it. |
|
One opened device: the D2XX calls |
|
FTDI's D2XX library, loaded through |
|
Serial-like adapter over one D2XX device, for |
Functions
|
Return whether address names a controller over D2XX ( |
|
Return the serial number of a |
|
Return a driver string — NUL-terminated ASCII — as text. |
|
Return FTDI's D2XX library, or |
|
Return every controller the D2XX driver lists. Opens nothing. |
Module Contents
- plesty.lib.traffic.apt_d2xx.ADDRESS_PREFIX = 'd2xx:'
- plesty.lib.traffic.apt_d2xx.BAUDRATE = 115200
- plesty.lib.traffic.apt_d2xx.WORD_LENGTH_8 = 8
- plesty.lib.traffic.apt_d2xx.STOP_BITS_1 = 0
- plesty.lib.traffic.apt_d2xx.PARITY_NONE = 0
- plesty.lib.traffic.apt_d2xx.FLOW_RTS_CTS = 256
- plesty.lib.traffic.apt_d2xx.PURGE_RX = 1
- plesty.lib.traffic.apt_d2xx.PURGE_TX = 2
- plesty.lib.traffic.apt_d2xx._PURGE_DWELL = 0.05
- plesty.lib.traffic.apt_d2xx._IO_TIMEOUT_MS = 1000
- class plesty.lib.traffic.apt_d2xx.D2xxDevice
One controller as the D2XX driver lists it.
- Variables:
serial – The serial number, as the driver reports it.
description – The driver’s description, e.g.
Kinesis K-Cube Stepper.
- serial: str
- description: str = ''
- property address: str
d2xx:<serial>.- Type:
The address that opens this controller
- Return type:
str
- plesty.lib.traffic.apt_d2xx.is_d2xx_address(address: str | None) bool
Return whether address names a controller over D2XX (
d2xx:<serial>).- Parameters:
address (str | None)
- Return type:
bool
- plesty.lib.traffic.apt_d2xx.d2xx_serial(address: str) str
Return the serial number of a
d2xx:<serial>address.- Parameters:
address (str)
- Return type:
str
- plesty.lib.traffic.apt_d2xx._LIBRARY_NAMES
- plesty.lib.traffic.apt_d2xx._OPEN_BY_SERIAL_NUMBER = 1
- plesty.lib.traffic.apt_d2xx._INFO_BUFFER = 256
- plesty.lib.traffic.apt_d2xx._HANDLE
- plesty.lib.traffic.apt_d2xx._DWORD_P
- plesty.lib.traffic.apt_d2xx._PROTOTYPES: dict[str, list[Any]]
- plesty.lib.traffic.apt_d2xx._STATUS = ('FT_OK', 'FT_INVALID_HANDLE', 'FT_DEVICE_NOT_FOUND', 'FT_DEVICE_NOT_OPENED', 'FT_IO_ERROR',...
- plesty.lib.traffic.apt_d2xx._decode(value: bytes) str
Return a driver string — NUL-terminated ASCII — as text.
- Parameters:
value (bytes)
- Return type:
str
- class plesty.lib.traffic.apt_d2xx._D2xxHandle(library: _D2xxLibrary, handle: ctypes.c_void_p)
One opened device: the D2XX calls
D2xxPortmakes on it.- Parameters:
library (_D2xxLibrary)
handle (ctypes.c_void_p)
- _lib
- _handle
- _call(name: str, *args: Any) None
- Parameters:
name (str)
args (Any)
- Return type:
None
- set_timeouts(read_ms: int, write_ms: int) None
- Parameters:
read_ms (int)
write_ms (int)
- Return type:
None
- set_baud_rate(baud: int) None
- Parameters:
baud (int)
- Return type:
None
- set_data_characteristics(word_length: int, stop_bits: int, parity: int) None
- Parameters:
word_length (int)
stop_bits (int)
parity (int)
- Return type:
None
- purge(mask: int) None
- Parameters:
mask (int)
- Return type:
None
- reset_device() None
- Return type:
None
- set_flow_control(flow: int, xon: int, xoff: int) None
- Parameters:
flow (int)
xon (int)
xoff (int)
- Return type:
None
- set_rts() None
- Return type:
None
- queue_status() int
- Return type:
int
- write(data: bytes) int
- Parameters:
data (bytes)
- Return type:
int
- read(size: int) bytes
- Parameters:
size (int)
- Return type:
bytes
- close() None
- Return type:
None
- class plesty.lib.traffic.apt_d2xx._D2xxLibrary(dll: Any)
FTDI’s D2XX library, loaded through
ctypes.Wrap dll and declare the prototypes of the functions it is asked for.
- Parameters:
dll (Any) – The loaded library — or, in a test, anything with the same function names; only real ctypes functions take a prototype.
- _dll
- call(name: str, *args: Any) None
Call the D2XX function name; anything but
FT_OKraises.- Raises:
OSError – The driver answered an error, named in the message.
- Parameters:
name (str)
args (Any)
- Return type:
None
- device_count() int
Build the driver’s device list and return its length.
- Return type:
int
- device_info(index: int) tuple[str, str]
Return the serial number and description of listed device index.
- Parameters:
index (int)
- Return type:
tuple[str, str]
- open_by_serial(serial: str) _D2xxHandle
Open the device with serial number serial.
The driver’s device list is rebuilt first, as the ftd2xx package did by default: a device plugged in (or released by Kinesis) since the last listing is then found.
- Parameters:
serial (str)
- Return type:
- plesty.lib.traffic.apt_d2xx.load_driver() _D2xxLibrary | None
Return FTDI’s D2XX library, or
Nonewhen it is not installed here.Loaded on first use: the library exists only where FTDI’s driver is installed, and a missing one must read as “no D2XX” rather than stop the caller from importing.
- Return type:
_D2xxLibrary | None
- plesty.lib.traffic.apt_d2xx.list_devices() list[D2xxDevice]
Return every controller the D2XX driver lists. Opens nothing.
The driver builds this list from the USB descriptors alone, which is why a controller Kinesis holds still appears in it.
- Return type:
list[D2xxDevice]
- class plesty.lib.traffic.apt_d2xx.D2xxPort(serial: str)
Serial-like adapter over one D2XX device, for
AptTrafficManager.Provides what the traffic manager calls on its port:
write,read,in_waiting,is_open,close,reset_input_bufferandreset_output_buffer.Remember which controller to open;
open()opens it.- Parameters:
serial (str) – The controller’s serial number, as the driver lists it.
- serial
- _dev: Any | None = None
- open() None
Open the device and set up the APT link: 115200 8N1, RTS/CTS.
- Raises:
RuntimeError – FTDI’s D2XX library is not installed on this host.
OSError – The device would not open, typically because Kinesis (or another process) holds it.
- Return type:
None
- property is_open: bool
Return
Truewhile the device is open.- Return type:
bool
- property in_waiting: int
Number of received bytes waiting to be read.
- Return type:
int
- write(data: bytes) int
Send data to the controller and return the byte count.
- Parameters:
data (bytes)
- Return type:
int
- read(size: int) bytes
Return up to size received bytes.
- Parameters:
size (int)
- Return type:
bytes
- reset_input_buffer() None
Discard received bytes not yet read.
- Return type:
None
- reset_output_buffer() None
Discard bytes queued for sending.
- Return type:
None
- close() None
Release the device so Kinesis (or the next session) can open it.
- Return type:
None