コード例 #1
0
ファイル: Form1.cs プロジェクト: betaEncoder/fav-button
 private void parseReport(hidReport report)
 {
     commandList.Clear();
     for (int i = 1; i < REPORT_PAYLOAD_SIZE; i += 10)
     {
         command temp = new command();
         for (int j = 0; j < 10; j++)
         {
             if (j == 0)
             {
                 temp.length = (byte)report.data[i + j];
                 if (temp.length == 0)
                 {
                     return;
                 }
             }
             else if (j == 1)
             {
                 temp.reportID = (byte)report.data[i + j];
             }
             else
             {
                 temp.data[j - 2] = (byte)report.data[i + j];
             }
         }
         commandList.Add(temp);
     }
 }
コード例 #2
0
ファイル: hidWrapper.cs プロジェクト: betaEncoder/fav-button
            public uint getReport(ref hidReport report)
            {
                uint written = 0;
                bool result  = ReadFile(
                    fileHandle,
                    report.data,
                    report.length,
                    ref written,
                    IntPtr.Zero);

                return(written);
            }
コード例 #3
0
ファイル: hidWrapper.cs プロジェクト: betaEncoder/fav-button
            public uint sendReport(hidReport report)
            {
                uint written = 0;
                bool result  = WriteFile(
                    fileHandle,
                    report.data,
                    report.length,
                    ref written,
                    IntPtr.Zero);

                return(written);
            }
コード例 #4
0
ファイル: Form1.cs プロジェクト: betaEncoder/fav-button
        private void buttonWrite_Click(object sender, EventArgs e)
        {
            report         = new hidReport(REPORT_PAYLOAD_SIZE + 1);
            report.data[0] = REPORT_ID;
            report.data[1] = QUEUE_WRITE;

            // 送信データの組み立て
            for (int i = 0; i < commandList.Count; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (j == 0)
                    {
                        report.data[i * 10 + j + 2] = ((command)commandList[i]).length;
                    }
                    else if (j == 1)
                    {
                        report.data[i * 10 + j + 2] = ((command)commandList[i]).reportID;
                    }
                    else
                    {
                        report.data[i * 10 + j + 2] = ((command)commandList[i]).data[j - 2];
                    }
                }
            }

            uint size = hid.devices[comboBoxDevices.SelectedIndex].sendReport(report);

            if (size == 0)
            {
                MessageBox.Show("データ送信に失敗しました");
                return;
            }
            size = hid.devices[comboBoxDevices.SelectedIndex].getReport(ref report);
            if (size == 0)
            {
                MessageBox.Show("書込結果の受信に失敗しました");
                return;
            }
            if (report.data[1] == 0)
            {
                MessageBox.Show("書き込みに成功しました");
            }
            else
            {
                MessageBox.Show("書き込みに失敗しました");
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: betaEncoder/fav-button
        private void comboBoxDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            report         = new hidReport(REPORT_PAYLOAD_SIZE + 1);
            report.data[0] = REPORT_ID;
            report.data[1] = QUEUE_READ;
            uint size = hid.devices[comboBoxDevices.SelectedIndex].sendReport(report);

            if (size == 0)
            {
                MessageBox.Show("データ取得要求の送信に失敗しました");
                return;
            }

            size = hid.devices[comboBoxDevices.SelectedIndex].getReport(ref report);
            if (size == 0)
            {
                MessageBox.Show("データ取得に失敗しました");
                return;
            }

            parseReport(report);
            refreshListBox();
            buttonAdd.Enabled = true;
        }