private void TimerTick(object sender, EventArgs e)
        {
            try
            {
                // Setup the BMU Panel

                BMU activeBMU = batteryService.BatteryData.GetBMU(activeBMUId);

                if (activeBMU != null && activeBMU.State != CanReceivingNode.STATE_NA)
                {
                    // Sys status
                    DataGridViewRow sysStatus = BMUdataGridView.Rows[0];
                    sysStatus.Cells[1].Value = "N" + activeBMU.CMUNumberMinCell + ":C" + activeBMU.CellNumberMinCell + "@" + activeBMU.MinCellVoltage;
                    sysStatus.Cells[2].Value = "N" + activeBMU.CMUNumberMaxCell + ":C" + activeBMU.CellNumberMaxCell + "@" + activeBMU.MaxCellVoltage;
                    sysStatus.Cells[3].Value = "N" + activeBMU.CMUNumberMinTemp + "@" + (double)activeBMU.MinCellTemp / 10;
                    sysStatus.Cells[4].Value = "N" + activeBMU.CMUNumberMaxTemp + "@" + (double)activeBMU.MaxCellTemp / 10;
                    sysStatus.Cells[5].Value = activeBMU.BatteryVoltage;
                    sysStatus.Cells[6].Value = activeBMU.BatteryCurrent;
                    sysStatus.Cells[7].Value = activeBMU.BalanceVoltageThresholdRising;
                    sysStatus.Cells[8].Value = activeBMU.BalanceVoltageThresholdFalling;
                    sysStatus.Cells[9].Value = activeBMU.CMUCount;

                    // preChgStatus
                    DataGridViewRow prechgStatus = BMUdataGridView.Rows[2];
                    prechgStatus.Cells[1].Value = activeBMU.PrechargeStateText;
                    prechgStatus.Cells[7].Value = activeBMU.FanSpeed0RPM;
                    prechgStatus.Cells[8].Value = Math.Round(activeBMU.SOCAh, 2);
                    prechgStatus.Cells[9].Value = Math.Round(activeBMU.SOCPercentage * 100, 2);

                    // Flags
                    DataGridViewRow flags = BMUdataGridView.Rows[3];
                    flags.Cells[1].Value = activeBMU.StateMessage;
                    flags.Cells[7].Value = activeBMU.FanSpeed1RPM;
                    flags.Cells[8].Value = Math.Round(activeBMU.BalanceAh, 2);
                    flags.Cells[9].Value = Math.Round(activeBMU.BalancePercentage * 100, 2);

                    List <CMU> cmus = batteryService.BatteryData.GetBMU(activeBMUId).GetCMUs();

                    int cmuIndex = 0;

                    foreach (CMU cmu in cmus)
                    {
                        if (cmus[cmuIndex].SerialNumber != null && cmus[cmuIndex].SerialNumber != 0)
                        {
                            if (CMUdataGridView.Rows.Count <= cmuIndex)
                            {
                                CMUdataGridView.Rows.Add(new DataGridViewRow());
                            }

                            DataGridViewRow cmuRow = CMUdataGridView.Rows[cmuIndex];
                            cmuRow.Cells[0].Value = "CMU " + (cmuIndex + 1);
                            cmuRow.Cells[1].Value = cmus[cmuIndex].SerialNumber;
                            cmuRow.Cells[2].Value = cmus[cmuIndex].PCBTemp;
                            cmuRow.Cells[3].Value = cmus[cmuIndex].CellTemp;
                            if (cmus[cmuIndex].Cell0mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[4].Value = cmus[cmuIndex].Cell0mV;
                            }
                            else
                            {
                                cmuRow.Cells[4].Value = null;
                            }
                            if (cmus[cmuIndex].Cell1mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[5].Value = cmus[cmuIndex].Cell1mV;
                            }
                            else
                            {
                                cmuRow.Cells[5].Value = null;
                            }
                            if (cmus[cmuIndex].Cell2mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[6].Value = cmus[cmuIndex].Cell2mV;
                            }
                            else
                            {
                                cmuRow.Cells[6].Value = null;
                            }
                            if (cmus[cmuIndex].Cell3mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[7].Value = cmus[cmuIndex].Cell3mV;
                            }
                            else
                            {
                                cmuRow.Cells[7].Value = null;
                            }
                            if (cmus[cmuIndex].Cell4mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[8].Value = cmus[cmuIndex].Cell4mV;
                            }
                            else
                            {
                                cmuRow.Cells[8].Value = null;
                            }
                            if (cmus[cmuIndex].Cell5mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[9].Value = cmus[cmuIndex].Cell5mV;
                            }
                            else
                            {
                                cmuRow.Cells[9].Value = null;
                            }
                            if (cmus[cmuIndex].Cell6mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[10].Value = cmus[cmuIndex].Cell6mV;
                            }
                            else
                            {
                                cmuRow.Cells[10].Value = null;
                            }
                            if (cmus[cmuIndex].Cell7mV <= activeBMU.MaxCellVoltage)
                            {
                                cmuRow.Cells[11].Value = cmus[cmuIndex].Cell7mV;
                            }
                            else
                            {
                                cmuRow.Cells[11].Value = null;
                            }

                            for (int cellIndex = 0; cellIndex <= 7; cellIndex++)
                            {
                                FormatCell(cmuRow.Cells[cellIndex + 4], cmuIndex, cellIndex);
                            }
                        }

                        cmuIndex++;
                    }

                    BatteryTwelveVolt batteryTwelveVolt = batteryService.BatteryData.BatteryTwelveVolt;

                    // Sys status

                    double cellTemp = 0;
                    if (batteryTwelveVolt.CellTemp != null)
                    {
                        cellTemp = (double)batteryTwelveVolt.CellTemp;
                    }

                    DataGridViewRow TwelveVStatus = TwelveVoltDataGridView.Rows[0];
                    TwelveVStatus.Cells[0].Value = batteryTwelveVolt.SerialNumber;
                    TwelveVStatus.Cells[1].Value = (double)cellTemp;
                    TwelveVStatus.Cells[2].Value = batteryTwelveVolt.Cell0mV;
                    TwelveVStatus.Cells[3].Value = batteryTwelveVolt.Cell1mV;
                    TwelveVStatus.Cells[4].Value = batteryTwelveVolt.Cell2mV;
                    TwelveVStatus.Cells[5].Value = batteryTwelveVolt.Cell3mV;
                    TwelveVStatus.Cells[6].Value = batteryTwelveVolt.Net12vCurrent;
                    TwelveVStatus.Cells[7].Value = batteryTwelveVolt.HVDc2DcCurrent;
                    TwelveVStatus.Cells[8].Value = batteryTwelveVolt.StatusFlags;
                    TwelveVStatus.Cells[9].Value = batteryTwelveVolt.StatusEvents;
                }
            }
            catch
            {
            }
        }
        private void Timer1_Tick(object sender, EventArgs e)
        {
            try {
                // Setup the BMU Panel

                BMU activeBMU = batteryService.BatteryData.GetBMU(activeBMUId);

                if (activeBMU != null)
                {
                    // Sys status
                    TXTMinCellV.Text     = activeBMU.MinCellVoltage.ToString();
                    TXTMinCellV.Text     = activeBMU.MaxCellVoltage.ToString();
                    TXTMinCellVTemp.Text = ((double)activeBMU.MinCellTemp / 10).ToString();
                    TXTMaxCellVTemp.Text = ((double)activeBMU.MaxCellTemp / 10).ToString();
                    TXTBatTemp.Text      = ((((double)activeBMU.MaxCellTemp / 10) - ((double)activeBMU.MinCellTemp / 10)) / 2).ToString();
                    //sysStatus.Cells[5].Value = activeBMU.BatteryVoltage;
                    //sysStatus.Cells[6].Value = activeBMU.BatteryCurrent;
                    //sysStatus.Cells[7].Value = activeBMU.BalanceVoltageThresholdRising;
                    //sysStatus.Cells[8].Value = activeBMU.BalanceVoltageThresholdFalling;
                    //sysStatus.Cells[9].Value = activeBMU.CMUCount;

                    /*
                     *
                     * // preChgStatus
                     * DataGridViewRow prechgStatus = BMUdataGridView.Rows[2];
                     * prechgStatus.Cells[1].Value = activeBMU.PrechargeStateText;
                     * prechgStatus.Cells[7].Value = activeBMU.FanSpeed0RPM;
                     * prechgStatus.Cells[8].Value = Math.Round(activeBMU.SOCAh, 2);
                     * prechgStatus.Cells[9].Value = activeBMU.SOCPercentage * 100;
                     *
                     * // Flags
                     * DataGridViewRow flags = BMUdataGridView.Rows[3];
                     * flags.Cells[1].Value = activeBMU.StateMessage;
                     * flags.Cells[7].Value = activeBMU.FanSpeed1RPM;
                     *
                     * CMU[] cmus = batteryService.BatteryData.GetBMU(activeBMUId).GetCMUs();
                     *
                     * for (int cmuIndex = 0; cmuIndex < cmus.Length; cmuIndex++) {
                     *  if (cmus[cmuIndex].SerialNumber != null && cmus[cmuIndex].SerialNumber != 0) {
                     *      if (CMUdataGridView.Rows.Count <= cmuIndex)
                     *          CMUdataGridView.Rows.Add(new DataGridViewRow());
                     *
                     *      DataGridViewRow cmuRow = CMUdataGridView.Rows[cmuIndex];
                     *      cmuRow.Cells[0].Value = "CMU " + (cmuIndex + 1);
                     *      cmuRow.Cells[1].Value = cmus[cmuIndex].SerialNumber;
                     *      cmuRow.Cells[2].Value = cmus[cmuIndex].PCBTemp;
                     *      cmuRow.Cells[3].Value = cmus[cmuIndex].CellTemp;
                     *      cmuRow.Cells[4].Value = cmus[cmuIndex].Cell0mV;
                     *      cmuRow.Cells[5].Value = cmus[cmuIndex].Cell1mV;
                     *      cmuRow.Cells[6].Value = cmus[cmuIndex].Cell2mV;
                     *      cmuRow.Cells[7].Value = cmus[cmuIndex].Cell3mV;
                     *      cmuRow.Cells[8].Value = cmus[cmuIndex].Cell4mV;
                     *      cmuRow.Cells[9].Value = cmus[cmuIndex].Cell5mV;
                     *      cmuRow.Cells[10].Value = cmus[cmuIndex].Cell6mV;
                     *      cmuRow.Cells[11].Value = cmus[cmuIndex].Cell7mV;
                     *
                     *      for (int cellIndex = 0; cellIndex <= 7; cellIndex++)
                     *          FormatCell(cmuRow.Cells[cellIndex + 4], cmuIndex, cellIndex);
                     *
                     *  }
                     * }
                     *
                     * BatteryTwelveVolt batteryTwelveVolt = batteryService.BatteryData.BatteryTwelveVolt;
                     *
                     * // Sys status
                     *
                     * double cellTemp = 0;
                     * if (batteryTwelveVolt.CellTemp != null) cellTemp = (double)batteryTwelveVolt.CellTemp;
                     *
                     * DataGridViewRow TwelveVStatus = TwelveVoltDataGridView.Rows[0];
                     * TwelveVStatus.Cells[0].Value = batteryTwelveVolt.SerialNumber;
                     * TwelveVStatus.Cells[1].Value = (double)cellTemp / 10;
                     * TwelveVStatus.Cells[2].Value = batteryTwelveVolt.Cell0mV;
                     * TwelveVStatus.Cells[3].Value = batteryTwelveVolt.Cell1mV;
                     * TwelveVStatus.Cells[4].Value = batteryTwelveVolt.Cell2mV;
                     * TwelveVStatus.Cells[5].Value = batteryTwelveVolt.Cell3mV;
                     * TwelveVStatus.Cells[6].Value = batteryTwelveVolt.Net12vCurrent;
                     * TwelveVStatus.Cells[7].Value = batteryTwelveVolt.HVDc2DcCurrent;
                     * TwelveVStatus.Cells[8].Value = batteryTwelveVolt.StatusFlags;
                     * TwelveVStatus.Cells[9].Value = batteryTwelveVolt.StatusEvents;
                     */
                }
            } catch {
                Console.WriteLine("Fail");
            }

            try {
                // Setup the BMU Panel

                BMU activeBMU = batteryService.BatteryData.GetBMU(activeBMUId);

                if (activeBMU != null)
                {
                    // Sys status
                    DataGridViewRow sysStatus = BMUdataGridView.Rows[0];
                    sysStatus.Cells[1].Value = activeBMU.MinCellVoltage;
                    sysStatus.Cells[2].Value = activeBMU.MaxCellVoltage;
                    sysStatus.Cells[3].Value = (double)activeBMU.MinCellTemp / 10;
                    sysStatus.Cells[4].Value = (double)activeBMU.MaxCellTemp / 10;
                    sysStatus.Cells[5].Value = activeBMU.BatteryVoltage;
                    sysStatus.Cells[6].Value = activeBMU.BatteryCurrent;
                    sysStatus.Cells[7].Value = activeBMU.BalanceVoltageThresholdRising;
                    sysStatus.Cells[8].Value = activeBMU.BalanceVoltageThresholdFalling;
                    sysStatus.Cells[9].Value = activeBMU.CMUCount;

                    // preChgStatus
                    DataGridViewRow prechgStatus = BMUdataGridView.Rows[2];
                    prechgStatus.Cells[1].Value = activeBMU.PrechargeStateText;
                    prechgStatus.Cells[7].Value = activeBMU.FanSpeed0RPM;
                    prechgStatus.Cells[8].Value = Math.Round(activeBMU.SOCAh, 2);
                    prechgStatus.Cells[9].Value = activeBMU.SOCPercentage * 100;

                    // Flags
                    DataGridViewRow flags = BMUdataGridView.Rows[3];
                    flags.Cells[1].Value = activeBMU.StateMessage;
                    flags.Cells[7].Value = activeBMU.FanSpeed1RPM;

                    CMU[] cmus = batteryService.BatteryData.GetBMU(activeBMUId).GetCMUs();

                    for (int cmuIndex = 0; cmuIndex < cmus.Length; cmuIndex++)
                    {
                        if (cmus[cmuIndex].SerialNumber != null && cmus[cmuIndex].SerialNumber != 0)
                        {
                            if (CMUdataGridView.Rows.Count <= cmuIndex)
                            {
                                CMUdataGridView.Rows.Add(new DataGridViewRow());
                            }

                            DataGridViewRow cmuRow = CMUdataGridView.Rows[cmuIndex];
                            cmuRow.Cells[0].Value  = "CMU " + (cmuIndex + 1);
                            cmuRow.Cells[1].Value  = cmus[cmuIndex].SerialNumber;
                            cmuRow.Cells[2].Value  = cmus[cmuIndex].PCBTemp;
                            cmuRow.Cells[3].Value  = cmus[cmuIndex].CellTemp;
                            cmuRow.Cells[4].Value  = cmus[cmuIndex].Cell0mV;
                            cmuRow.Cells[5].Value  = cmus[cmuIndex].Cell1mV;
                            cmuRow.Cells[6].Value  = cmus[cmuIndex].Cell2mV;
                            cmuRow.Cells[7].Value  = cmus[cmuIndex].Cell3mV;
                            cmuRow.Cells[8].Value  = cmus[cmuIndex].Cell4mV;
                            cmuRow.Cells[9].Value  = cmus[cmuIndex].Cell5mV;
                            cmuRow.Cells[10].Value = cmus[cmuIndex].Cell6mV;
                            cmuRow.Cells[11].Value = cmus[cmuIndex].Cell7mV;

                            for (int cellIndex = 0; cellIndex <= 7; cellIndex++)
                            {
                                FormatCell(cmuRow.Cells[cellIndex + 4], cmuIndex, cellIndex);
                            }
                        }
                    }

                    BatteryTwelveVolt batteryTwelveVolt = batteryService.BatteryData.BatteryTwelveVolt;

                    // Sys status

                    double cellTemp = 0;
                    if (batteryTwelveVolt.CellTemp != null)
                    {
                        cellTemp = (double)batteryTwelveVolt.CellTemp;
                    }

                    DataGridViewRow TwelveVStatus = TwelveVoltDataGridView.Rows[0];
                    TwelveVStatus.Cells[0].Value = batteryTwelveVolt.SerialNumber;
                    TwelveVStatus.Cells[1].Value = (double)cellTemp / 10;
                    TwelveVStatus.Cells[2].Value = batteryTwelveVolt.Cell0mV;
                    TwelveVStatus.Cells[3].Value = batteryTwelveVolt.Cell1mV;
                    TwelveVStatus.Cells[4].Value = batteryTwelveVolt.Cell2mV;
                    TwelveVStatus.Cells[5].Value = batteryTwelveVolt.Cell3mV;
                    TwelveVStatus.Cells[6].Value = batteryTwelveVolt.Net12vCurrent;
                    TwelveVStatus.Cells[7].Value = batteryTwelveVolt.HVDc2DcCurrent;
                    TwelveVStatus.Cells[8].Value = batteryTwelveVolt.StatusFlags;
                    TwelveVStatus.Cells[9].Value = batteryTwelveVolt.StatusEvents;
                }
            } catch {
            }
        }