Darien Figueroa / Mbed OS Final_Program

Dependencies:   USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RegisterView.cs Source File

RegisterView.cs

00001 /*******************************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
00003 * 
00004 * This software is protected by copyright laws of the United States and
00005 * of foreign countries. This material may also be protected by patent laws
00006 * and technology transfer regulations of the United States and of foreign
00007 * countries. This software is furnished under a license agreement and/or a
00008 * nondisclosure agreement and may only be used or reproduced in accordance
00009 * with the terms of those agreements. Dissemination of this information to
00010 * any party or parties not specified in the license agreement and/or
00011 * nondisclosure agreement is expressly prohibited.
00012 *
00013 * The above copyright notice and this permission notice shall be included
00014 * in all copies or substantial portions of the Software.
00015 *
00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00022 * OTHER DEALINGS IN THE SOFTWARE.
00023 *
00024 * Except as contained in this notice, the name of Maxim Integrated
00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00026 * Products, Inc. Branding Policy.
00027 *
00028 * The mere transfer of this software does not imply any licenses
00029 * of trade secrets, proprietary technology, copyrights, patents,
00030 * trademarks, maskwork rights, or any other form of intellectual
00031 * property whatsoever. Maxim Integrated Products, Inc. retains all
00032 * ownership rights.
00033 *******************************************************************************
00034 */
00035 
00036 using System;
00037 using System.Collections.Generic;
00038 using System.ComponentModel;
00039 using System.Drawing;
00040 using System.Data;
00041 using System.Linq;
00042 using System.Text;
00043 using System.Text.RegularExpressions;
00044 using System.Windows.Forms;
00045 using System.IO;
00046 
00047 using HealthSensorPlatform.DeviceDescriptions;
00048 using HealthSensorPlatform.CustomControls;
00049 using RPCSupport.DeviceSupport;
00050 //using Maxim.MAX30101GUI.DeviceDescriptions;
00051 //using Maxim.MAX30101;
00052 
00053 namespace Maxim.CustomControls
00054 {
00055     public partial class RegisterView : UserControl, IDeviceView
00056     {
00057         private bool connected = false;
00058         public bool Connected
00059         {
00060             get
00061             {
00062                 return connected;
00063             }
00064             set 
00065             {
00066                 connected = value;
00067             }
00068         }
00069 
00070         public string DeviceName;
00071 
00072         public DeviceController Controller
00073         {
00074             get { return controller; }
00075         }
00076         private DeviceController controller;
00077 
00078 
00079         /// <summary>
00080         /// Value of current selected register 
00081         /// </summary>
00082         int RegisterValue;
00083 
00084         Label[] bitLabels = new Label[24];
00085         
00086         Font RegularFont;
00087         Font BoldFont;
00088 
00089         public event RegisterWriteCompleteHandler RegisterWriteComplete;
00090         public delegate void RegisterWriteCompleteHandler(object sender, RegisterArgs e);
00091 
00092         public event CellBeginEditHandler CellBeginEdit;
00093         public delegate void CellBeginEditHandler(object sender, DataGridViewCellCancelEventArgs e);
00094 
00095         public RegisterView()
00096         {
00097             //accelDevice = new AccelDevice();
00098             InitializeComponent();
00099 
00100             // Initialize font styles for label
00101             RegularFont = new Font(lblBit00.Font, FontStyle.Regular); 
00102             BoldFont = new Font(lblBit00.Font, FontStyle.Bold);
00103 
00104             // References to all bit labels
00105             for(int i = 0; i < 24; i++)
00106             {
00107                 string labelName = "lblBit" + i.ToString("D2");
00108                 bitLabels[i] = (Label)panelRegisterBits.Controls[labelName];
00109             }
00110 
00111             dgv_Registers.CellBeginEdit += OnCellBeginEdit; // Pass thru event
00112             dgv_Registers.SelectionChanged += dgv_Registers_SelectionChanged;
00113             dgv_Registers.CellEndEdit += dgv_Registers_CellEndEdit;
00114         }
00115 
00116         public void SetController(DeviceController controller)
00117         {
00118             Clear();
00119             this.controller = controller;
00120         }
00121 
00122         /// <summary>
00123         /// RegisterInfo register value to string
00124         /// </summary>
00125         /// <param name="reg"></param>
00126         /// <returns></returns>
00127         private string FormatData(RegisterInfo reg)
00128         {
00129             return reg.dataField.ToString("X" + (reg.numBytes * 2).ToString());
00130         }
00131 
00132         /// <summary>
00133         /// Populate register tables
00134         /// </summary>
00135         public void DisplayRegisters()
00136         {
00137             if (dgv_Registers.RowCount == 0)
00138             {
00139                 //add rows to table
00140                 foreach (RegisterInfo reg in controller.InfoArray)
00141                 {
00142                     //get the number of bytes of the register
00143                     int numBytes = reg.numBytes;
00144 
00145                     String dataStr = FormatData(reg);
00146                     //add a row to the table with the register address, name, and value
00147                     dgv_Registers.Rows.Add(reg.address.ToString("X2") + "h", reg.detailedName, dataStr);
00148                 }
00149                 
00150                 //resize length of table to the number of rows
00151                 if (dgv_Registers.RowCount > 8)
00152                 {
00153                     dgv_Registers.Height = (dgv_Registers.RowCount - 1) * 23 + 42;
00154                     dgv_RegDes.Height = dgv_Registers.Height;
00155                 }
00156                 else
00157                 {
00158                     dgv_Registers.Height = 7 * 23 + 42;
00159                     dgv_RegDes.Height = dgv_Registers.Height;
00160                 }
00161             }
00162             else //the table has already been populated with rows
00163             {
00164                 //update the value column with the new value in the ADC registers
00165                 for (int i = 0; i < dgv_Registers.Rows.Count; i++)
00166                 {
00167                     RegisterInfo reg = controller.InfoArray[i];
00168                     int numBytes = reg.numBytes;
00169                     String dataStr = FormatData(reg);
00170                     //add a row to the table with the register address, name, and value
00171                     dgv_Registers[col_Value.Index, i].Value = dataStr;
00172                 }
00173             }
00174         }
00175 
00176         public void Clear()
00177         {
00178             dgv_Registers.Rows.Clear();
00179             dgv_Registers.Refresh();
00180         }
00181 
00182         public string RegistersToString()
00183         {
00184             //RegisterProcess registerProcess;
00185             StringBuilder sb = new StringBuilder();
00186             string dataStr;
00187             string[][] bitDescriptions;
00188             int longestRow;
00189 
00190             //registerProcess = new RegisterProcess(controller.InfoArray);
00191             
00192             bitDescriptions = new string[controller.InfoArray.Length + 4][];
00193 
00194             UpdateRegisterIndexWidth();
00195 
00196             // Generate register data to string
00197             for (int i = 0; i < controller.InfoArray.Length; i++)
00198             {
00199                 RegisterInfo reg = controller.InfoArray[i];
00200 
00201                 bitDescriptions[i] = new string[reg.description.list.Count];
00202 
00203                 for (int k = 0; k < reg.description.list.Count; k++)
00204                 {
00205                     RegisterBitDescriptions.RegisterBitDescription b = reg.description.list[k];
00206                     int bitValue = (reg.dataField >> b.Index) & ((1 << b.Width) - 1); // MAX30001 only
00207                     bitDescriptions[i][k] = b.name + " = " + bitValue.ToString("X") + "h";
00208                 }
00209             }
00210 
00211             // Find longest row for how deep to loop to print out all registers bits
00212             longestRow = controller.InfoArray.Length + 1;
00213             for (int j = 0; j < controller.InfoArray.Length; j++ )
00214             {
00215                 if (controller.InfoArray[j].description.list.Count > longestRow)
00216                 {
00217                     longestRow = controller.InfoArray[j].description.list.Count + 1;
00218                 }
00219             }
00220 
00221             for (int i = 0; i < longestRow; i++)
00222             {
00223                 if (i < controller.InfoArray.Length) // register map
00224                 {
00225                     RegisterInfo reg = controller.InfoArray[i];
00226 
00227                     dataStr = FormatData(reg);
00228 
00229                     sb.Append(this.DeviceName);
00230                     sb.Append(", ");
00231                     sb.Append(reg.address.ToString("X2"));
00232                     sb.Append("h, ");
00233                     sb.Append(reg.detailedName);
00234                     sb.Append(", ");
00235                     sb.Append(dataStr);
00236                     sb.Append("h");
00237                     sb.Append(", ");
00238                     sb.Append(", ");
00239                 }
00240                 else // finished with register map, just have descriptions
00241                 {
00242                     sb.Append(", ");
00243                     sb.Append(", ");
00244                     sb.Append(", ");
00245                     sb.Append(", ");
00246                     sb.Append(", ");
00247                 }
00248 
00249                 if (i == 0) // Register name and values
00250                 {
00251                     for (int k = 0; k < controller.InfoArray.Length; k++)
00252                     {
00253                         if (controller.InfoArray[k].type != RegisterInfo.RegisterType.WriteOnly)
00254                         {
00255                             sb.Append(controller.InfoArray[k].name);
00256                             sb.Append(" = ");
00257                             sb.Append(FormatData(controller.InfoArray[k]));
00258                             sb.Append("h");
00259                             sb.Append(", ");
00260                         }
00261                     }
00262                 }
00263                 else // descriptions
00264                 {
00265                     for (int k = 0; k < controller.InfoArray.Length; k++)
00266                     {
00267                         if (controller.InfoArray[k].type != RegisterInfo.RegisterType.WriteOnly)
00268                         {
00269                             if (i - 1 < bitDescriptions[k].Length)
00270                             {
00271                                 sb.Append(bitDescriptions[k][i - 1]);
00272                             }
00273                             sb.Append(',');
00274                         }
00275                     }
00276                 }
00277                 sb.Append(Environment.NewLine);
00278             }
00279 
00280             /*
00281             foreach(RegisterInfo reg in controller.InfoArray)
00282             {
00283                 if (reg.address == 1 || reg.address == 8 || reg.address == 9 || reg.address == 10)
00284                     continue;
00285 
00286                 sb.Append("% ");
00287                 sb.Append(reg.name);
00288                 sb.Append(" (");
00289                 sb.Append(reg.address.ToString("X2"));
00290                 sb.Append("h)");
00291                 sb.Append(" = ");
00292                 sb.Append(FormatData(reg));
00293                 sb.Append("h\n");
00294 
00295                 foreach(RegisterBitDescriptions.RegisterBitDescription b in reg.description.list)
00296                 {
00297                     int bitValue = (RegisterData(reg) >> b.Index) & ((1 << b.Width) - 1); // MAX30001 only
00298                     sb.Append("% ");
00299                     sb.Append(b.name);
00300                     sb.Append(" = ");
00301                     sb.Append(bitValue.ToString("X"));
00302                     sb.Append("h\n");
00303                 }
00304             }
00305             */
00306             return sb.ToString().TrimEnd(Environment.NewLine.ToCharArray());
00307         }
00308 
00309         /// <summary>
00310         /// Register selection change display register description and update display bits
00311         /// </summary>
00312         /// <param name="sender"></param>
00313         /// <param name="e"></param>
00314         private void dgv_Registers_SelectionChanged(object sender, EventArgs e)
00315         {
00316             UpdateRegisters();
00317         }
00318 
00319         private void UpdateRegisters()
00320         {
00321             //get the index of the row selected
00322             int row = dgv_Registers.CurrentRow.Index;
00323 
00324             //make sure there is bit description info and then display it
00325             if (controller.InfoArray[row].description != null)
00326             {
00327                 lbl_bitDes.Text = "Bit Description: " + controller.InfoArray[row].name + " Register";
00328                 UpdateRegisterDesTable(controller.InfoArray[row].description);
00329                 RegisterValue = Int32.Parse((string)(dgv_Registers[2, row].Value), System.Globalization.NumberStyles.HexNumber);
00330                 UpdateRegisterBits(controller.InfoArray[row].description, RegisterValue);
00331             }
00332         }
00333 
00334         /// <summary>
00335         /// Fill register description table
00336         /// </summary>
00337         /// <param name="bitsDes"></param>
00338         public void UpdateRegisterDesTable(RegisterBitDescriptions bitsDes)
00339         {
00340             //int numBits = bitsDes.Count;
00341 
00342             dgv_RegDes.Rows.Clear();
00343 
00344             foreach (RegisterBitDescriptions.RegisterBitDescription b in bitsDes.list)
00345             {
00346                 dgv_RegDes.Rows.Add(b.bit, b.name, b.description);
00347             }
00348 
00349         }
00350 
00351         public void UpdateRegisterBits()
00352         {
00353             int row;
00354 
00355             if (dgv_Registers.CurrentRow != null)
00356             {
00357                 row = dgv_Registers.CurrentRow.Index;
00358 
00359                 if (controller.InfoArray[row].description != null)
00360                 {
00361                     RegisterValue = Int32.Parse((string)(dgv_Registers[2, row].Value), System.Globalization.NumberStyles.HexNumber);
00362                     UpdateRegisterBits(controller.InfoArray[row].description, RegisterValue);
00363                 }
00364             }
00365         }
00366 
00367         public void UpdateRegisterIndexWidth()
00368         {
00369             RegisterInfo[] info = controller.InfoArray;
00370 
00371             foreach(RegisterInfo regInfo in info) // Registers
00372             {
00373                 foreach (RegisterBitDescriptions.RegisterBitDescription b in regInfo.description.list) // Bits
00374                 {
00375                     string[] numbers = Regex.Split(b.bit, @"\D+"); // Bits [20:17]
00376                     string registerBitName;
00377                     int number1 = -1;
00378                     int number2 = -1;
00379 
00380                     // Find Bit Range
00381                     foreach (string value in numbers)
00382                     {
00383                         if (value != String.Empty)
00384                         {
00385                             if (number1 == -1) // First number found
00386                                 number1 = Int32.Parse(value);
00387                             else // Second number found
00388                                 number2 = Int32.Parse(value);
00389                         }
00390                     }
00391 
00392                     if (number2 == -1) // Single Number: single bit field (example: Bit 20)
00393                     {
00394                         b.Width = 1;
00395                         b.Index = number1;
00396                     }
00397                     else // Multiple Bits: multiple bit field (example: Bit [20:17])
00398                     {
00399                         registerBitName = Regex.Replace(b.name, @"\[\d+:\d+\]", String.Empty); // Remove [#.#] from bit field name
00400 
00401                         for (int i = number1; i >= number2; i--)
00402                         {
00403                             bitLabels[i].Text = registerBitName + "[" + (i - number2) + "]"; // Calculate bit field number
00404                         }
00405 
00406                         b.Index = number2;
00407                         b.Width = number1 - number2 + 1; 
00408 
00409                     }
00410                 }
00411             }
00412         }
00413 
00414         /// <summary>
00415         /// Fill bit table
00416         /// </summary>
00417         /// <param name="bitDes"></param>
00418         /// <param name="regValue"></param>
00419         public void UpdateRegisterBits(RegisterBitDescriptions bitDes, int regValue)
00420         {
00421             // Reset Bit State
00422             for (int i = 0; i < 24; i++ )
00423             {
00424                 bitLabels[i].Text = "-";
00425 
00426                 // Set label based on bit state
00427                 if (((regValue >> i) & 0x01) == 0x01)
00428                     bitLabels[i].Font = BoldFont;
00429                 else
00430                     bitLabels[i].Font = RegularFont;
00431             }
00432 
00433             foreach (RegisterBitDescriptions.RegisterBitDescription b in bitDes.list)
00434             {
00435                 string[] numbers = Regex.Split(b.bit, @"\D+"); // Bits [20:17]
00436                 string registerBitName;
00437                 int number1 = -1;
00438                 int number2 = -1;
00439 
00440                 // Find Bit Range
00441                 foreach (string value in numbers)
00442                 {
00443                     if (value != String.Empty)
00444                     {
00445                         if (number1 == -1) // First number found
00446                             number1 = Int32.Parse(value);
00447                         else // Second number found
00448                             number2 = Int32.Parse(value);
00449                     }
00450                 }
00451 
00452                 if (number2 == -1) // Single Number: single bit field (example: Bit 20)
00453                 {
00454                     bitLabels[number1].Text = b.name;
00455                 }
00456                 else // Multiple Bits: multiple bit field (example: Bit [20:17])
00457                 {
00458                     registerBitName = Regex.Replace(b.name, @"\[\d+:\d+\]", String.Empty); // Remove [#.#] from bit field name
00459 
00460                     for (int i = number1; i >= number2; i--)
00461                     {
00462                         bitLabels[i].Text = registerBitName + "[" + (i - number2) + "]"; // Calculate bit field number
00463                     }
00464                     
00465                 }
00466             }
00467         }
00468 
00469         /// <summary>
00470         /// Parse user input and write register
00471         /// </summary>
00472         /// <param name="sender"></param>
00473         /// <param name="e"></param>
00474         private void dgv_Registers_CellEndEdit(object sender, DataGridViewCellEventArgs e)
00475         {
00476             //check if hardware is connected
00477             //if (online && !COMMConnected())
00478             //    return;
00479 
00480             RegisterInfo reg = controller.InfoArray[e.RowIndex];
00481             byte address = (byte)reg.address;
00482             byte numBytes = (byte)reg.numBytes;
00483 
00484             int[] data = reg.data;
00485 
00486             string value = (string)dgv_Registers[col_Value.Index, e.RowIndex].Value;
00487             string error = ValidateHexValue(value, numBytes);
00488 
00489             if (error == "Valid")
00490             {
00491                 //erase error text if one exist
00492                 if (dgv_Registers[col_Value.Index, e.RowIndex].ErrorText != String.Empty)
00493                     dgv_Registers[col_Value.Index, e.RowIndex].ErrorText = String.Empty;
00494 
00495                 //convert string hex to number hex
00496                 int hex = Int32.Parse(value, System.Globalization.NumberStyles.HexNumber);
00497 
00498                 //write value back to GUI with correct number of characters
00499                 dgv_Registers[col_Value.Index, e.RowIndex].Value = hex.ToString("X" + numBytes * 2);
00500 
00501                 WriteRegister(reg, hex);
00502 
00503                 if (RegisterWriteComplete != null)
00504                 {
00505                     RegisterWriteComplete(this, new RegisterArgs { Register = address });
00506                 }
00507 
00508             }
00509             else//value is not valid
00510             {
00511                 byte zero = 0;
00512                 dgv_Registers[col_Value.Index, e.RowIndex].Value = zero.ToString("X" + numBytes * 2); //enter zeros with correct number of characters
00513                 dgv_Registers[col_Value.Index, e.RowIndex].ErrorText = error;    //add error text
00514             }
00515 
00516             UpdateRegisters();
00517         }
00518 
00519         /// <summary>
00520         /// Write data to register
00521         /// </summary>
00522         /// <param name="reg"></param>
00523         /// <param name="hex"></param>
00524         public void WriteRegister(RegisterInfo reg, int hex)
00525         {
00526             byte numBytes = (byte)reg.numBytes;
00527             int[] data = reg.data;
00528 
00529             switch (numBytes)
00530             {
00531                 case 4:
00532                     data[0] = (byte)(hex >> 24);
00533                     data[1] = (byte)(hex >> 16);
00534                     data[2] = (byte)(hex >> 8);
00535                     data[3] = (byte)hex;
00536                     break;
00537                 case 3:
00538                     hex &= 0x00FFFFFF;//clear bits not used
00539                     data[0] = (byte)(hex >> 16);
00540                     data[1] = (byte)(hex >> 8);
00541                     data[2] = (byte)hex;
00542                     break;
00543                 case 2:
00544                     hex &= 0x0000FFFF;//clear bits not used
00545                     data[0] = (byte)(hex >> 8);
00546                     data[1] = (byte)hex;
00547                     break;
00548                 case 1:
00549                     hex &= 0x000000FF;//clear bits not used
00550                     data[0] = (byte)hex;
00551                     break;
00552             }
00553             controller.WriteRegister(reg);
00554         }
00555 
00556         /// <summary>
00557         /// Verify hex
00558         /// </summary>
00559         /// <param name="value"></param>
00560         /// <param name="numBytes"></param>
00561         /// <returns></returns>
00562         public String ValidateHexValue(String value, byte numBytes)
00563         {
00564             char[] character = new char[numBytes * 2];
00565             String error = "Valid";
00566 
00567             if (value == null)
00568             {
00569                 error = "Empty Value";
00570                 return error;
00571             }
00572 
00573             //check to see if too many characters were entered
00574             if (value.Length > numBytes * 2)
00575                 error = "Too many characters";
00576             else
00577             {
00578                 character = value.ToCharArray();    //split string into character array
00579 
00580                 for (int i = 0; i < value.Length; i++)
00581                 {
00582                     if (Char.IsLetterOrDigit(character[i])) //check for letter and digits
00583                     {
00584                         if (Char.IsLower(character[i]))
00585                             character[i] = Char.ToUpper(character[i]); //changed letter to upper case
00586 
00587                         //check A-F
00588                         if (character[i] > 'F')
00589                             error = "Invalid Letter";
00590                     }
00591                     else
00592                         error = "Invalid Character";
00593                 }
00594             }
00595             return error;
00596         }
00597 
00598         public void WriteAll()
00599         {
00600             if (Connected)
00601                 controller.WriteAll();
00602             DisplayRegisters();
00603         }
00604 
00605         /// <summary>
00606         /// Read all button handler
00607         /// </summary>
00608         /// <param name="sender"></param>
00609         /// <param name="e"></param>
00610         private void btn_ReadAll_Click(object sender, EventArgs e)
00611         {
00612             ReadAll();
00613         }
00614 
00615         /// <summary>
00616         /// Read all registers and display results
00617         /// </summary>
00618         public void ReadAll()
00619         {
00620             if (Connected)
00621                 controller.ReadAll();
00622             DisplayRegisters();
00623             UpdateRegisterBits();
00624         }
00625 
00626         public RegisterInfo RegisterAddress(int address)
00627         {
00628             for(int i = 0; i < controller.InfoArray.Length; i++)
00629             {
00630                 if (controller.InfoArray[i].address == address)
00631                     return controller.InfoArray[i];
00632             }
00633 
00634             return null;
00635         }
00636 
00637         /// <summary>
00638         /// Read register handler
00639         /// </summary>
00640         /// <param name="sender"></param>
00641         /// <param name="e"></param>
00642         private void btnRead_Click(object sender, EventArgs e)
00643         {
00644             if (connected)
00645             {
00646                 controller.ReadRegister(controller.InfoArray[dgv_Registers.SelectedRows[0].Index]);
00647                 DisplayRegisters();
00648                 UpdateRegisterBits();
00649             }
00650         }
00651 
00652         /// <summary>
00653         /// Toggle register bit handler
00654         /// </summary>
00655         /// <param name="sender"></param>
00656         /// <param name="e"></param>
00657         private void lblBit_Click(object sender, EventArgs e)
00658         {
00659             Label lbl = (Label)sender;
00660 
00661             string[] number = Regex.Split(lbl.Name, @"\D+");
00662 
00663             if (lbl.Font.Bold == true)
00664                 lbl.Font = RegularFont;
00665             else
00666                 lbl.Font = BoldFont;
00667 
00668             foreach(string value in number)
00669             {
00670                 if (value != String.Empty)
00671                 {
00672                     int bitNumber = Int32.Parse(value);
00673 
00674                     RegisterValue &= ~(1 << bitNumber); // clear bit
00675                     RegisterValue |= ((lbl.Font.Bold == true ? 1 : 0) << bitNumber); // set bit
00676                 }
00677             }
00678         }
00679 
00680         /// <summary>
00681         /// Write register button handler
00682         /// </summary>
00683         /// <param name="sender"></param>
00684         /// <param name="e"></param>
00685         private void btnWrite_Click(object sender, EventArgs e)
00686         {
00687             if (connected)
00688             {
00689                 WriteRegister(controller.InfoArray[dgv_Registers.SelectedRows[0].Index], RegisterValue);
00690                 controller.ReadRegister(controller.InfoArray[dgv_Registers.SelectedRows[0].Index]);
00691                 DisplayRegisters();
00692             }
00693         }
00694 
00695         /// <summary>
00696         /// On cell begin edit
00697         /// </summary>
00698         /// <param name="sender"></param>
00699         /// <param name="e"></param>
00700         private void OnCellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
00701         {
00702             if (CellBeginEdit != null)
00703             {
00704                 CellBeginEdit(sender, e);
00705             }
00706         } 
00707 
00708         private void DataGridViewColumns(DataGridView listview, SizeF factor)
00709         {
00710             foreach (DataGridViewColumn column in listview.Columns)
00711             {
00712                 column.Width = (int)Math.Round(column.Width * factor.Width);
00713             }
00714         }
00715 
00716         protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
00717         {
00718             base.ScaleControl(factor, specified);
00719             DataGridViewColumns(dgv_RegDes, factor);
00720             DataGridViewColumns(dgv_Registers, factor);
00721         }
00722         /*
00723         public class RegisterProcess
00724         {
00725             RegisterBit[][] Data;
00726 
00727             public RegisterProcess(RegisterInfo[] info)
00728             {
00729                 Data = new RegisterBit[info.Length][];
00730                 
00731                 for (int i = 0; i < info.Length; i++)
00732                 {
00733                     Data[i] = new RegisterBit[info[i].description.list.Count];
00734                     
00735                     for (int j = 0; j < info[i].description.list.Count; j++)
00736                     {
00737                         int fieldValue;
00738                         fieldValue = (info[i].dataField >> info[i].description.list[j].Index) & info[i].description.list[j].Width;
00739                         Data[i][j] = new RegisterBit(info[i].description.list[j].name, fieldValue);
00740                     }
00741                 }
00742             }
00743 
00744             class RegisterBit
00745             {
00746                 string Name;
00747                 int Data;
00748                 
00749                 public RegisterBit(string name, int data)
00750                 {
00751                     Name = name;
00752                     Data = data;
00753                 }
00754             }
00755         }
00756         */
00757 
00758         public class RegisterArgs : EventArgs
00759         {
00760             public int Register;
00761         }
00762 
00763 
00764     }
00765 }