私は、データ パイプを介してコマンドを受け取り、コマンド自体と同じ長さのコマンド パケットのみを受け入れるデバイス (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() からエラーが発生します。
任意のサイズのデバイスにデータを渡す方法はありますか? ご協力いただきありがとうございます。