PyD2XX 0.0.2__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/PKG-INFO +2 -2
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/README.md +1 -1
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/pyproject.toml +1 -1
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/PyD2XX.py +111 -17
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/LICENSE +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/FTD2XX.dll +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/FTD2XX_32.dll +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/FTD2XX_ARM.dll +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/Licenses/FTDI DRIVER LICENSE.txt +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/Licenses/PyD2XX LICENSE.txt +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/__init__.py +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/libftd2xx.dylib +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/libftd2xx.so +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/libftd2xx_32.so +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/libftd2xx_ARM.so +0 -0
- {pyd2xx-0.0.2 → pyd2xx-0.0.4}/src/PyD2XX/libftd2xx_ARM_32.so +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyD2XX
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: A Python wrapper for the FTDI D2XX library.
|
|
5
5
|
Keywords: FTDI,ftdichip,PyD2XX,D2XX,FTD2XX
|
|
6
6
|
Author-Email: Hector Soto <hector.soto@ftdichip.com>
|
|
@@ -16,7 +16,7 @@ Description-Content-Type: text/markdown
|
|
|
16
16
|
|
|
17
17
|
# PyD2XX
|
|
18
18
|
A Python wrapper for the FTDI D2XX library.
|
|
19
|
-
PyD2XX
|
|
19
|
+
PyD2XX supports Windows, Linux, and MacOS.
|
|
20
20
|
Most D2XX dynamic library variants are included in this package, so you don't need to include them directly in your project!
|
|
21
21
|
\^You don't need and should not have any D2XX .dll, .dylib, or .so file in your script's directory.
|
|
22
22
|
This was designed so the user needs zero ctypes knowledge and not need to import anything besides PyD2XX to interact with D2XX devices. The user should never have to interact with a ctypes object or method.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# PyD2XX
|
|
2
2
|
A Python wrapper for the FTDI D2XX library.
|
|
3
|
-
PyD2XX
|
|
3
|
+
PyD2XX supports Windows, Linux, and MacOS.
|
|
4
4
|
Most D2XX dynamic library variants are included in this package, so you don't need to include them directly in your project!
|
|
5
5
|
\^You don't need and should not have any D2XX .dll, .dylib, or .so file in your script's directory.
|
|
6
6
|
This was designed so the user needs zero ctypes knowledge and not need to import anything besides PyD2XX to interact with D2XX devices. The user should never have to interact with a ctypes object or method.
|
|
@@ -20,8 +20,8 @@ from sys import platform as Platform
|
|
|
20
20
|
|
|
21
21
|
# ---| Python Library Specific Definitions |---
|
|
22
22
|
|
|
23
|
-
VERSION = "0.0.
|
|
24
|
-
VERSION_TEST = "0.0.
|
|
23
|
+
VERSION = "0.0.4"
|
|
24
|
+
VERSION_TEST = "0.0.7_adresă_nouă"
|
|
25
25
|
|
|
26
26
|
PRINT_NONE = int("00000", 2) # Print no messages.
|
|
27
27
|
PRINT_ERROR_CRITICAL = int("00001", 2) # Print critical error messages.
|
|
@@ -227,6 +227,13 @@ FT_FLAGS_HISPEED = 2
|
|
|
227
227
|
FT_PURGE_RX = 1
|
|
228
228
|
FT_PURGE_TX = 2
|
|
229
229
|
|
|
230
|
+
FT_LIST_NUMBER_ONLY = int("0x80000000", 16)
|
|
231
|
+
FT_LIST_BY_INDEX = int("0x40000000", 16)
|
|
232
|
+
FT_LIST_ALL = int("0x20000000", 16)
|
|
233
|
+
FT_OPEN_BY_SERIAL_NUMBER = int("0x00000001", 16)
|
|
234
|
+
FT_OPEN_BY_DESCRIPTION = int("0x00000002", 16)
|
|
235
|
+
FT_OPEN_BY_LOCATION = int("0x00000004", 16)
|
|
236
|
+
|
|
230
237
|
class FT_Buffer:
|
|
231
238
|
def __init__(self, Size: int = None):
|
|
232
239
|
if(isinstance(Size, int)):
|
|
@@ -274,10 +281,10 @@ class FT_Buffer:
|
|
|
274
281
|
|
|
275
282
|
class _FT_DEVICE_LIST_INFO_NODE(ctypes.Structure):
|
|
276
283
|
_fields_ = [
|
|
277
|
-
("Flags", ctypes.
|
|
278
|
-
("Type", ctypes.
|
|
279
|
-
("ID", ctypes.
|
|
280
|
-
("LocID", ctypes.
|
|
284
|
+
("Flags", ctypes.c_ulong), #ULONG for Windows is 4 bytes. Linux library follows same byte alignment against normal convention.
|
|
285
|
+
("Type", ctypes.c_ulong),
|
|
286
|
+
("ID", ctypes.c_ulong),
|
|
287
|
+
("LocID", ctypes.wintypes.DWORD),
|
|
281
288
|
("SerialNumber", ctypes.c_char * 16),
|
|
282
289
|
("Description", ctypes.c_char * 64),
|
|
283
290
|
("Handle", ctypes.c_void_p)
|
|
@@ -339,7 +346,6 @@ def FT_GetDeviceInfoList(DeviceCount: int) -> tuple[int, list[FT_Device]] | tupl
|
|
|
339
346
|
_Print(FT_STATUS_STR[Status] + " | ERROR: DeviceCount IS LESS THAN 1.", PRINT_ERROR_MINOR, False)
|
|
340
347
|
return Status, "FT_OTHER_ERROR"
|
|
341
348
|
DeviceList = (_FT_DEVICE_LIST_INFO_NODE * DeviceCount.value)()
|
|
342
|
-
Handle = ctypes.c_void_p(0)
|
|
343
349
|
Status = _DLL.FT_GetDeviceInfoList(ctypes.byref(DeviceList), ctypes.byref(DeviceCount))
|
|
344
350
|
if(Status != FT_OK):
|
|
345
351
|
_Print(FT_STATUS_STR[Status] + " | ERROR: FAILED TO GET DEVICE INFO LIST.", PRINT_ERROR_MAJOR, False)
|
|
@@ -354,8 +360,73 @@ def FT_GetDeviceInfoList(DeviceCount: int) -> tuple[int, list[FT_Device]] | tupl
|
|
|
354
360
|
ReturnDeviceList[i].LocID = DeviceList[i].LocID
|
|
355
361
|
ReturnDeviceList[i].SerialNumber = DeviceList[i].SerialNumber.decode("utf-8")
|
|
356
362
|
ReturnDeviceList[i].Description = DeviceList[i].Description.decode("utf-8")
|
|
363
|
+
ReturnDeviceList[i].Handle = DeviceList[i].Handle.value if (DeviceList[i].Handle is not None) else 0
|
|
357
364
|
return Status, ReturnDeviceList
|
|
358
365
|
|
|
366
|
+
def FT_GetDeviceInfoDetail(Index: int) -> tuple[int, FT_Device] | tuple[int, str]:
|
|
367
|
+
Status = FT_OK
|
|
368
|
+
Index = ctypes.c_ulong(Index)
|
|
369
|
+
Device = _FT_DEVICE_LIST_INFO_NODE()
|
|
370
|
+
Status = _DLL.FT_GetDeviceInfoDetail(Index,
|
|
371
|
+
ctypes.c_void_p(ctypes.addressof(Device) + _FT_DEVICE_LIST_INFO_NODE.Flags.offset),
|
|
372
|
+
ctypes.c_void_p(ctypes.addressof(Device) + _FT_DEVICE_LIST_INFO_NODE.Type.offset),
|
|
373
|
+
ctypes.c_void_p(ctypes.addressof(Device) + _FT_DEVICE_LIST_INFO_NODE.ID.offset),
|
|
374
|
+
ctypes.c_void_p(ctypes.addressof(Device) + _FT_DEVICE_LIST_INFO_NODE.LocID.offset),
|
|
375
|
+
ctypes.c_void_p(ctypes.addressof(Device) + _FT_DEVICE_LIST_INFO_NODE.SerialNumber.offset),
|
|
376
|
+
ctypes.c_void_p(ctypes.addressof(Device) + _FT_DEVICE_LIST_INFO_NODE.Description.offset),
|
|
377
|
+
ctypes.c_void_p(ctypes.addressof(Device) + _FT_DEVICE_LIST_INFO_NODE.Handle.offset))
|
|
378
|
+
if(Status != FT_OK):
|
|
379
|
+
_Print(FT_STATUS_STR[Status] + " | ERROR: FAILED TO GET DEVICE INFO DETAIL.", PRINT_ERROR_MAJOR, False)
|
|
380
|
+
return Status, "FT_OTHER_ERROR"
|
|
381
|
+
ReturnDevice = _CreateDevice()
|
|
382
|
+
ReturnDevice.Flags = Device.Flags
|
|
383
|
+
ReturnDevice.Type = Device.Type
|
|
384
|
+
ReturnDevice.ID = Device.ID
|
|
385
|
+
ReturnDevice.LocID = Device.LocID
|
|
386
|
+
ReturnDevice.SerialNumber = Device.SerialNumber.decode("utf-8")
|
|
387
|
+
ReturnDevice.Description = Device.Description.decode("utf-8")
|
|
388
|
+
ReturnDevice.Handle = Device.Handle.value if (Device.Handle is not None) else 0
|
|
389
|
+
return Status, ReturnDevice
|
|
390
|
+
|
|
391
|
+
def FT_ListDevices(IndexCount: int, Flags: int) -> tuple[int, int] | tuple[int, str] | tuple[int, list[str]]:
|
|
392
|
+
Status = FT_OTHER_ERROR
|
|
393
|
+
ReturnValue = FT_OTHER_ERROR
|
|
394
|
+
if(Flags & FT_LIST_NUMBER_ONLY):
|
|
395
|
+
ReturnValue = ctypes.wintypes.DWORD(0)
|
|
396
|
+
Status = _DLL.FT_ListDevices(ctypes.byref(ReturnValue), NULL, Flags)
|
|
397
|
+
if(Status == FT_OK):
|
|
398
|
+
ReturnValue = ReturnValue.value
|
|
399
|
+
else:
|
|
400
|
+
ReturnValue = 0
|
|
401
|
+
_Print(FT_STATUS_STR[Status] + " | FT_ListDevices(), ERROR: FAILED TO LIST DEVICE COUNT.", PRINT_ERROR_MAJOR, False)
|
|
402
|
+
elif(Flags & FT_LIST_BY_INDEX):
|
|
403
|
+
Buffer = ctypes.c_buffer(SIZE_CHAR * 64)
|
|
404
|
+
DeviceIndex = ctypes.wintypes.DWORD(IndexCount)
|
|
405
|
+
Status = _DLL.FT_ListDevices(DeviceIndex, ctypes.byref(Buffer), Flags)
|
|
406
|
+
if(Status == FT_OK):
|
|
407
|
+
ReturnValue = Buffer.value.decode("ascii")
|
|
408
|
+
else:
|
|
409
|
+
ReturnValue = FT_STATUS_STR[Status]
|
|
410
|
+
_Print(FT_STATUS_STR[Status] + " | FT_ListDevices(), ERROR: FAILED TO GET DEVICE INFO.", PRINT_ERROR_MAJOR, False)
|
|
411
|
+
elif(Flags & FT_LIST_ALL):
|
|
412
|
+
ReturnValue = []
|
|
413
|
+
PointerArray = (ctypes.c_void_p * (IndexCount + 1))()
|
|
414
|
+
PointerArray[IndexCount] = NULL
|
|
415
|
+
for i in range(IndexCount):
|
|
416
|
+
PointerArray[i] = ctypes.cast(ctypes.c_buffer(SIZE_CHAR*64), ctypes.c_void_p)
|
|
417
|
+
DeviceCount = ctypes.wintypes.DWORD(IndexCount)
|
|
418
|
+
Status = _DLL.FT_ListDevices(PointerArray, ctypes.byref(DeviceCount), Flags)
|
|
419
|
+
if(Status == FT_OK):
|
|
420
|
+
for i in range(IndexCount):
|
|
421
|
+
ReturnValue.append(ctypes.cast(PointerArray[i], ctypes.c_char_p).value.decode("ascii"))
|
|
422
|
+
else:
|
|
423
|
+
for i in range(IndexCount):
|
|
424
|
+
ReturnValue.append(FT_STATUS_STR[Status])
|
|
425
|
+
_Print(FT_STATUS_STR[Status] + " | FT_ListDevices(), ERROR: FAILED TO GET INFO FOR DEVICES.", PRINT_ERROR_MAJOR, False)
|
|
426
|
+
else:
|
|
427
|
+
_Print(FT_STATUS_STR[Status] + " | FT_ListDevices(), WARNING: NOT GIVEN VALID FLAGS.", PRINT_ERROR_MAJOR, False)
|
|
428
|
+
return Status, ReturnValue
|
|
429
|
+
|
|
359
430
|
def FT_Open(Index: int, Device: FT_Device) -> int:
|
|
360
431
|
Status = FT_OTHER_ERROR
|
|
361
432
|
if(not(isinstance(Device, FT_Device))):
|
|
@@ -367,6 +438,24 @@ def FT_Open(Index: int, Device: FT_Device) -> int:
|
|
|
367
438
|
Device.Handle = Device._Handle.value
|
|
368
439
|
return Status
|
|
369
440
|
|
|
441
|
+
def FT_OpenEx(Arg1: int | str, Flags: int, Device: FT_Device) -> int:
|
|
442
|
+
Status = FT_OTHER_ERROR
|
|
443
|
+
if(not(isinstance(Device, FT_Device))):
|
|
444
|
+
_Print("FT_OpenEx(), did not get an FT_Device!", PRINT_ERROR_MAJOR, False)
|
|
445
|
+
return Status
|
|
446
|
+
elif(not(isinstance(Device._Handle, ctypes.c_void_p))):
|
|
447
|
+
_Print("FT_OpenEx(), got an uninitialized or broken FT_Device object!", PRINT_ERROR_MAJOR, False)
|
|
448
|
+
return Status
|
|
449
|
+
if isinstance(Arg1, str):
|
|
450
|
+
Status = _DLL.FT_OpenEx(ctypes.create_string_buffer(Arg1.encode("utf-8")), ctypes.wintypes.DWORD(Flags), ctypes.byref(Device._Handle))
|
|
451
|
+
elif isinstance(Arg1, int):
|
|
452
|
+
Status = _DLL.FT_OpenEx(ctypes.wintypes.DWORD(Arg1), ctypes.wintypes.DWORD(Flags), ctypes.byref(Device._Handle))
|
|
453
|
+
else:
|
|
454
|
+
_Print("FT_OpenEx(), got an invalid Arg1 type!", PRINT_ERROR_MAJOR, False)
|
|
455
|
+
return Status
|
|
456
|
+
Device.Handle = Device._Handle.value
|
|
457
|
+
return Status
|
|
458
|
+
|
|
370
459
|
def FT_Close(Device: FT_Device) -> int:
|
|
371
460
|
Status = FT_OTHER_ERROR
|
|
372
461
|
if(not(isinstance(Device, FT_Device))):
|
|
@@ -383,6 +472,18 @@ def FT_SetBitMode(Device: FT_Device, Mask: int, Mode: int) -> int:
|
|
|
383
472
|
Status = _DLL.FT_SetBitMode(Device._Handle, ctypes.c_char(Mask), ctypes.c_char(Mode))
|
|
384
473
|
return Status
|
|
385
474
|
|
|
475
|
+
def FT_Read(Device: FT_Device, BufferLength: int) -> tuple[int, FT_Buffer, int]:
|
|
476
|
+
Status = FT_OTHER_ERROR
|
|
477
|
+
Buffer = FT_Buffer()
|
|
478
|
+
Buffer._RawAddress = ctypes.c_buffer(BufferLength)
|
|
479
|
+
Buffer._Length = BufferLength
|
|
480
|
+
BytesTransferred = ctypes.c_ulong(0)
|
|
481
|
+
Status = _DLL.FT_Read(Device._Handle,
|
|
482
|
+
ctypes.byref(Buffer._RawAddress),
|
|
483
|
+
BufferLength,
|
|
484
|
+
ctypes.byref(BytesTransferred))
|
|
485
|
+
return Status, Buffer, BytesTransferred.value
|
|
486
|
+
|
|
386
487
|
def FT_Write(Device: FT_Device, Buffer: FT_Buffer, BufferLength: int) -> tuple[int, int]:
|
|
387
488
|
Status = FT_OTHER_ERROR
|
|
388
489
|
if(isinstance(Buffer._RawAddress, FT_Buffer)):
|
|
@@ -395,17 +496,10 @@ def FT_Write(Device: FT_Device, Buffer: FT_Buffer, BufferLength: int) -> tuple[i
|
|
|
395
496
|
ctypes.byref(BytesTransferred))
|
|
396
497
|
return Status, BytesTransferred.value
|
|
397
498
|
|
|
398
|
-
def
|
|
499
|
+
def FT_SetBaudRate(Device: FT_Device, Baudrate: int) -> int:
|
|
399
500
|
Status = FT_OTHER_ERROR
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
Buffer._Length = BufferLength
|
|
403
|
-
BytesTransferred = ctypes.c_ulong(0)
|
|
404
|
-
Status = _DLL.FT_Read(Device._Handle,
|
|
405
|
-
ctypes.byref(Buffer._RawAddress),
|
|
406
|
-
BufferLength,
|
|
407
|
-
ctypes.byref(BytesTransferred))
|
|
408
|
-
return Status, Buffer, BytesTransferred.value
|
|
501
|
+
Status = _DLL.FT_SetBaudRate(Device._Handle, ctypes.wintypes.DWORD(Baudrate))
|
|
502
|
+
return Status
|
|
409
503
|
|
|
410
504
|
def FT_Purge(Device: FT_Device, Mask: int) -> int:
|
|
411
505
|
Status = FT_OTHER_ERROR
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|