2

私は、データ パイプを介してコマンドを受け取り、コマンド自体と同じ長さのコマンド パケットのみを受け入れるデバイス (wiimote) を使用しています。たとえば、次を受け入れます。

0x11 0x10

しかし、それは受け入れません:

0x11 0x10 0x00 0x00 0x00 ... etc.

Windows 上の WriteFile() には、渡される byte[] が少なくとも caps.OutputReportByteLength と同じ長さである必要があるため、これは Windows の問題です。この制限がない Mac では、私のコードは正しく動作します。この問題を引き起こす hid.c のコードは次のとおりです。

/* Make sure the right number of bytes are passed to WriteFile. Windows
   expects the number of bytes which are in the _longest_ report (plus
   one for the report number) bytes even if the data is a report
   which is shorter than that. Windows gives us this value in
   caps.OutputReportByteLength. If a user passes in fewer bytes than this,
   create a temporary buffer which is the proper size. */
if (length >= dev->output_report_length) {
    /* The user passed the right number of bytes. Use the buffer as-is. */
    buf = (unsigned char *) data;
} else {
    /* Create a temporary buffer and copy the user's data
       into it, padding the rest with zeros. */
    buf = (unsigned char *) malloc(dev->output_report_length);
    memcpy(buf, data, length);
    memset(buf + length, 0, dev->output_report_length - length);
    length = dev->output_report_length;
}
res = WriteFile(dev->device_handle, buf, length, NULL, &ol);

コメントに記載されているように、上記のコードを削除すると、WriteFile() からエラーが発生します。

任意のサイズのデバイスにデータを渡す方法はありますか? ご協力いただきありがとうございます。

4

1 に答える 1

1

解決しました。私は、Wii エミュレーターであるDolphinの担当者と同様のソリューションを使用しました。どうやら、Microsoft bluetooth スタックでは、WriteFile() が正しく機能せず、Wiimote がエラーを返す原因となっているようです。MS スタックで HidD_SetOutputReport() を使用し、BlueSoleil スタックで WriteFile() を使用することで、(少なくとも私のマシンでは) デバイスに正常に接続できました。

BlueSoleil スタックでこれをテストしたことはありませんが、Dolphin はこの方法を使用しているため、動作すると言っても過言ではありません。

この修正の醜い実装を含む要点は次のとおりです: https://gist.github.com/Flafla2/d261a156ea2e3e3c1e5c

于 2015-04-10T02:21:42.723 に答える