//Returns the number of cells enabled within the enabled boards int getCellCount(BalancerComm.Config_t config) { int count = 0; for (int i = 0; i < config.slaveCount + 1; i++) { for (int j = 0; j < 6; j++) { if ((config.cellEnable[i] & (1 << j)) != 0) { count++; } } } return(count); }
void updateUI(BalancerComm.Config_t config) { txtCellCount.Text = Convert.ToString(config.cellCount); updnBoardCount.Value = config.slaveCount + 1; txtBoardCANID.Text = config.canID.ToString("X8"); txtCANDstID.Text = config.canDstID.ToString("X8"); txtBalPollPeriod.Text = config.balPollPeriod.ToString(); txtBalReplyTimeout.Text = config.balReplyTimeout.ToString(); txtCellVoltageBalance.Text = ((double)config.cellVoltageBalance / 1000).ToString(); txtBalanceOffset.Text = ((double)config.balanceOffset / 1000).ToString(); txtCellVoltageMax.Text = ((double)config.cellVoltageMax / 1000).ToString(); txtCellVoltageMin.Text = ((double)config.cellVoltageMin / 1000).ToString(); radioChgEnActHigh.Checked = config.chgEnActiveHigh > 0 ? true : false; radioChgEnActLow.Checked = !radioChgEnActLow.Checked; chkAFS1Enable.Checked = (config.analog1FunctionSelect & (byte)BalancerComm.AFS.AFS_ENABLE) > 0; radioAFS1Digital.Checked = (config.analog1FunctionSelect & (byte)BalancerComm.AFS.AFS_DIGITAL) > 0; radioAFS1Analog.Checked = !radioAFS1Digital.Checked; radioAFS1PolarityHigher.Checked = (config.analog1FunctionSelect & (byte)BalancerComm.AFS.AFS_POLARITY) > 0; radioAFS1PolarityLower.Checked = !radioAFS1PolarityHigher.Checked; radioAFS1ChargeLim.Checked = (config.analog1FunctionSelect & (byte)BalancerComm.AFS.AFS_FUNCTION) > 0; radioAFS1DischargeLim.Checked = !radioAFS1ChargeLim.Checked; chkAFS2Enable.Checked = (config.analog2FunctionSelect & (byte)BalancerComm.AFS.AFS_ENABLE) > 0; radioAFS2Digital.Checked = (config.analog2FunctionSelect & (byte)BalancerComm.AFS.AFS_DIGITAL) > 0; radioAFS2Analog.Checked = !radioAFS2Digital.Checked; radioAFS2PolarityHigher.Checked = (config.analog2FunctionSelect & (byte)BalancerComm.AFS.AFS_POLARITY) > 0; radioAFS2PolarityLower.Checked = !radioAFS2PolarityHigher.Checked; radioAFS2ChargeLim.Checked = (config.analog2FunctionSelect & (byte)BalancerComm.AFS.AFS_FUNCTION) > 0; radioAFS2DischargeLim.Checked = !radioAFS2ChargeLim.Checked; txtMaxVFilterFreq.Text = config.maxVFilterMult.ToString(); txtMinVFilterFreq.Text = config.minVFilterMult.ToString(); txtChargeLimPGain.Text = config.chargeLimitGain.ToString(); txtDischargeLimPGain.Text = config.dischargeLimitGain.ToString(); setCellGridCount(config.slaveCount + 1); setCellGrid(config.cellEnable); txtCurrentGain.Text = config.currentGain.ToString(); txtCurrentOffset.Text = config.currentOffset.ToString(); }
void updateConfig(ref BalancerComm.Config_t config) { config.slaveCount = (byte)(Convert.ToByte(updnBoardCount.Value) - 1); config.cellEnable = getCellGridData(); config.cellCount = (byte)getCellCount(config); config.canID = Convert.ToUInt32(txtBoardCANID.Text, 16); config.canDstID = Convert.ToUInt32(txtCANDstID.Text, 16); config.balPollPeriod = Convert.ToUInt16(txtBalPollPeriod.Text); config.balReplyTimeout = Convert.ToUInt16(txtBalReplyTimeout.Text); config.cellVoltageBalance = (UInt16)(Convert.ToDouble(txtCellVoltageBalance.Text) * 1000); config.balanceOffset = (UInt16)(Convert.ToDouble(txtBalanceOffset.Text) * 1000); config.cellVoltageMax = (UInt16)(Convert.ToDouble(txtCellVoltageMax.Text) * 1000); config.cellVoltageMin = (UInt16)(Convert.ToDouble(txtCellVoltageMin.Text) * 1000); config.chgEnActiveHigh = (byte)(radioChgEnActHigh.Checked ? 1 : 0); config.analog1FunctionSelect = (byte)((chkAFS1Enable.Checked ? (byte)BalancerComm.AFS.AFS_ENABLE : 0) | (radioAFS1Digital.Checked ? (byte)BalancerComm.AFS.AFS_DIGITAL : 0) | (radioAFS1PolarityHigher.Checked ? (byte)BalancerComm.AFS.AFS_POLARITY : 0) | (radioAFS1ChargeLim.Checked ? (byte)BalancerComm.AFS.AFS_FUNCTION : 0)); config.analog2FunctionSelect = (byte)((chkAFS2Enable.Checked ? (byte)BalancerComm.AFS.AFS_ENABLE : 0) | (radioAFS2Digital.Checked ? (byte)BalancerComm.AFS.AFS_DIGITAL : 0) | (radioAFS2PolarityHigher.Checked ? (byte)BalancerComm.AFS.AFS_POLARITY : 0) | (radioAFS2ChargeLim.Checked ? (byte)BalancerComm.AFS.AFS_FUNCTION : 0)); config.maxVFilterMult = Convert.ToUInt16(txtMaxVFilterFreq.Text); config.minVFilterMult = Convert.ToUInt16(txtMinVFilterFreq.Text); config.chargeLimitGain = Convert.ToUInt16(txtChargeLimPGain.Text); config.dischargeLimitGain = Convert.ToUInt16(txtDischargeLimPGain.Text); config.currentGain = Convert.ToUInt32(txtCurrentGain.Text); config.currentOffset = Convert.ToInt16(txtCurrentOffset.Text); }
private void cmdRead_Click(object sender, EventArgs e) { config = bc.getConfig(0xA); updateUI(config); }