更新UCD-API库及文档
This commit is contained in:
65
docs/UCD-API文档/examples/work_with_pdc_pdo.py
Normal file
65
docs/UCD-API文档/examples/work_with_pdc_pdo.py
Normal file
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# Import UniTAP module.
|
||||
#
|
||||
import UniTAP
|
||||
|
||||
#
|
||||
# To initialize UniTAP library wrapper user should create UniTAP.TsiLib() object.
|
||||
#
|
||||
lUniTAP = UniTAP.TsiLib()
|
||||
|
||||
#
|
||||
# For opening device, please, put serial number of the device as 8 symbol str or put index of device.
|
||||
#
|
||||
# dev = lUniTAP.open("NNNNNNNN")
|
||||
dev = lUniTAP.open(0)
|
||||
|
||||
# After opening device as in UCD Console device role should be selected.
|
||||
role = dev.select_role(UniTAP.dev.UCD424.USBCSourceUSBCSink)
|
||||
# role = dev.select_role(UniTAP.dev.UCD500.USBCSourceUSBCSink)
|
||||
dev.opf_handler = UniTAP.OpfHandlerInternal(port_tx=role.dptx, port_rx=role.dprx)
|
||||
|
||||
|
||||
# Get Source PDO from RX side.
|
||||
# If read_from_device = True, PDO will be read directly from device, not from internal buffer
|
||||
source_pdo_list = role.pdcrx.power_source.get_pdo_list(read_from_device=True)
|
||||
|
||||
for item in source_pdo_list:
|
||||
print(item)
|
||||
|
||||
# Get current Power Role
|
||||
power_role = role.pdcrx.capabilities.status.power_role()
|
||||
print(power_role.name)
|
||||
|
||||
if power_role == UniTAP.pdc.PowerRole.Sink:
|
||||
# If needed to change power role, use reconnect
|
||||
role.pdcrx.controls.reconnect()
|
||||
if power_role == UniTAP.pdc.PowerRole.Source:
|
||||
for index, item in enumerate(source_pdo_list):
|
||||
if index > 0:
|
||||
item.interpret_pdo_as_selected_type(UniTAP.pdc.BatteryPdo)
|
||||
role.pdcrx.power_source.set_pdo_list(source_pdo_list)
|
||||
role.pdcrx.power_source.send_pdo()
|
||||
role.pdcrx.controls.reconnect()
|
||||
|
||||
source_pdo_list = role.pdcrx.power_source.get_pdo_list(read_from_device=True)
|
||||
for item in source_pdo_list:
|
||||
print(item)
|
||||
|
||||
# For Sink PDO the same algorythm, but it is also possible to control `Power Contract`
|
||||
role.pdcrx.power_contract_control.pdo_type_priority = UniTAP.pdc.ContractTypePriority.HigherCurrent
|
||||
|
||||
# Control Internal resistance (only for UCD-340)
|
||||
# print(role.pdcrx.power_contract_control.internal_resistance)
|
||||
# role.pdcrx.power_contract_control.internal_resistance = UniTAP.pdc.InternalResistance.Resistance_3_5_Ohm
|
||||
# print(role.pdcrx.power_contract_control.internal_resistance)
|
||||
|
||||
#
|
||||
# Since the 3.5 version, TsiLib and TSIDevice objects have the option to be closed earlier.
|
||||
# TSIDevice can be closed with the TsiLib method close(). TsiLib can be closed with cleanup().
|
||||
# Clean up will close all opened devices and block ability to open any devices
|
||||
# with same TsiLib object.
|
||||
#
|
||||
lUniTAP.close(dev)
|
||||
|
||||
lUniTAP.cleanup()
|
||||
Reference in New Issue
Block a user