Community Translation - Accessing Multiple USB-Serial Devices using the Device Instance Path – KBA228257

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
yasa_4608926
Level 4
Level 4
Distributor - Marubun (Japan)
250 sign-ins 5 solutions authored 25 replies posted

Hi,

I tried to translate this KBA228257 into Japanese.

Accessing Multiple USB-Serial Devices using the Device Instance Path – KBA228257

Accessing Multiple USB-Serial Devices using the Device Instance Path – KBA228257

=========================

タイトル:

デバイス インスタンス パスを使用した複数のUSBシリアル デバイスへのアクセス

バージョン: **

質問:

複数のデバイスが接続されている場合、どうすればUSBシリアル デバイスにアクセスできますか?

回答:

ベンダーモードでI2C、SPI、またはUARTとしてコンフィグレーションされたUSBシリアル製品がUSBホストへ接続されている場合、コンフィグレーションに基づいて1つ以上のデバイスがエニュメレートされます。

Windows OSは、デバイス エニュメレーション プロセス中に各デバイスに特定のデバイス エニュメレーション インデックスを割り当てます。また、このUSBデバイス エニュメレーション プロセスは、すべてのUSBデバイスに対して一意のデバイス インスタンス パスを作成します。このデバイス インスタンス パスを使用して、この記事で明示されている関数のように、デバイスのインスタンス パスをそれぞれのデバイス エニュメレーション インデックスにマッピングすることにより、同じVIDとPIDを持つデバイスを区別できます。

以下で明示されている GetDevicePath() 関数は、CyOpen および CyGetDeviceInfo API と同様、パラメータとしてサイプレス デバイスのデバイス エニュメレーション インデックスを持っており、Windows APIを使用してそのデバイスのデバイス インスタンス パスを出力します。

注: setupapi ライブラリはプロジェクトにリンクする必要があります。プロパティページ → Linker → Input → Additional Dependencies に setupapi.lib を追加することでリンクできます。

コード:

// Additional header file to be added

#include <setupapi.h>

// GetDevicePath Function

void GetDevicePath(int deviceNumber)

{

       //Initialization

       GUID CyDrvGuid = { 0xae18aa60, 0x7f6a, 0x11d4, 0x97, 0xdd, 0x0, 0x1, 0x2, 0x29, 0xb9, 0x59 };   // cyusb3 guid

       SP_DEVINFO_DATA devInfoData;

       SP_DEVICE_INTERFACE_DATA  devInterfaceData;

       PSP_INTERFACE_DEVICE_DETAIL_DATA functionClassDeviceData;

       ULONG requiredLength = 0;

       HDEVINFO hwDeviceInfo = SetupDiGetClassDevs((LPGUID)& CyDrvGuid,   //Returns a handle to the device information set

              NULL,

              NULL,

              DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

       if (hwDeviceInfo != INVALID_HANDLE_VALUE) { //checks if the handle is invalid

              devInterfaceData.cbSize = sizeof(devInterfaceData);         //get the size of devInterfaceData structure

              //enumerates the device interfaces that are contained in a device information set

              if (SetupDiEnumDeviceInterfaces(hwDeviceInfo, 0, (LPGUID)& CyDrvGuid,     

                     deviceNumber, &devInterfaceData)) {                                   

                     SetupDiGetInterfaceDeviceDetail(hwDeviceInfo, &devInterfaceData, NULL, 0,

                     &requiredLength, NULL);

                     ULONG predictedLength = requiredLength;

                     functionClassDeviceData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(predictedLength);

                     functionClassDeviceData->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);

                     devInfoData.cbSize = sizeof(devInfoData);

                     //Retrieve the information from Plug and Play including the device path

                     if (SetupDiGetInterfaceDeviceDetail(hwDeviceInfo,

                   &devInterfaceData,

                   functionClassDeviceData,

                   predictedLength,

                   &requiredLength,

                   &devInfoData)) {

                   wprintf(L"%ls\n", functionClassDeviceData->DevicePath); //Prints the device path of the required device

                     }

              }

       }

       SetupDiDestroyDeviceInfoList(hwDeviceInfo);

}

=========================

0 Likes
1 Reply
JennaJo
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello,

We receive your translation, it will be published to KBA to Community.

After upload, You will receive the points as the word of KBA.

Due to the current delay of processed work, Please bear with me for the delayed the response.

It could be delayed, but it will be processed soon.

Thanks for your contribution to CDC!

Will keep you update the status.

Thanks,

Jenna Jo

Jenna Jo
0 Likes