repo time

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Committer:
darienf
Date:
Tue Apr 06 06:41:40 2021 +0000
Revision:
20:6d2af70c92ab
another repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darienf 20:6d2af70c92ab 1 /*******************************************************************************
darienf 20:6d2af70c92ab 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
darienf 20:6d2af70c92ab 3 *
darienf 20:6d2af70c92ab 4 * This software is protected by copyright laws of the United States and
darienf 20:6d2af70c92ab 5 * of foreign countries. This material may also be protected by patent laws
darienf 20:6d2af70c92ab 6 * and technology transfer regulations of the United States and of foreign
darienf 20:6d2af70c92ab 7 * countries. This software is furnished under a license agreement and/or a
darienf 20:6d2af70c92ab 8 * nondisclosure agreement and may only be used or reproduced in accordance
darienf 20:6d2af70c92ab 9 * with the terms of those agreements. Dissemination of this information to
darienf 20:6d2af70c92ab 10 * any party or parties not specified in the license agreement and/or
darienf 20:6d2af70c92ab 11 * nondisclosure agreement is expressly prohibited.
darienf 20:6d2af70c92ab 12 *
darienf 20:6d2af70c92ab 13 * The above copyright notice and this permission notice shall be included
darienf 20:6d2af70c92ab 14 * in all copies or substantial portions of the Software.
darienf 20:6d2af70c92ab 15 *
darienf 20:6d2af70c92ab 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 20:6d2af70c92ab 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 20:6d2af70c92ab 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 20:6d2af70c92ab 19 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 20:6d2af70c92ab 20 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 20:6d2af70c92ab 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 20:6d2af70c92ab 22 * OTHER DEALINGS IN THE SOFTWARE.
darienf 20:6d2af70c92ab 23 *
darienf 20:6d2af70c92ab 24 * Except as contained in this notice, the name of Maxim Integrated
darienf 20:6d2af70c92ab 25 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 20:6d2af70c92ab 26 * Products, Inc. Branding Policy.
darienf 20:6d2af70c92ab 27 *
darienf 20:6d2af70c92ab 28 * The mere transfer of this software does not imply any licenses
darienf 20:6d2af70c92ab 29 * of trade secrets, proprietary technology, copyrights, patents,
darienf 20:6d2af70c92ab 30 * trademarks, maskwork rights, or any other form of intellectual
darienf 20:6d2af70c92ab 31 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 20:6d2af70c92ab 32 * ownership rights.
darienf 20:6d2af70c92ab 33 *******************************************************************************
darienf 20:6d2af70c92ab 34 */
darienf 20:6d2af70c92ab 35
darienf 20:6d2af70c92ab 36 using System;
darienf 20:6d2af70c92ab 37 using System.Collections.Generic;
darienf 20:6d2af70c92ab 38 using System.ComponentModel;
darienf 20:6d2af70c92ab 39 using System.Drawing;
darienf 20:6d2af70c92ab 40 using System.Data;
darienf 20:6d2af70c92ab 41 using System.Linq;
darienf 20:6d2af70c92ab 42 using System.Text;
darienf 20:6d2af70c92ab 43 using System.Text.RegularExpressions;
darienf 20:6d2af70c92ab 44 using System.Windows.Forms;
darienf 20:6d2af70c92ab 45 using System.IO;
darienf 20:6d2af70c92ab 46
darienf 20:6d2af70c92ab 47 using HealthSensorPlatform.DeviceDescriptions;
darienf 20:6d2af70c92ab 48 using HealthSensorPlatform.CustomControls;
darienf 20:6d2af70c92ab 49 using RPCSupport.DeviceSupport;
darienf 20:6d2af70c92ab 50 //using Maxim.MAX30101GUI.DeviceDescriptions;
darienf 20:6d2af70c92ab 51 //using Maxim.MAX30101;
darienf 20:6d2af70c92ab 52
darienf 20:6d2af70c92ab 53 namespace Maxim.CustomControls
darienf 20:6d2af70c92ab 54 {
darienf 20:6d2af70c92ab 55 public partial class RegisterView : UserControl, IDeviceView
darienf 20:6d2af70c92ab 56 {
darienf 20:6d2af70c92ab 57 private bool connected = false;
darienf 20:6d2af70c92ab 58 public bool Connected
darienf 20:6d2af70c92ab 59 {
darienf 20:6d2af70c92ab 60 get
darienf 20:6d2af70c92ab 61 {
darienf 20:6d2af70c92ab 62 return connected;
darienf 20:6d2af70c92ab 63 }
darienf 20:6d2af70c92ab 64 set
darienf 20:6d2af70c92ab 65 {
darienf 20:6d2af70c92ab 66 connected = value;
darienf 20:6d2af70c92ab 67 }
darienf 20:6d2af70c92ab 68 }
darienf 20:6d2af70c92ab 69
darienf 20:6d2af70c92ab 70 public string DeviceName;
darienf 20:6d2af70c92ab 71
darienf 20:6d2af70c92ab 72 public DeviceController Controller
darienf 20:6d2af70c92ab 73 {
darienf 20:6d2af70c92ab 74 get { return controller; }
darienf 20:6d2af70c92ab 75 }
darienf 20:6d2af70c92ab 76 private DeviceController controller;
darienf 20:6d2af70c92ab 77
darienf 20:6d2af70c92ab 78
darienf 20:6d2af70c92ab 79 /// <summary>
darienf 20:6d2af70c92ab 80 /// Value of current selected register
darienf 20:6d2af70c92ab 81 /// </summary>
darienf 20:6d2af70c92ab 82 int RegisterValue;
darienf 20:6d2af70c92ab 83
darienf 20:6d2af70c92ab 84 Label[] bitLabels = new Label[24];
darienf 20:6d2af70c92ab 85
darienf 20:6d2af70c92ab 86 Font RegularFont;
darienf 20:6d2af70c92ab 87 Font BoldFont;
darienf 20:6d2af70c92ab 88
darienf 20:6d2af70c92ab 89 public event RegisterWriteCompleteHandler RegisterWriteComplete;
darienf 20:6d2af70c92ab 90 public delegate void RegisterWriteCompleteHandler(object sender, RegisterArgs e);
darienf 20:6d2af70c92ab 91
darienf 20:6d2af70c92ab 92 public event CellBeginEditHandler CellBeginEdit;
darienf 20:6d2af70c92ab 93 public delegate void CellBeginEditHandler(object sender, DataGridViewCellCancelEventArgs e);
darienf 20:6d2af70c92ab 94
darienf 20:6d2af70c92ab 95 public RegisterView()
darienf 20:6d2af70c92ab 96 {
darienf 20:6d2af70c92ab 97 //accelDevice = new AccelDevice();
darienf 20:6d2af70c92ab 98 InitializeComponent();
darienf 20:6d2af70c92ab 99
darienf 20:6d2af70c92ab 100 // Initialize font styles for label
darienf 20:6d2af70c92ab 101 RegularFont = new Font(lblBit00.Font, FontStyle.Regular);
darienf 20:6d2af70c92ab 102 BoldFont = new Font(lblBit00.Font, FontStyle.Bold);
darienf 20:6d2af70c92ab 103
darienf 20:6d2af70c92ab 104 // References to all bit labels
darienf 20:6d2af70c92ab 105 for(int i = 0; i < 24; i++)
darienf 20:6d2af70c92ab 106 {
darienf 20:6d2af70c92ab 107 string labelName = "lblBit" + i.ToString("D2");
darienf 20:6d2af70c92ab 108 bitLabels[i] = (Label)panelRegisterBits.Controls[labelName];
darienf 20:6d2af70c92ab 109 }
darienf 20:6d2af70c92ab 110
darienf 20:6d2af70c92ab 111 dgv_Registers.CellBeginEdit += OnCellBeginEdit; // Pass thru event
darienf 20:6d2af70c92ab 112 dgv_Registers.SelectionChanged += dgv_Registers_SelectionChanged;
darienf 20:6d2af70c92ab 113 dgv_Registers.CellEndEdit += dgv_Registers_CellEndEdit;
darienf 20:6d2af70c92ab 114 }
darienf 20:6d2af70c92ab 115
darienf 20:6d2af70c92ab 116 public void SetController(DeviceController controller)
darienf 20:6d2af70c92ab 117 {
darienf 20:6d2af70c92ab 118 Clear();
darienf 20:6d2af70c92ab 119 this.controller = controller;
darienf 20:6d2af70c92ab 120 }
darienf 20:6d2af70c92ab 121
darienf 20:6d2af70c92ab 122 /// <summary>
darienf 20:6d2af70c92ab 123 /// RegisterInfo register value to string
darienf 20:6d2af70c92ab 124 /// </summary>
darienf 20:6d2af70c92ab 125 /// <param name="reg"></param>
darienf 20:6d2af70c92ab 126 /// <returns></returns>
darienf 20:6d2af70c92ab 127 private string FormatData(RegisterInfo reg)
darienf 20:6d2af70c92ab 128 {
darienf 20:6d2af70c92ab 129 return reg.dataField.ToString("X" + (reg.numBytes * 2).ToString());
darienf 20:6d2af70c92ab 130 }
darienf 20:6d2af70c92ab 131
darienf 20:6d2af70c92ab 132 /// <summary>
darienf 20:6d2af70c92ab 133 /// Populate register tables
darienf 20:6d2af70c92ab 134 /// </summary>
darienf 20:6d2af70c92ab 135 public void DisplayRegisters()
darienf 20:6d2af70c92ab 136 {
darienf 20:6d2af70c92ab 137 if (dgv_Registers.RowCount == 0)
darienf 20:6d2af70c92ab 138 {
darienf 20:6d2af70c92ab 139 //add rows to table
darienf 20:6d2af70c92ab 140 foreach (RegisterInfo reg in controller.InfoArray)
darienf 20:6d2af70c92ab 141 {
darienf 20:6d2af70c92ab 142 //get the number of bytes of the register
darienf 20:6d2af70c92ab 143 int numBytes = reg.numBytes;
darienf 20:6d2af70c92ab 144
darienf 20:6d2af70c92ab 145 String dataStr = FormatData(reg);
darienf 20:6d2af70c92ab 146 //add a row to the table with the register address, name, and value
darienf 20:6d2af70c92ab 147 dgv_Registers.Rows.Add(reg.address.ToString("X2") + "h", reg.detailedName, dataStr);
darienf 20:6d2af70c92ab 148 }
darienf 20:6d2af70c92ab 149
darienf 20:6d2af70c92ab 150 //resize length of table to the number of rows
darienf 20:6d2af70c92ab 151 if (dgv_Registers.RowCount > 8)
darienf 20:6d2af70c92ab 152 {
darienf 20:6d2af70c92ab 153 dgv_Registers.Height = (dgv_Registers.RowCount - 1) * 23 + 42;
darienf 20:6d2af70c92ab 154 dgv_RegDes.Height = dgv_Registers.Height;
darienf 20:6d2af70c92ab 155 }
darienf 20:6d2af70c92ab 156 else
darienf 20:6d2af70c92ab 157 {
darienf 20:6d2af70c92ab 158 dgv_Registers.Height = 7 * 23 + 42;
darienf 20:6d2af70c92ab 159 dgv_RegDes.Height = dgv_Registers.Height;
darienf 20:6d2af70c92ab 160 }
darienf 20:6d2af70c92ab 161 }
darienf 20:6d2af70c92ab 162 else //the table has already been populated with rows
darienf 20:6d2af70c92ab 163 {
darienf 20:6d2af70c92ab 164 //update the value column with the new value in the ADC registers
darienf 20:6d2af70c92ab 165 for (int i = 0; i < dgv_Registers.Rows.Count; i++)
darienf 20:6d2af70c92ab 166 {
darienf 20:6d2af70c92ab 167 RegisterInfo reg = controller.InfoArray[i];
darienf 20:6d2af70c92ab 168 int numBytes = reg.numBytes;
darienf 20:6d2af70c92ab 169 String dataStr = FormatData(reg);
darienf 20:6d2af70c92ab 170 //add a row to the table with the register address, name, and value
darienf 20:6d2af70c92ab 171 dgv_Registers[col_Value.Index, i].Value = dataStr;
darienf 20:6d2af70c92ab 172 }
darienf 20:6d2af70c92ab 173 }
darienf 20:6d2af70c92ab 174 }
darienf 20:6d2af70c92ab 175
darienf 20:6d2af70c92ab 176 public void Clear()
darienf 20:6d2af70c92ab 177 {
darienf 20:6d2af70c92ab 178 dgv_Registers.Rows.Clear();
darienf 20:6d2af70c92ab 179 dgv_Registers.Refresh();
darienf 20:6d2af70c92ab 180 }
darienf 20:6d2af70c92ab 181
darienf 20:6d2af70c92ab 182 public string RegistersToString()
darienf 20:6d2af70c92ab 183 {
darienf 20:6d2af70c92ab 184 //RegisterProcess registerProcess;
darienf 20:6d2af70c92ab 185 StringBuilder sb = new StringBuilder();
darienf 20:6d2af70c92ab 186 string dataStr;
darienf 20:6d2af70c92ab 187 string[][] bitDescriptions;
darienf 20:6d2af70c92ab 188 int longestRow;
darienf 20:6d2af70c92ab 189
darienf 20:6d2af70c92ab 190 //registerProcess = new RegisterProcess(controller.InfoArray);
darienf 20:6d2af70c92ab 191
darienf 20:6d2af70c92ab 192 bitDescriptions = new string[controller.InfoArray.Length + 4][];
darienf 20:6d2af70c92ab 193
darienf 20:6d2af70c92ab 194 UpdateRegisterIndexWidth();
darienf 20:6d2af70c92ab 195
darienf 20:6d2af70c92ab 196 // Generate register data to string
darienf 20:6d2af70c92ab 197 for (int i = 0; i < controller.InfoArray.Length; i++)
darienf 20:6d2af70c92ab 198 {
darienf 20:6d2af70c92ab 199 RegisterInfo reg = controller.InfoArray[i];
darienf 20:6d2af70c92ab 200
darienf 20:6d2af70c92ab 201 bitDescriptions[i] = new string[reg.description.list.Count];
darienf 20:6d2af70c92ab 202
darienf 20:6d2af70c92ab 203 for (int k = 0; k < reg.description.list.Count; k++)
darienf 20:6d2af70c92ab 204 {
darienf 20:6d2af70c92ab 205 RegisterBitDescriptions.RegisterBitDescription b = reg.description.list[k];
darienf 20:6d2af70c92ab 206 int bitValue = (reg.dataField >> b.Index) & ((1 << b.Width) - 1); // MAX30001 only
darienf 20:6d2af70c92ab 207 bitDescriptions[i][k] = b.name + " = " + bitValue.ToString("X") + "h";
darienf 20:6d2af70c92ab 208 }
darienf 20:6d2af70c92ab 209 }
darienf 20:6d2af70c92ab 210
darienf 20:6d2af70c92ab 211 // Find longest row for how deep to loop to print out all registers bits
darienf 20:6d2af70c92ab 212 longestRow = controller.InfoArray.Length + 1;
darienf 20:6d2af70c92ab 213 for (int j = 0; j < controller.InfoArray.Length; j++ )
darienf 20:6d2af70c92ab 214 {
darienf 20:6d2af70c92ab 215 if (controller.InfoArray[j].description.list.Count > longestRow)
darienf 20:6d2af70c92ab 216 {
darienf 20:6d2af70c92ab 217 longestRow = controller.InfoArray[j].description.list.Count + 1;
darienf 20:6d2af70c92ab 218 }
darienf 20:6d2af70c92ab 219 }
darienf 20:6d2af70c92ab 220
darienf 20:6d2af70c92ab 221 for (int i = 0; i < longestRow; i++)
darienf 20:6d2af70c92ab 222 {
darienf 20:6d2af70c92ab 223 if (i < controller.InfoArray.Length) // register map
darienf 20:6d2af70c92ab 224 {
darienf 20:6d2af70c92ab 225 RegisterInfo reg = controller.InfoArray[i];
darienf 20:6d2af70c92ab 226
darienf 20:6d2af70c92ab 227 dataStr = FormatData(reg);
darienf 20:6d2af70c92ab 228
darienf 20:6d2af70c92ab 229 sb.Append(this.DeviceName);
darienf 20:6d2af70c92ab 230 sb.Append(", ");
darienf 20:6d2af70c92ab 231 sb.Append(reg.address.ToString("X2"));
darienf 20:6d2af70c92ab 232 sb.Append("h, ");
darienf 20:6d2af70c92ab 233 sb.Append(reg.detailedName);
darienf 20:6d2af70c92ab 234 sb.Append(", ");
darienf 20:6d2af70c92ab 235 sb.Append(dataStr);
darienf 20:6d2af70c92ab 236 sb.Append("h");
darienf 20:6d2af70c92ab 237 sb.Append(", ");
darienf 20:6d2af70c92ab 238 sb.Append(", ");
darienf 20:6d2af70c92ab 239 }
darienf 20:6d2af70c92ab 240 else // finished with register map, just have descriptions
darienf 20:6d2af70c92ab 241 {
darienf 20:6d2af70c92ab 242 sb.Append(", ");
darienf 20:6d2af70c92ab 243 sb.Append(", ");
darienf 20:6d2af70c92ab 244 sb.Append(", ");
darienf 20:6d2af70c92ab 245 sb.Append(", ");
darienf 20:6d2af70c92ab 246 sb.Append(", ");
darienf 20:6d2af70c92ab 247 }
darienf 20:6d2af70c92ab 248
darienf 20:6d2af70c92ab 249 if (i == 0) // Register name and values
darienf 20:6d2af70c92ab 250 {
darienf 20:6d2af70c92ab 251 for (int k = 0; k < controller.InfoArray.Length; k++)
darienf 20:6d2af70c92ab 252 {
darienf 20:6d2af70c92ab 253 if (controller.InfoArray[k].type != RegisterInfo.RegisterType.WriteOnly)
darienf 20:6d2af70c92ab 254 {
darienf 20:6d2af70c92ab 255 sb.Append(controller.InfoArray[k].name);
darienf 20:6d2af70c92ab 256 sb.Append(" = ");
darienf 20:6d2af70c92ab 257 sb.Append(FormatData(controller.InfoArray[k]));
darienf 20:6d2af70c92ab 258 sb.Append("h");
darienf 20:6d2af70c92ab 259 sb.Append(", ");
darienf 20:6d2af70c92ab 260 }
darienf 20:6d2af70c92ab 261 }
darienf 20:6d2af70c92ab 262 }
darienf 20:6d2af70c92ab 263 else // descriptions
darienf 20:6d2af70c92ab 264 {
darienf 20:6d2af70c92ab 265 for (int k = 0; k < controller.InfoArray.Length; k++)
darienf 20:6d2af70c92ab 266 {
darienf 20:6d2af70c92ab 267 if (controller.InfoArray[k].type != RegisterInfo.RegisterType.WriteOnly)
darienf 20:6d2af70c92ab 268 {
darienf 20:6d2af70c92ab 269 if (i - 1 < bitDescriptions[k].Length)
darienf 20:6d2af70c92ab 270 {
darienf 20:6d2af70c92ab 271 sb.Append(bitDescriptions[k][i - 1]);
darienf 20:6d2af70c92ab 272 }
darienf 20:6d2af70c92ab 273 sb.Append(',');
darienf 20:6d2af70c92ab 274 }
darienf 20:6d2af70c92ab 275 }
darienf 20:6d2af70c92ab 276 }
darienf 20:6d2af70c92ab 277 sb.Append(Environment.NewLine);
darienf 20:6d2af70c92ab 278 }
darienf 20:6d2af70c92ab 279
darienf 20:6d2af70c92ab 280 /*
darienf 20:6d2af70c92ab 281 foreach(RegisterInfo reg in controller.InfoArray)
darienf 20:6d2af70c92ab 282 {
darienf 20:6d2af70c92ab 283 if (reg.address == 1 || reg.address == 8 || reg.address == 9 || reg.address == 10)
darienf 20:6d2af70c92ab 284 continue;
darienf 20:6d2af70c92ab 285
darienf 20:6d2af70c92ab 286 sb.Append("% ");
darienf 20:6d2af70c92ab 287 sb.Append(reg.name);
darienf 20:6d2af70c92ab 288 sb.Append(" (");
darienf 20:6d2af70c92ab 289 sb.Append(reg.address.ToString("X2"));
darienf 20:6d2af70c92ab 290 sb.Append("h)");
darienf 20:6d2af70c92ab 291 sb.Append(" = ");
darienf 20:6d2af70c92ab 292 sb.Append(FormatData(reg));
darienf 20:6d2af70c92ab 293 sb.Append("h\n");
darienf 20:6d2af70c92ab 294
darienf 20:6d2af70c92ab 295 foreach(RegisterBitDescriptions.RegisterBitDescription b in reg.description.list)
darienf 20:6d2af70c92ab 296 {
darienf 20:6d2af70c92ab 297 int bitValue = (RegisterData(reg) >> b.Index) & ((1 << b.Width) - 1); // MAX30001 only
darienf 20:6d2af70c92ab 298 sb.Append("% ");
darienf 20:6d2af70c92ab 299 sb.Append(b.name);
darienf 20:6d2af70c92ab 300 sb.Append(" = ");
darienf 20:6d2af70c92ab 301 sb.Append(bitValue.ToString("X"));
darienf 20:6d2af70c92ab 302 sb.Append("h\n");
darienf 20:6d2af70c92ab 303 }
darienf 20:6d2af70c92ab 304 }
darienf 20:6d2af70c92ab 305 */
darienf 20:6d2af70c92ab 306 return sb.ToString().TrimEnd(Environment.NewLine.ToCharArray());
darienf 20:6d2af70c92ab 307 }
darienf 20:6d2af70c92ab 308
darienf 20:6d2af70c92ab 309 /// <summary>
darienf 20:6d2af70c92ab 310 /// Register selection change display register description and update display bits
darienf 20:6d2af70c92ab 311 /// </summary>
darienf 20:6d2af70c92ab 312 /// <param name="sender"></param>
darienf 20:6d2af70c92ab 313 /// <param name="e"></param>
darienf 20:6d2af70c92ab 314 private void dgv_Registers_SelectionChanged(object sender, EventArgs e)
darienf 20:6d2af70c92ab 315 {
darienf 20:6d2af70c92ab 316 UpdateRegisters();
darienf 20:6d2af70c92ab 317 }
darienf 20:6d2af70c92ab 318
darienf 20:6d2af70c92ab 319 private void UpdateRegisters()
darienf 20:6d2af70c92ab 320 {
darienf 20:6d2af70c92ab 321 //get the index of the row selected
darienf 20:6d2af70c92ab 322 int row = dgv_Registers.CurrentRow.Index;
darienf 20:6d2af70c92ab 323
darienf 20:6d2af70c92ab 324 //make sure there is bit description info and then display it
darienf 20:6d2af70c92ab 325 if (controller.InfoArray[row].description != null)
darienf 20:6d2af70c92ab 326 {
darienf 20:6d2af70c92ab 327 lbl_bitDes.Text = "Bit Description: " + controller.InfoArray[row].name + " Register";
darienf 20:6d2af70c92ab 328 UpdateRegisterDesTable(controller.InfoArray[row].description);
darienf 20:6d2af70c92ab 329 RegisterValue = Int32.Parse((string)(dgv_Registers[2, row].Value), System.Globalization.NumberStyles.HexNumber);
darienf 20:6d2af70c92ab 330 UpdateRegisterBits(controller.InfoArray[row].description, RegisterValue);
darienf 20:6d2af70c92ab 331 }
darienf 20:6d2af70c92ab 332 }
darienf 20:6d2af70c92ab 333
darienf 20:6d2af70c92ab 334 /// <summary>
darienf 20:6d2af70c92ab 335 /// Fill register description table
darienf 20:6d2af70c92ab 336 /// </summary>
darienf 20:6d2af70c92ab 337 /// <param name="bitsDes"></param>
darienf 20:6d2af70c92ab 338 public void UpdateRegisterDesTable(RegisterBitDescriptions bitsDes)
darienf 20:6d2af70c92ab 339 {
darienf 20:6d2af70c92ab 340 //int numBits = bitsDes.Count;
darienf 20:6d2af70c92ab 341
darienf 20:6d2af70c92ab 342 dgv_RegDes.Rows.Clear();
darienf 20:6d2af70c92ab 343
darienf 20:6d2af70c92ab 344 foreach (RegisterBitDescriptions.RegisterBitDescription b in bitsDes.list)
darienf 20:6d2af70c92ab 345 {
darienf 20:6d2af70c92ab 346 dgv_RegDes.Rows.Add(b.bit, b.name, b.description);
darienf 20:6d2af70c92ab 347 }
darienf 20:6d2af70c92ab 348
darienf 20:6d2af70c92ab 349 }
darienf 20:6d2af70c92ab 350
darienf 20:6d2af70c92ab 351 public void UpdateRegisterBits()
darienf 20:6d2af70c92ab 352 {
darienf 20:6d2af70c92ab 353 int row;
darienf 20:6d2af70c92ab 354
darienf 20:6d2af70c92ab 355 if (dgv_Registers.CurrentRow != null)
darienf 20:6d2af70c92ab 356 {
darienf 20:6d2af70c92ab 357 row = dgv_Registers.CurrentRow.Index;
darienf 20:6d2af70c92ab 358
darienf 20:6d2af70c92ab 359 if (controller.InfoArray[row].description != null)
darienf 20:6d2af70c92ab 360 {
darienf 20:6d2af70c92ab 361 RegisterValue = Int32.Parse((string)(dgv_Registers[2, row].Value), System.Globalization.NumberStyles.HexNumber);
darienf 20:6d2af70c92ab 362 UpdateRegisterBits(controller.InfoArray[row].description, RegisterValue);
darienf 20:6d2af70c92ab 363 }
darienf 20:6d2af70c92ab 364 }
darienf 20:6d2af70c92ab 365 }
darienf 20:6d2af70c92ab 366
darienf 20:6d2af70c92ab 367 public void UpdateRegisterIndexWidth()
darienf 20:6d2af70c92ab 368 {
darienf 20:6d2af70c92ab 369 RegisterInfo[] info = controller.InfoArray;
darienf 20:6d2af70c92ab 370
darienf 20:6d2af70c92ab 371 foreach(RegisterInfo regInfo in info) // Registers
darienf 20:6d2af70c92ab 372 {
darienf 20:6d2af70c92ab 373 foreach (RegisterBitDescriptions.RegisterBitDescription b in regInfo.description.list) // Bits
darienf 20:6d2af70c92ab 374 {
darienf 20:6d2af70c92ab 375 string[] numbers = Regex.Split(b.bit, @"\D+"); // Bits [20:17]
darienf 20:6d2af70c92ab 376 string registerBitName;
darienf 20:6d2af70c92ab 377 int number1 = -1;
darienf 20:6d2af70c92ab 378 int number2 = -1;
darienf 20:6d2af70c92ab 379
darienf 20:6d2af70c92ab 380 // Find Bit Range
darienf 20:6d2af70c92ab 381 foreach (string value in numbers)
darienf 20:6d2af70c92ab 382 {
darienf 20:6d2af70c92ab 383 if (value != String.Empty)
darienf 20:6d2af70c92ab 384 {
darienf 20:6d2af70c92ab 385 if (number1 == -1) // First number found
darienf 20:6d2af70c92ab 386 number1 = Int32.Parse(value);
darienf 20:6d2af70c92ab 387 else // Second number found
darienf 20:6d2af70c92ab 388 number2 = Int32.Parse(value);
darienf 20:6d2af70c92ab 389 }
darienf 20:6d2af70c92ab 390 }
darienf 20:6d2af70c92ab 391
darienf 20:6d2af70c92ab 392 if (number2 == -1) // Single Number: single bit field (example: Bit 20)
darienf 20:6d2af70c92ab 393 {
darienf 20:6d2af70c92ab 394 b.Width = 1;
darienf 20:6d2af70c92ab 395 b.Index = number1;
darienf 20:6d2af70c92ab 396 }
darienf 20:6d2af70c92ab 397 else // Multiple Bits: multiple bit field (example: Bit [20:17])
darienf 20:6d2af70c92ab 398 {
darienf 20:6d2af70c92ab 399 registerBitName = Regex.Replace(b.name, @"\[\d+:\d+\]", String.Empty); // Remove [#.#] from bit field name
darienf 20:6d2af70c92ab 400
darienf 20:6d2af70c92ab 401 for (int i = number1; i >= number2; i--)
darienf 20:6d2af70c92ab 402 {
darienf 20:6d2af70c92ab 403 bitLabels[i].Text = registerBitName + "[" + (i - number2) + "]"; // Calculate bit field number
darienf 20:6d2af70c92ab 404 }
darienf 20:6d2af70c92ab 405
darienf 20:6d2af70c92ab 406 b.Index = number2;
darienf 20:6d2af70c92ab 407 b.Width = number1 - number2 + 1;
darienf 20:6d2af70c92ab 408
darienf 20:6d2af70c92ab 409 }
darienf 20:6d2af70c92ab 410 }
darienf 20:6d2af70c92ab 411 }
darienf 20:6d2af70c92ab 412 }
darienf 20:6d2af70c92ab 413
darienf 20:6d2af70c92ab 414 /// <summary>
darienf 20:6d2af70c92ab 415 /// Fill bit table
darienf 20:6d2af70c92ab 416 /// </summary>
darienf 20:6d2af70c92ab 417 /// <param name="bitDes"></param>
darienf 20:6d2af70c92ab 418 /// <param name="regValue"></param>
darienf 20:6d2af70c92ab 419 public void UpdateRegisterBits(RegisterBitDescriptions bitDes, int regValue)
darienf 20:6d2af70c92ab 420 {
darienf 20:6d2af70c92ab 421 // Reset Bit State
darienf 20:6d2af70c92ab 422 for (int i = 0; i < 24; i++ )
darienf 20:6d2af70c92ab 423 {
darienf 20:6d2af70c92ab 424 bitLabels[i].Text = "-";
darienf 20:6d2af70c92ab 425
darienf 20:6d2af70c92ab 426 // Set label based on bit state
darienf 20:6d2af70c92ab 427 if (((regValue >> i) & 0x01) == 0x01)
darienf 20:6d2af70c92ab 428 bitLabels[i].Font = BoldFont;
darienf 20:6d2af70c92ab 429 else
darienf 20:6d2af70c92ab 430 bitLabels[i].Font = RegularFont;
darienf 20:6d2af70c92ab 431 }
darienf 20:6d2af70c92ab 432
darienf 20:6d2af70c92ab 433 foreach (RegisterBitDescriptions.RegisterBitDescription b in bitDes.list)
darienf 20:6d2af70c92ab 434 {
darienf 20:6d2af70c92ab 435 string[] numbers = Regex.Split(b.bit, @"\D+"); // Bits [20:17]
darienf 20:6d2af70c92ab 436 string registerBitName;
darienf 20:6d2af70c92ab 437 int number1 = -1;
darienf 20:6d2af70c92ab 438 int number2 = -1;
darienf 20:6d2af70c92ab 439
darienf 20:6d2af70c92ab 440 // Find Bit Range
darienf 20:6d2af70c92ab 441 foreach (string value in numbers)
darienf 20:6d2af70c92ab 442 {
darienf 20:6d2af70c92ab 443 if (value != String.Empty)
darienf 20:6d2af70c92ab 444 {
darienf 20:6d2af70c92ab 445 if (number1 == -1) // First number found
darienf 20:6d2af70c92ab 446 number1 = Int32.Parse(value);
darienf 20:6d2af70c92ab 447 else // Second number found
darienf 20:6d2af70c92ab 448 number2 = Int32.Parse(value);
darienf 20:6d2af70c92ab 449 }
darienf 20:6d2af70c92ab 450 }
darienf 20:6d2af70c92ab 451
darienf 20:6d2af70c92ab 452 if (number2 == -1) // Single Number: single bit field (example: Bit 20)
darienf 20:6d2af70c92ab 453 {
darienf 20:6d2af70c92ab 454 bitLabels[number1].Text = b.name;
darienf 20:6d2af70c92ab 455 }
darienf 20:6d2af70c92ab 456 else // Multiple Bits: multiple bit field (example: Bit [20:17])
darienf 20:6d2af70c92ab 457 {
darienf 20:6d2af70c92ab 458 registerBitName = Regex.Replace(b.name, @"\[\d+:\d+\]", String.Empty); // Remove [#.#] from bit field name
darienf 20:6d2af70c92ab 459
darienf 20:6d2af70c92ab 460 for (int i = number1; i >= number2; i--)
darienf 20:6d2af70c92ab 461 {
darienf 20:6d2af70c92ab 462 bitLabels[i].Text = registerBitName + "[" + (i - number2) + "]"; // Calculate bit field number
darienf 20:6d2af70c92ab 463 }
darienf 20:6d2af70c92ab 464
darienf 20:6d2af70c92ab 465 }
darienf 20:6d2af70c92ab 466 }
darienf 20:6d2af70c92ab 467 }
darienf 20:6d2af70c92ab 468
darienf 20:6d2af70c92ab 469 /// <summary>
darienf 20:6d2af70c92ab 470 /// Parse user input and write register
darienf 20:6d2af70c92ab 471 /// </summary>
darienf 20:6d2af70c92ab 472 /// <param name="sender"></param>
darienf 20:6d2af70c92ab 473 /// <param name="e"></param>
darienf 20:6d2af70c92ab 474 private void dgv_Registers_CellEndEdit(object sender, DataGridViewCellEventArgs e)
darienf 20:6d2af70c92ab 475 {
darienf 20:6d2af70c92ab 476 //check if hardware is connected
darienf 20:6d2af70c92ab 477 //if (online && !COMMConnected())
darienf 20:6d2af70c92ab 478 // return;
darienf 20:6d2af70c92ab 479
darienf 20:6d2af70c92ab 480 RegisterInfo reg = controller.InfoArray[e.RowIndex];
darienf 20:6d2af70c92ab 481 byte address = (byte)reg.address;
darienf 20:6d2af70c92ab 482 byte numBytes = (byte)reg.numBytes;
darienf 20:6d2af70c92ab 483
darienf 20:6d2af70c92ab 484 int[] data = reg.data;
darienf 20:6d2af70c92ab 485
darienf 20:6d2af70c92ab 486 string value = (string)dgv_Registers[col_Value.Index, e.RowIndex].Value;
darienf 20:6d2af70c92ab 487 string error = ValidateHexValue(value, numBytes);
darienf 20:6d2af70c92ab 488
darienf 20:6d2af70c92ab 489 if (error == "Valid")
darienf 20:6d2af70c92ab 490 {
darienf 20:6d2af70c92ab 491 //erase error text if one exist
darienf 20:6d2af70c92ab 492 if (dgv_Registers[col_Value.Index, e.RowIndex].ErrorText != String.Empty)
darienf 20:6d2af70c92ab 493 dgv_Registers[col_Value.Index, e.RowIndex].ErrorText = String.Empty;
darienf 20:6d2af70c92ab 494
darienf 20:6d2af70c92ab 495 //convert string hex to number hex
darienf 20:6d2af70c92ab 496 int hex = Int32.Parse(value, System.Globalization.NumberStyles.HexNumber);
darienf 20:6d2af70c92ab 497
darienf 20:6d2af70c92ab 498 //write value back to GUI with correct number of characters
darienf 20:6d2af70c92ab 499 dgv_Registers[col_Value.Index, e.RowIndex].Value = hex.ToString("X" + numBytes * 2);
darienf 20:6d2af70c92ab 500
darienf 20:6d2af70c92ab 501 WriteRegister(reg, hex);
darienf 20:6d2af70c92ab 502
darienf 20:6d2af70c92ab 503 if (RegisterWriteComplete != null)
darienf 20:6d2af70c92ab 504 {
darienf 20:6d2af70c92ab 505 RegisterWriteComplete(this, new RegisterArgs { Register = address });
darienf 20:6d2af70c92ab 506 }
darienf 20:6d2af70c92ab 507
darienf 20:6d2af70c92ab 508 }
darienf 20:6d2af70c92ab 509 else//value is not valid
darienf 20:6d2af70c92ab 510 {
darienf 20:6d2af70c92ab 511 byte zero = 0;
darienf 20:6d2af70c92ab 512 dgv_Registers[col_Value.Index, e.RowIndex].Value = zero.ToString("X" + numBytes * 2); //enter zeros with correct number of characters
darienf 20:6d2af70c92ab 513 dgv_Registers[col_Value.Index, e.RowIndex].ErrorText = error; //add error text
darienf 20:6d2af70c92ab 514 }
darienf 20:6d2af70c92ab 515
darienf 20:6d2af70c92ab 516 UpdateRegisters();
darienf 20:6d2af70c92ab 517 }
darienf 20:6d2af70c92ab 518
darienf 20:6d2af70c92ab 519 /// <summary>
darienf 20:6d2af70c92ab 520 /// Write data to register
darienf 20:6d2af70c92ab 521 /// </summary>
darienf 20:6d2af70c92ab 522 /// <param name="reg"></param>
darienf 20:6d2af70c92ab 523 /// <param name="hex"></param>
darienf 20:6d2af70c92ab 524 public void WriteRegister(RegisterInfo reg, int hex)
darienf 20:6d2af70c92ab 525 {
darienf 20:6d2af70c92ab 526 byte numBytes = (byte)reg.numBytes;
darienf 20:6d2af70c92ab 527 int[] data = reg.data;
darienf 20:6d2af70c92ab 528
darienf 20:6d2af70c92ab 529 switch (numBytes)
darienf 20:6d2af70c92ab 530 {
darienf 20:6d2af70c92ab 531 case 4:
darienf 20:6d2af70c92ab 532 data[0] = (byte)(hex >> 24);
darienf 20:6d2af70c92ab 533 data[1] = (byte)(hex >> 16);
darienf 20:6d2af70c92ab 534 data[2] = (byte)(hex >> 8);
darienf 20:6d2af70c92ab 535 data[3] = (byte)hex;
darienf 20:6d2af70c92ab 536 break;
darienf 20:6d2af70c92ab 537 case 3:
darienf 20:6d2af70c92ab 538 hex &= 0x00FFFFFF;//clear bits not used
darienf 20:6d2af70c92ab 539 data[0] = (byte)(hex >> 16);
darienf 20:6d2af70c92ab 540 data[1] = (byte)(hex >> 8);
darienf 20:6d2af70c92ab 541 data[2] = (byte)hex;
darienf 20:6d2af70c92ab 542 break;
darienf 20:6d2af70c92ab 543 case 2:
darienf 20:6d2af70c92ab 544 hex &= 0x0000FFFF;//clear bits not used
darienf 20:6d2af70c92ab 545 data[0] = (byte)(hex >> 8);
darienf 20:6d2af70c92ab 546 data[1] = (byte)hex;
darienf 20:6d2af70c92ab 547 break;
darienf 20:6d2af70c92ab 548 case 1:
darienf 20:6d2af70c92ab 549 hex &= 0x000000FF;//clear bits not used
darienf 20:6d2af70c92ab 550 data[0] = (byte)hex;
darienf 20:6d2af70c92ab 551 break;
darienf 20:6d2af70c92ab 552 }
darienf 20:6d2af70c92ab 553 controller.WriteRegister(reg);
darienf 20:6d2af70c92ab 554 }
darienf 20:6d2af70c92ab 555
darienf 20:6d2af70c92ab 556 /// <summary>
darienf 20:6d2af70c92ab 557 /// Verify hex
darienf 20:6d2af70c92ab 558 /// </summary>
darienf 20:6d2af70c92ab 559 /// <param name="value"></param>
darienf 20:6d2af70c92ab 560 /// <param name="numBytes"></param>
darienf 20:6d2af70c92ab 561 /// <returns></returns>
darienf 20:6d2af70c92ab 562 public String ValidateHexValue(String value, byte numBytes)
darienf 20:6d2af70c92ab 563 {
darienf 20:6d2af70c92ab 564 char[] character = new char[numBytes * 2];
darienf 20:6d2af70c92ab 565 String error = "Valid";
darienf 20:6d2af70c92ab 566
darienf 20:6d2af70c92ab 567 if (value == null)
darienf 20:6d2af70c92ab 568 {
darienf 20:6d2af70c92ab 569 error = "Empty Value";
darienf 20:6d2af70c92ab 570 return error;
darienf 20:6d2af70c92ab 571 }
darienf 20:6d2af70c92ab 572
darienf 20:6d2af70c92ab 573 //check to see if too many characters were entered
darienf 20:6d2af70c92ab 574 if (value.Length > numBytes * 2)
darienf 20:6d2af70c92ab 575 error = "Too many characters";
darienf 20:6d2af70c92ab 576 else
darienf 20:6d2af70c92ab 577 {
darienf 20:6d2af70c92ab 578 character = value.ToCharArray(); //split string into character array
darienf 20:6d2af70c92ab 579
darienf 20:6d2af70c92ab 580 for (int i = 0; i < value.Length; i++)
darienf 20:6d2af70c92ab 581 {
darienf 20:6d2af70c92ab 582 if (Char.IsLetterOrDigit(character[i])) //check for letter and digits
darienf 20:6d2af70c92ab 583 {
darienf 20:6d2af70c92ab 584 if (Char.IsLower(character[i]))
darienf 20:6d2af70c92ab 585 character[i] = Char.ToUpper(character[i]); //changed letter to upper case
darienf 20:6d2af70c92ab 586
darienf 20:6d2af70c92ab 587 //check A-F
darienf 20:6d2af70c92ab 588 if (character[i] > 'F')
darienf 20:6d2af70c92ab 589 error = "Invalid Letter";
darienf 20:6d2af70c92ab 590 }
darienf 20:6d2af70c92ab 591 else
darienf 20:6d2af70c92ab 592 error = "Invalid Character";
darienf 20:6d2af70c92ab 593 }
darienf 20:6d2af70c92ab 594 }
darienf 20:6d2af70c92ab 595 return error;
darienf 20:6d2af70c92ab 596 }
darienf 20:6d2af70c92ab 597
darienf 20:6d2af70c92ab 598 public void WriteAll()
darienf 20:6d2af70c92ab 599 {
darienf 20:6d2af70c92ab 600 if (Connected)
darienf 20:6d2af70c92ab 601 controller.WriteAll();
darienf 20:6d2af70c92ab 602 DisplayRegisters();
darienf 20:6d2af70c92ab 603 }
darienf 20:6d2af70c92ab 604
darienf 20:6d2af70c92ab 605 /// <summary>
darienf 20:6d2af70c92ab 606 /// Read all button handler
darienf 20:6d2af70c92ab 607 /// </summary>
darienf 20:6d2af70c92ab 608 /// <param name="sender"></param>
darienf 20:6d2af70c92ab 609 /// <param name="e"></param>
darienf 20:6d2af70c92ab 610 private void btn_ReadAll_Click(object sender, EventArgs e)
darienf 20:6d2af70c92ab 611 {
darienf 20:6d2af70c92ab 612 ReadAll();
darienf 20:6d2af70c92ab 613 }
darienf 20:6d2af70c92ab 614
darienf 20:6d2af70c92ab 615 /// <summary>
darienf 20:6d2af70c92ab 616 /// Read all registers and display results
darienf 20:6d2af70c92ab 617 /// </summary>
darienf 20:6d2af70c92ab 618 public void ReadAll()
darienf 20:6d2af70c92ab 619 {
darienf 20:6d2af70c92ab 620 if (Connected)
darienf 20:6d2af70c92ab 621 controller.ReadAll();
darienf 20:6d2af70c92ab 622 DisplayRegisters();
darienf 20:6d2af70c92ab 623 UpdateRegisterBits();
darienf 20:6d2af70c92ab 624 }
darienf 20:6d2af70c92ab 625
darienf 20:6d2af70c92ab 626 public RegisterInfo RegisterAddress(int address)
darienf 20:6d2af70c92ab 627 {
darienf 20:6d2af70c92ab 628 for(int i = 0; i < controller.InfoArray.Length; i++)
darienf 20:6d2af70c92ab 629 {
darienf 20:6d2af70c92ab 630 if (controller.InfoArray[i].address == address)
darienf 20:6d2af70c92ab 631 return controller.InfoArray[i];
darienf 20:6d2af70c92ab 632 }
darienf 20:6d2af70c92ab 633
darienf 20:6d2af70c92ab 634 return null;
darienf 20:6d2af70c92ab 635 }
darienf 20:6d2af70c92ab 636
darienf 20:6d2af70c92ab 637 /// <summary>
darienf 20:6d2af70c92ab 638 /// Read register handler
darienf 20:6d2af70c92ab 639 /// </summary>
darienf 20:6d2af70c92ab 640 /// <param name="sender"></param>
darienf 20:6d2af70c92ab 641 /// <param name="e"></param>
darienf 20:6d2af70c92ab 642 private void btnRead_Click(object sender, EventArgs e)
darienf 20:6d2af70c92ab 643 {
darienf 20:6d2af70c92ab 644 if (connected)
darienf 20:6d2af70c92ab 645 {
darienf 20:6d2af70c92ab 646 controller.ReadRegister(controller.InfoArray[dgv_Registers.SelectedRows[0].Index]);
darienf 20:6d2af70c92ab 647 DisplayRegisters();
darienf 20:6d2af70c92ab 648 UpdateRegisterBits();
darienf 20:6d2af70c92ab 649 }
darienf 20:6d2af70c92ab 650 }
darienf 20:6d2af70c92ab 651
darienf 20:6d2af70c92ab 652 /// <summary>
darienf 20:6d2af70c92ab 653 /// Toggle register bit handler
darienf 20:6d2af70c92ab 654 /// </summary>
darienf 20:6d2af70c92ab 655 /// <param name="sender"></param>
darienf 20:6d2af70c92ab 656 /// <param name="e"></param>
darienf 20:6d2af70c92ab 657 private void lblBit_Click(object sender, EventArgs e)
darienf 20:6d2af70c92ab 658 {
darienf 20:6d2af70c92ab 659 Label lbl = (Label)sender;
darienf 20:6d2af70c92ab 660
darienf 20:6d2af70c92ab 661 string[] number = Regex.Split(lbl.Name, @"\D+");
darienf 20:6d2af70c92ab 662
darienf 20:6d2af70c92ab 663 if (lbl.Font.Bold == true)
darienf 20:6d2af70c92ab 664 lbl.Font = RegularFont;
darienf 20:6d2af70c92ab 665 else
darienf 20:6d2af70c92ab 666 lbl.Font = BoldFont;
darienf 20:6d2af70c92ab 667
darienf 20:6d2af70c92ab 668 foreach(string value in number)
darienf 20:6d2af70c92ab 669 {
darienf 20:6d2af70c92ab 670 if (value != String.Empty)
darienf 20:6d2af70c92ab 671 {
darienf 20:6d2af70c92ab 672 int bitNumber = Int32.Parse(value);
darienf 20:6d2af70c92ab 673
darienf 20:6d2af70c92ab 674 RegisterValue &= ~(1 << bitNumber); // clear bit
darienf 20:6d2af70c92ab 675 RegisterValue |= ((lbl.Font.Bold == true ? 1 : 0) << bitNumber); // set bit
darienf 20:6d2af70c92ab 676 }
darienf 20:6d2af70c92ab 677 }
darienf 20:6d2af70c92ab 678 }
darienf 20:6d2af70c92ab 679
darienf 20:6d2af70c92ab 680 /// <summary>
darienf 20:6d2af70c92ab 681 /// Write register button handler
darienf 20:6d2af70c92ab 682 /// </summary>
darienf 20:6d2af70c92ab 683 /// <param name="sender"></param>
darienf 20:6d2af70c92ab 684 /// <param name="e"></param>
darienf 20:6d2af70c92ab 685 private void btnWrite_Click(object sender, EventArgs e)
darienf 20:6d2af70c92ab 686 {
darienf 20:6d2af70c92ab 687 if (connected)
darienf 20:6d2af70c92ab 688 {
darienf 20:6d2af70c92ab 689 WriteRegister(controller.InfoArray[dgv_Registers.SelectedRows[0].Index], RegisterValue);
darienf 20:6d2af70c92ab 690 controller.ReadRegister(controller.InfoArray[dgv_Registers.SelectedRows[0].Index]);
darienf 20:6d2af70c92ab 691 DisplayRegisters();
darienf 20:6d2af70c92ab 692 }
darienf 20:6d2af70c92ab 693 }
darienf 20:6d2af70c92ab 694
darienf 20:6d2af70c92ab 695 /// <summary>
darienf 20:6d2af70c92ab 696 /// On cell begin edit
darienf 20:6d2af70c92ab 697 /// </summary>
darienf 20:6d2af70c92ab 698 /// <param name="sender"></param>
darienf 20:6d2af70c92ab 699 /// <param name="e"></param>
darienf 20:6d2af70c92ab 700 private void OnCellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
darienf 20:6d2af70c92ab 701 {
darienf 20:6d2af70c92ab 702 if (CellBeginEdit != null)
darienf 20:6d2af70c92ab 703 {
darienf 20:6d2af70c92ab 704 CellBeginEdit(sender, e);
darienf 20:6d2af70c92ab 705 }
darienf 20:6d2af70c92ab 706 }
darienf 20:6d2af70c92ab 707
darienf 20:6d2af70c92ab 708 private void DataGridViewColumns(DataGridView listview, SizeF factor)
darienf 20:6d2af70c92ab 709 {
darienf 20:6d2af70c92ab 710 foreach (DataGridViewColumn column in listview.Columns)
darienf 20:6d2af70c92ab 711 {
darienf 20:6d2af70c92ab 712 column.Width = (int)Math.Round(column.Width * factor.Width);
darienf 20:6d2af70c92ab 713 }
darienf 20:6d2af70c92ab 714 }
darienf 20:6d2af70c92ab 715
darienf 20:6d2af70c92ab 716 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
darienf 20:6d2af70c92ab 717 {
darienf 20:6d2af70c92ab 718 base.ScaleControl(factor, specified);
darienf 20:6d2af70c92ab 719 DataGridViewColumns(dgv_RegDes, factor);
darienf 20:6d2af70c92ab 720 DataGridViewColumns(dgv_Registers, factor);
darienf 20:6d2af70c92ab 721 }
darienf 20:6d2af70c92ab 722 /*
darienf 20:6d2af70c92ab 723 public class RegisterProcess
darienf 20:6d2af70c92ab 724 {
darienf 20:6d2af70c92ab 725 RegisterBit[][] Data;
darienf 20:6d2af70c92ab 726
darienf 20:6d2af70c92ab 727 public RegisterProcess(RegisterInfo[] info)
darienf 20:6d2af70c92ab 728 {
darienf 20:6d2af70c92ab 729 Data = new RegisterBit[info.Length][];
darienf 20:6d2af70c92ab 730
darienf 20:6d2af70c92ab 731 for (int i = 0; i < info.Length; i++)
darienf 20:6d2af70c92ab 732 {
darienf 20:6d2af70c92ab 733 Data[i] = new RegisterBit[info[i].description.list.Count];
darienf 20:6d2af70c92ab 734
darienf 20:6d2af70c92ab 735 for (int j = 0; j < info[i].description.list.Count; j++)
darienf 20:6d2af70c92ab 736 {
darienf 20:6d2af70c92ab 737 int fieldValue;
darienf 20:6d2af70c92ab 738 fieldValue = (info[i].dataField >> info[i].description.list[j].Index) & info[i].description.list[j].Width;
darienf 20:6d2af70c92ab 739 Data[i][j] = new RegisterBit(info[i].description.list[j].name, fieldValue);
darienf 20:6d2af70c92ab 740 }
darienf 20:6d2af70c92ab 741 }
darienf 20:6d2af70c92ab 742 }
darienf 20:6d2af70c92ab 743
darienf 20:6d2af70c92ab 744 class RegisterBit
darienf 20:6d2af70c92ab 745 {
darienf 20:6d2af70c92ab 746 string Name;
darienf 20:6d2af70c92ab 747 int Data;
darienf 20:6d2af70c92ab 748
darienf 20:6d2af70c92ab 749 public RegisterBit(string name, int data)
darienf 20:6d2af70c92ab 750 {
darienf 20:6d2af70c92ab 751 Name = name;
darienf 20:6d2af70c92ab 752 Data = data;
darienf 20:6d2af70c92ab 753 }
darienf 20:6d2af70c92ab 754 }
darienf 20:6d2af70c92ab 755 }
darienf 20:6d2af70c92ab 756 */
darienf 20:6d2af70c92ab 757
darienf 20:6d2af70c92ab 758 public class RegisterArgs : EventArgs
darienf 20:6d2af70c92ab 759 {
darienf 20:6d2af70c92ab 760 public int Register;
darienf 20:6d2af70c92ab 761 }
darienf 20:6d2af70c92ab 762
darienf 20:6d2af70c92ab 763
darienf 20:6d2af70c92ab 764 }
darienf 20:6d2af70c92ab 765 }