private void btn_send_interrupt_Click(object sender, EventArgs e) { int itemCount = 0; int itemNo = LstReadyCmd.SelectedIndex; if (itemNo >= 0 && _deviceHandleObtained && timerFlag != true) { btn_send.Enabled = false; LstReadyCmd.Enabled = false; //Lock to Item that Selected var output_Buffer = new Byte[recordWaitDataNum[itemNo]]; FieldCount field = Field_Count(recordWaitDataNum[itemNo]); //recordWaitDataNum[itemNo] is continuous bytes of number that is selected in listbox. for (int j = 0; j < field.ColumnNum + field.columnShift; j++) { if (field.ColumnMod == 0 || (field.mutiFlag == true && j < field.ColumnNum)) { for (int i = 0; i < ROW_NUM; i++, itemCount++) { output_Buffer[itemCount] = Convert.ToByte(sendWaitData[itemNo, Convert.ToInt32(textbox[i, j].Name)], 16);//textbox[i, j].Name is same as bytes of ID } } else { for (int i = 0; i < field.ColumnMod; i++, itemCount++) { output_Buffer[itemCount] = Convert.ToByte(sendWaitData[itemNo, Convert.ToInt32(textbox[i, j].Name)], 16); } } }//for SendOutputReport(output_Buffer, recordWaitDataNum[itemNo], "Interrupt"); ShowInfoToForm(FormTypes.ListBoxResult, "Send an Output report message: " + LstReadyCmd.Items[itemNo].ToString()); LstReadyCmd.Enabled = true; btn_send.Enabled = true; } }
private FieldCount Field_Count(int Number) { FieldCount _field = new FieldCount(); _field.columnShift = 0; _field.ColumnMod = 0; if (Number > ROW_NUM) { _field.mutiFlag = true; _field.ColumnNum = Number / ROW_NUM; _field.ColumnMod = Number % ROW_NUM; if (_field.ColumnMod == 0) { _field.columnShift = 0; } else { _field.columnShift = 1; } } else { _field.mutiFlag = false; _field.ColumnNum = 1; _field.columnShift = 0; _field.ColumnMod = Number % ROW_NUM; } return(_field); }
private void InitialTextBox(int Number) { FieldCount _field = Field_Count(Number); for (int j = 0; j < _field.ColumnNum + _field.columnShift; j++) { if (_field.ColumnMod == 0 || (_field.mutiFlag == true && j < _field.ColumnNum)) { for (int i = 0; i < ROW_NUM; i++) { label[i, j] = new Label(); label[i, j].Name = item_no.ToString(); label[i, j].Text = "Byte " + item_no.ToString(); label[i, j].AutoSize = true; label[i, j].Location = new Point(33 + j * X_SHIFT, Y_SHIFT * i + 2); label[i, j].Font = new System.Drawing.Font("Buxton Sketch", 10); panel1.Controls.Add(label[i, j]); textbox[i, j] = new TextBox(); textbox[i, j].Name = item_no.ToString(); textbox[i, j].Width = 50; textbox[i, j].Height = 22; textbox[i, j].Location = new Point(80 + j * X_SHIFT, Y_SHIFT * i); textbox[i, j].Font = new System.Drawing.Font("Buxton Sketch", 13); textbox[i, j].MaxLength = 2; textbox[i, j].KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBox_KeyPress); panel1.Controls.Add(textbox[i, j]); item_no++; } } else { for (int i = 0; i < _field.ColumnMod; i++) { label[i, j] = new Label(); label[i, j].Name = item_no.ToString(); label[i, j].Text = "Byte " + item_no.ToString(); label[i, j].AutoSize = true; label[i, j].Location = new Point(33 + j * X_SHIFT, Y_SHIFT * i + 2); label[i, j].Font = new System.Drawing.Font("Buxton Sketch", 10); panel1.Controls.Add(label[i, j]); textbox[i, j] = new TextBox(); textbox[i, j].Name = item_no.ToString(); textbox[i, j].Width = 50; textbox[i, j].Height = 22; textbox[i, j].Location = new Point(80 + j * X_SHIFT, Y_SHIFT * i); textbox[i, j].Font = new System.Drawing.Font("Buxton Sketch", 13); textbox[i, j].MaxLength = 2; textbox[i, j].KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBox_KeyPress); panel1.Controls.Add(textbox[i, j]); item_no++; } } } }
public static void IncrementFieldCount(Dictionary <int, FieldCount> field_counts, string name) { int hashCode = name.GetHashCode(); FieldCount value = null; if (!field_counts.TryGetValue(hashCode, out value)) { value = new FieldCount(); value.name = name; field_counts[hashCode] = value; } value.count++; }
private void btn_leftRead_Click(object sender, EventArgs e) { //object item = LstReadyCmd.SelectedItem; int itemNo = LstReadyCmd.SelectedIndex; //itemNo is item of ID that is selected item_no = 0; //One command consist of continuous bytes of ID recordWaitDateNo = itemNo; LstReadyCmd.Enabled = false; //Lock to Item that Selected if (sendWaitData_flag == true && itemNo >= 0) { Read_flag = true; panel1.Controls.Clear(); int packetLength = recordWaitDataNum[itemNo]; if (packetLength > _myHid.Capabilities.OutputReportByteLength) { packetLength = _myHid.Capabilities.OutputReportByteLength; } FieldCount field = Field_Count(packetLength);//recordWaitDataNum[itemNo] is continuous bytes of number that is selected in listbox. InitialTextBox(recordWaitDataNum[itemNo]); for (int j = 0; j < field.ColumnNum + field.columnShift; j++) { if (field.ColumnMod == 0 || (field.mutiFlag == true && j < field.ColumnNum)) { for (int i = 0; i < ROW_NUM; i++) { textbox[i, j].Text = sendWaitData[itemNo, Convert.ToInt32(textbox[i, j].Name)];//textbox[i, j].Name is same as bytes of ID } } else { for (int i = 0; i < field.ColumnMod; i++) { textbox[i, j].Text = sendWaitData[itemNo, Convert.ToInt32(textbox[i, j].Name)]; } } }//for } }