更新UCD-API库及文档
This commit is contained in:
64
docs/UCD-API文档/examples/work_with_pdc_pdo_config.py
Normal file
64
docs/UCD-API文档/examples/work_with_pdc_pdo_config.py
Normal file
@@ -0,0 +1,64 @@
|
||||
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)
|
||||
|
||||
|
||||
# Set initial power role RX side - SINK, TX side - SOURCE
|
||||
role.pdcrx.capabilities.enable_dr_swap(False)
|
||||
role.pdctx.capabilities.enable_dr_swap(False)
|
||||
role.pdcrx.capabilities.set_initial_role(UniTAP.pdc.PdcDeviceRole.UFP)
|
||||
role.pdctx.capabilities.set_initial_role(UniTAP.pdc.PdcDeviceRole.DFP)
|
||||
|
||||
# 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.pdctx.power_source.get_pdo_list(read_from_device=True)
|
||||
|
||||
# Print PDO list from Source
|
||||
print("Initial source PDO list:\n")
|
||||
for item in source_pdo_list:
|
||||
print(item)
|
||||
|
||||
# Change Voltage and Max Current on PDO2
|
||||
source_pdo_list[1].pdo_object.voltage(150)
|
||||
source_pdo_list[1].pdo_object.max_current(200)
|
||||
|
||||
# Apply changes
|
||||
role.pdctx.power_source.set_pdo_list(source_pdo_list)
|
||||
role.pdctx.power_source.send_pdo()
|
||||
role.pdctx.controls.reconnect()
|
||||
|
||||
# Check new pdo list
|
||||
source_pdo_list = role.pdctx.power_source.get_pdo_list(read_from_device=True)
|
||||
print("Source PDO list with changed PDO2 voltage and current fields:\n")
|
||||
for item in source_pdo_list:
|
||||
print(item)
|
||||
|
||||
# Disable PDO2
|
||||
source_pdo_list[1].disable_pdo()
|
||||
role.pdctx.power_source.set_pdo_list(source_pdo_list)
|
||||
role.pdctx.power_source.send_pdo()
|
||||
role.pdctx.controls.reconnect()
|
||||
|
||||
# Check new pdo list
|
||||
source_pdo_list = role.pdctx.power_source.get_pdo_list(read_from_device=True)
|
||||
print("Source PDO list with disabled PDO2:\n")
|
||||
for item in source_pdo_list:
|
||||
print(item)
|
||||
|
||||
|
||||
# Configuration Power Contract Control on Sink. Set PDO Type Priority to Prefer higher current
|
||||
role.pdcrx.power_contract_control.pdo_type_priority = UniTAP.pdc.ContractTypePriority.HigherCurrent
|
||||
|
||||
Reference in New Issue
Block a user