internal void Add(CANPackage package) { if (InvokeRequired) { BeginInvoke(new Action<CANPackage>(Add), package); return; } if (!m_ids.ContainsKey(package.ID)) m_ids.Add(package.ID, new MatrixRow()); MatrixRow row = m_ids[package.ID]; row.Count++; row.LastPackage = package; row.LastTime = DateTime.Now; string[] subitems = package.ToStrings(row.Count); if (row.Count == 1) { // Add new row to grid ListViewItem item = new ListViewItem(subitems, 0); item.Tag = package.ID; int idx = 0; for (; idx < grid.Items.Count; idx++) { ListViewItem current = grid.Items[idx]; if (((UInt32)current.Tag) > package.ID) break; } if (idx >= grid.Items.Count) grid.Items.Add(item); else grid.Items.Insert(idx, item); } else { // Change existed grid row for (int idx = 0; idx < grid.Items.Count; idx++) { ListViewItem current = grid.Items[idx]; if (((UInt32)current.Tag) == package.ID) { // Found it and change current.SubItems[0].Text = subitems[0]; current.SubItems[1].Text = subitems[1]; current.SubItems[2].Text = subitems[2]; current.SubItems[3].Text = subitems[3]; current.SubItems[4].Text = subitems[4]; current.SubItems[5].Text = subitems[5]; current.SubItems[6].Text = subitems[6]; current.SubItems[7].Text = subitems[7]; current.SubItems[8].Text = subitems[8]; current.SubItems[9].Text = subitems[9]; current.SubItems[10].Text = subitems[10]; current.SubItems[11].Text = subitems[11]; current.SubItems[12].Text = subitems[12]; break; } } } }
private void Send_Click(object sender, EventArgs e) { CANPackage package = BuildPackage(grid.GetRow((Control)sender)); if (package != null) { MessageBox.Show("Not implemented"); } }
/// <summary> /// Send all rows /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SendAll_Click(object sender, EventArgs e) { for (int iRow = 1; iRow < grid.RowStyles.Count; iRow++) { CANPackage package = BuildPackage(iRow); if (package == null) { break; } MessageBox.Show("Not implement"); break; } }
public void Add(CANPackage package) { if (InvokeRequired) { BeginInvoke(new Action<CANPackage>(Add), package); return; } string[] subitems = package.ToStrings(); ListViewItem item = new ListViewItem(subitems, 0); if (grid.Items.Count == 0) grid.Items.Add(item); else grid.Items.Insert(0, item); }
public void Add(CANPackage package) { if (InvokeRequired) { BeginInvoke(new Action <CANPackage>(Add), package); return; } string[] subitems = package.ToStrings(); ListViewItem item = new ListViewItem(subitems, 0); if (grid.Items.Count == 0) { grid.Items.Add(item); } else { grid.Items.Insert(0, item); } }
internal void Add(CANPackage package) { if (InvokeRequired) { BeginInvoke(new Action <CANPackage>(Add), package); return; } if (!m_ids.ContainsKey(package.ID)) { m_ids.Add(package.ID, new MatrixRow()); } MatrixRow row = m_ids[package.ID]; row.Count++; row.LastPackage = package; row.LastTime = DateTime.Now; string[] subitems = package.ToStrings(row.Count); if (row.Count == 1) { // Add new row to grid ListViewItem item = new ListViewItem(subitems, 0); item.Tag = package.ID; int idx = 0; for (; idx < grid.Items.Count; idx++) { ListViewItem current = grid.Items[idx]; if (((UInt32)current.Tag) > package.ID) { break; } } if (idx >= grid.Items.Count) { grid.Items.Add(item); } else { grid.Items.Insert(idx, item); } } else { // Change existed grid row for (int idx = 0; idx < grid.Items.Count; idx++) { ListViewItem current = grid.Items[idx]; if (((UInt32)current.Tag) == package.ID) { // Found it and change current.SubItems[0].Text = subitems[0]; current.SubItems[1].Text = subitems[1]; current.SubItems[2].Text = subitems[2]; current.SubItems[3].Text = subitems[3]; current.SubItems[4].Text = subitems[4]; current.SubItems[5].Text = subitems[5]; current.SubItems[6].Text = subitems[6]; current.SubItems[7].Text = subitems[7]; current.SubItems[8].Text = subitems[8]; current.SubItems[9].Text = subitems[9]; current.SubItems[10].Text = subitems[10]; current.SubItems[11].Text = subitems[11]; current.SubItems[12].Text = subitems[12]; break; } } } }
/// <summary> /// Build CAN package from Row /// </summary> /// <param name="iRow"></param> /// <returns></returns> private CANPackage BuildPackage(int iRow) { List <Control> controls = GetRowControls(null, Controls, iRow); CANPackage package = new CANPackage(); package.Use = false; UInt32 v_base = 16; UInt32 max_id = 0x7FF; bool failed = false; SetStatus(); // Prescan controls to define values base and IDE foreach (Control c in controls) { if (c.Name == R_HEX.Name) { v_base = (UInt32)(((CheckBox)c).Checked ? 16 : 10); } else if (c.Name == R_EXT_ID.Name) { package.IdType = ((CheckBox)c).Checked ? CanIdType.CAN_ID_EXT : CanIdType.CAN_ID_STD; max_id = (package.IdType == CanIdType.CAN_ID_STD) ? 0x7FFu : 0x1FFFFFFFu; } } // Scan controls and build CAN package foreach (Control c in controls) { try { if (c.Name == R_HEX.Name) { continue; } else if (c.Name == R_ID.Name) { package.ID = ParseValue(c.Text, v_base, max_id, 0); } else if (c.Name == R_EXT_ID.Name) { continue; } else if (c.Name == R_RTR_DATA.Name) { package.FrameType = ((CheckBox)c).Checked ? CanFrameType.CAN_RTR_DATA : CanFrameType.CAN_RTR_REMOTE; } else if (c.Name == R_DLC.Name) { package.DLC = (UInt16)ParseValue(c.Text, v_base, 8, 0); } else if (c.Name == R_D0.Name) { package.Data[0] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_D1.Name) { package.Data[1] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_D2.Name) { package.Data[2] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_D3.Name) { package.Data[3] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_D4.Name) { package.Data[4] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_D5.Name) { package.Data[5] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_D6.Name) { package.Data[6] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_D7.Name) { package.Data[7] = (byte)ParseValue(c.Text, v_base, 0xFF, 0); } else if (c.Name == R_DELAY.Name) { package.Delay = ParseValue(c.Text, 10, 300000, 100); } else if (c.Name == R_COUNT.Name) { package.Count = ParseValue(c.Text, 10, 1000, 1); } else if (c.Name == R_USE.Name) { package.Use = ((CheckBox)c).Checked; } else if (c.Name == R_SEND.Name) { continue; } else { throw new Exception("Unknown row control."); } } catch (Exception ex) { SetStatus(ex.Message); c.BackColor = Color.Red; failed = true; } } if (failed) { package = null; } return(package); }
private void ParsePackage(ref string package) { if (package.Length > 1) { CANPackage pack = new CANPackage(); int i, j; switch (package[0]) { case 't': pack.FrameType = CanFrameType.CAN_RTR_DATA; pack.IdType = CanIdType.CAN_ID_STD; break; case 'T': pack.FrameType = CanFrameType.CAN_RTR_DATA; pack.IdType = CanIdType.CAN_ID_EXT; break; case 'r': pack.FrameType = CanFrameType.CAN_RTR_REMOTE; pack.IdType = CanIdType.CAN_ID_STD; break; case 'R': pack.FrameType = CanFrameType.CAN_RTR_REMOTE; pack.IdType = CanIdType.CAN_ID_EXT; break; default: return; } if (pack.IdType == CanIdType.CAN_ID_STD) j = 3; else if (pack.IdType == CanIdType.CAN_ID_EXT) j = 8; else return; for (i = 1; i <= j; ) { pack.ID <<= 4; pack.ID |= GetPackData(ref package, i++); } pack.DLC = (UInt16)GetPackData(ref package, i++); if (pack.DLC <= 8) { for (j = 0; j < pack.DLC; j++) { pack.Data[j] = (byte)(GetPackData(ref package, i++) << 4); pack.Data[j] |= GetPackData(ref package, i++); } } if (m_rolling != null) m_rolling.Add(pack); if (m_matrix != null) m_matrix.Add(pack); } }
private void ParsePackage(ref string package) { if (package.Length > 1) { CANPackage pack = new CANPackage(); int i, j; switch (package[0]) { case 't': pack.FrameType = CanFrameType.CAN_RTR_DATA; pack.IdType = CanIdType.CAN_ID_STD; break; case 'T': pack.FrameType = CanFrameType.CAN_RTR_DATA; pack.IdType = CanIdType.CAN_ID_EXT; break; case 'r': pack.FrameType = CanFrameType.CAN_RTR_REMOTE; pack.IdType = CanIdType.CAN_ID_STD; break; case 'R': pack.FrameType = CanFrameType.CAN_RTR_REMOTE; pack.IdType = CanIdType.CAN_ID_EXT; break; default: return; } if (pack.IdType == CanIdType.CAN_ID_STD) { j = 3; } else if (pack.IdType == CanIdType.CAN_ID_EXT) { j = 8; } else { return; } for (i = 1; i <= j;) { pack.ID <<= 4; pack.ID |= GetPackData(ref package, i++); } pack.DLC = (UInt16)GetPackData(ref package, i++); if (pack.DLC <= 8) { for (j = 0; j < pack.DLC; j++) { pack.Data[j] = (byte)(GetPackData(ref package, i++) << 4); pack.Data[j] |= GetPackData(ref package, i++); } } if (m_rolling != null) { m_rolling.Add(pack); } if (m_matrix != null) { m_matrix.Add(pack); } } }