usb
類別包含多個子類別,用來存取 USB 裝置的介面、描述元和端點。包含的子類別如下:
USB 描述元會回報裝置的所有屬性。端點是一種特定類型的描述元,用於說明主機與裝置之間通訊流程的術語。
InterfaceList
類別會針對 USB 裝置中的每個 Interface
執行疊代作業。接著每個 Interface
都包含:
DescriptorList
到GetDescriptorList()
EndpointList
到GetEndpointList()
這些方法可讓您存取介面的所有描述元和端點。
這些子類別的階層請見圖 1。
圖 1
範例
接收 USB 的描述元
這些範例會反覆疊代 USB 裝置中的所有描述元。範例會疊代所有 USB 介面,然後反覆查看每個介面中的所有描述元。
以範圍為基礎的迴圈
std::optional<InterfaceList> interface_list;
status = InterfaceList::Create(my_client, true, &interface_list);
if (status != ZX_OK) {
...
}
for (auto& interface : *interface_list) {
for (auto& descriptor : interface.GetDescriptorList()) {
...
}
}
手動循環播放
std::optional<InterfaceList> interface_list;
status = InterfaceList::Create(my_client, true, &interface_list);
if (status != ZX_OK) {
...
}
for (auto& interface : *interface_list) {
auto dList_itr = interface.GetDescriptorList().begin(); // or cbegin().
do {
...
} while (++dList_itr != interface.GetDescriptorList().end());
}