FTDI¤
Prerequisites¤
Before communicating with equipment that use a Future Technology Devices International (FTDI) chip for the interface, either a libusb-compatible driver or the d2xx driver must be installed and the directory to the appropriate library file (libusb or ftd2xx) must be available on the PATH environment variable.
Tip
If using the d2xx driver, you can create a D2XX_LIBRARY environment variable with the value being the full path to a d2xx library file to load. This variable can also be defined as a <d2xx_library> element in a Configuration file.
The following instructions are intended to be a starting point if you are having issues communicating with an FTDI chip.
Windows¤
The choice of using a libusb or d2xx driver depends on whether the manufacturer of the equipment provides software that you also want to use to control the equipment and what driver their software uses. On Windows, this is typically the d2xx driver. If you don't want to use the manufacturer's software (or they don't provide software) then the choice of which driver to use does not matter.
If you want to use a libusb driver, follow these instructions.
If you want to use the d2xx driver, follow the installation guide (skip this step if the Windows Device Manager shows that the driver for the equipment has already been successfully installed), download the zip file that contains the ftd2xx library file then extract the zip file and copy the appropriate library file (i.e., amd64\ftd2xx64.dll if using 64-bit Python, i386\ftd2xx.dll if using 32-bit Python) to a directory that is on your PATH environment variable.
Debian/Ubuntu¤
If you want to use the libusb driver (recommended), follow these instructions.
If you want to use the d2xx driver, follow the installation guide, download the compressed-archive file that contains the libftd2xx.so library file then extract the archive and copy the library file (i.e., linux-x86_64\libftd2xx.so) to a directory that is on your PATH environment variable, and, finally create a udev rule to be able to access the equipment as a non-root user (follow the udev instructions from here).
macOS¤
If you want to use the libusb driver (recommended), follow these instructions.
If you want to use the d2xx driver, follow the installation guide, download the virtual-disk file that contains the libftd2xx.dylib library file then extract the file and copy the library file (i.e., release\build\libftd2xx.1.4.30.dylib) to a directory that is on your PATH environment variable, and, finally rename the library file to be libftd2xx.dylib (i.e., remove the version information).
FTDI
(MessageBased)
¤
FTDI(equipment: Equipment)
Base class for equipment that use a Future Technology Devices International (FTDI) chip for communication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties
for the FTDI communication protocol, as well as the properties defined in
MessageBased. The
DataBits,
Parity and StopBits
enumeration names or values may also be used. For properties that specify an alias, you
may also use the alternative name as the property name. The
read_termination and
write_termination values
are automatically set to None (termination characters are not used in the FTDI protocol).
Connection Properties:
| Name | Type | Description |
|---|---|---|
baud_rate |
int
|
The baud rate (alias: baudrate).
Default: |
data_bits |
DataBits | str | int
|
The number of data bits: 7 or 8 (alias: bytesize).
Default: |
dsr_dtr |
bool
|
Whether to enable hardware (DSR/DTR) flow control (alias: dsrdtr).
Default: |
latency |
int | None
|
The latency-timer value in milliseconds, between 1 and 255.
If |
parity |
Parity | str
|
Parity checking: NONE, ODD, EVEN, MARK or SPACE.
Default: |
rts_cts |
bool
|
Whether to enable hardware (RTS/CTS) flow control (alias: rtscts).
Default: |
stop_bits |
StopBits | str | float
|
The number of stop bits: 1, 1.5 or 2 (alias: stopbits).
Default: |
xon_xoff |
bool
|
Whether to enable software flow control (alias: xonxoff).
Default: |
Source code in src/msl/equipment/interfaces/ftdi.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | |
check_packet_for_errors
instance-attribute
¤
check_packet_for_errors: bool = True
Whether to check the bit mask of the line byte in a read packet for errors.
This attribute is only used if libusb is used as the communication library.
See poll_status for more details
about the line bit mask.
disconnect
¤
disconnect() -> None
Disconnect from the equipment.
Source code in src/msl/equipment/interfaces/ftdi.py
922 923 924 925 926 927 928 929 930 931 | |
get_latency_timer
¤
get_latency_timer() -> int
Get the latency-timer value from the FTDI chip.
Returns:
| Type | Description |
|---|---|
int
|
The latency-timer value, in milliseconds. |
Source code in src/msl/equipment/interfaces/ftdi.py
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 | |
poll_status
¤
Polls the modem and line status bytes from the FTDI chip.
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
The Bit mask of the
Bit mask of the
|
Source code in src/msl/equipment/interfaces/ftdi.py
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
purge_buffers
¤
purge_buffers() -> None
Purge the receive (Rx) and transmit (Tx) buffers of the FTDI chip.
Source code in src/msl/equipment/interfaces/ftdi.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | |
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat = None,
size: int | None = None
) -> bytes | str | NumpyArray1D
Convenience method for performing a write followed by a read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
bytes | str
|
The message to write to the equipment. |
required |
delay
|
float
|
Time delay, in seconds, to wait between the write and read operations. |
0.0
|
decode
|
bool
|
True
|
|
dtype
|
MessageDataType | None
|
The data type of the elements in the returned message. Can be any object that numpy
dtype supports. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat
|
The format that the returned message data is in. Ignored if |
None
|
size
|
int | None
|
The number of bytes to read. Ignored if the value is |
None
|
Returns:
| Type | Description |
|---|---|
bytes | str | NumpyArray1D
|
Source code in src/msl/equipment/interfaces/message_based.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat = None,
size: int | None = None
) -> bytes | str | NumpyArray1D
Read a message from the equipment.
This method will block until one of the following conditions is fulfilled:
sizebytes have been received — only ifsizeis notNone.- the read_termination
byte(s) is(are) received — only if
read_termination
is not
None. - a timeout occurs — only if timeout
is not
None. If a timeout occurs, an MSLTimeoutError is raised. - max_read_size bytes have been received. If the maximum number of bytes have been read, an MSLConnectionError is raised.
Tip
You may also want to set the rstrip value for the class instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decode
|
bool
|
True
|
|
dtype
|
MessageDataType | None
|
The data type of the elements in the returned message. Can be any object that numpy
dtype supports. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat
|
The format that the returned message data is in. Ignored if |
None
|
size
|
int | None
|
The number of bytes to read. Ignored if the value is |
None
|
Returns:
| Type | Description |
|---|---|
bytes | str | NumpyArray1D
|
Source code in src/msl/equipment/interfaces/message_based.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
reset_device
¤
reset_device() -> None
Sends a reset command to the FTDI chip.
Source code in src/msl/equipment/interfaces/ftdi.py
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
set_baud_rate
¤
set_baud_rate(rate: int) -> None
Set the baud rate for the FTDI chip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
int
|
The baud rate. |
required |
Source code in src/msl/equipment/interfaces/ftdi.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 | |
set_break
¤
set_break(state: bool) -> None
Set the BREAK condition for the FTDI chip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
bool
|
The state of the BREAK condition. If |
required |
Source code in src/msl/equipment/interfaces/ftdi.py
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 | |
set_data_characteristics
¤
set_data_characteristics(
*,
data_bits: DataBits | str | int = EIGHT,
parity: Parity | str = NONE,
stop_bits: StopBits | str | float = ONE
) -> None
Set the RS-232 data characteristics for the FTDI chip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_bits
|
DataBits | str | int
|
The number of data bits (7 or 8). Can be an enum member name (case insensitive) or value. |
EIGHT
|
parity
|
Parity | str
|
The parity. Can be an enum member name (case insensitive) or value. |
NONE
|
stop_bits
|
StopBits | str | float
|
The number of stop bits. Can be an enum member name (case insensitive) or value. |
ONE
|
Source code in src/msl/equipment/interfaces/ftdi.py
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
set_dtr
¤
set_dtr(state: bool) -> None
Set the Data Terminal Ready (DTR) control signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
bool
|
New state of the DTR logical level: HIGH ( |
required |
Source code in src/msl/equipment/interfaces/ftdi.py
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
set_flow_control
¤
set_flow_control(
flow: Literal["RTS_CTS", "DTR_DSR", "XON_XOFF"] | None = None,
*,
xon: int = 0,
xoff: int = 0
) -> None
Sets the flow control for the FTDI chip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
Literal['RTS_CTS', 'DTR_DSR', 'XON_XOFF'] | None
|
The type of flow control to use, |
None
|
xon
|
int
|
The character (between 0 and 255) to signal Xon. Only used if |
0
|
xoff
|
int
|
The character (between 0 and 255) to signal Xoff. Only used if |
0
|
Source code in src/msl/equipment/interfaces/ftdi.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 | |
set_latency_timer
¤
set_latency_timer(value: int) -> None
Set the latency-timer value for the FTDI chip.
The latency timer is a form of timeout mechanism for the read buffer of FTDI chip.
The latency timer counts from the last time data was sent back to the computer. If the latency timer expires, the chip will send what data it has available to the computer regardless of how many bytes it is waiting on. The latency timer will then reset and begin counting again.
The timer allows the chip to be better optimized for protocols requiring faster response times from shorter data packets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Required value, in milliseconds, of the latency timer. Valid range is [1, 255]. |
required |
Source code in src/msl/equipment/interfaces/ftdi.py
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 | |
set_rts
¤
set_rts(state: bool) -> None
Set the Request To Send (RTS) control signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
bool
|
New state of the RTS logical level: HIGH ( |
required |
Source code in src/msl/equipment/interfaces/ftdi.py
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 | |
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat = "ieee"
) -> int
Write a message to the equipment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
bytes | str
|
The message to write to the equipment. |
required |
data
|
Sequence1D | None
|
The data to append to |
None
|
dtype
|
MessageDataType
|
The data type to use to convert each element in |
'<f'
|
fmt
|
MessageFormat
|
The format to use to convert |
'ieee'
|
Returns:
| Type | Description |
|---|---|
int
|
The number of bytes written. |
Source code in src/msl/equipment/interfaces/message_based.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |