public void AddPart(ushort nRegAddr, byte nBitLow, byte nBitHigh) { classPartOfReg item = new classPartOfReg(); item.nRegAddr = nRegAddr; item.nBitLow = nBitLow; item.nBitHigh = nBitHigh; m_listPart.Add(item); }
/// <summary> /// 从2200的寄存器地址和起始终止位转换为FPGA寄存器的地址和起始位终止位 /// </summary> /// <param name="src"></param> /// <returns></returns> public classPartOfReg TransformAddr(classPartOfReg src) { //------------寄存器地址和位的转换------------ classPartOfReg objNew = new classPartOfReg(); byte nBitLow, nBitHigh; nBitLow = nBitHigh = 0; nBitLow = (byte)src.nBitLow; nBitHigh = (byte)src.nBitHigh; ushort regAddr = 0; regAddr = (ushort)src.nRegAddr; if (regAddr >= 0xF0)//针对F0,F1,F2,F3这三个地址 { regAddr -= 0xF0; regAddr += 0x0E; } //针对寄存器地址0x01到0x0D if (nBitLow > 15) //起始位高于15的话就是高16位 { regAddr += 0x5E; //高16bit的地址 //起始位需要减去16 nBitLow -= 16; nBitHigh -= 16; } else { regAddr += 0x6F; //低16bit的地址 } regAddr--; //减去1 objNew.nRegAddr = regAddr; objNew.nBitLow = nBitLow; objNew.nBitHigh = nBitHigh; return(objNew); }
/// <summary> /// 显示数据到控件或者将控件数据保存起来 /// </summary> /// <param name="nMode"></param> /// <param name="bUpdate"></param> public void UpdateData(int nMode, bool bUpdate = true) { if (bUpdate) { //从控件上获取值 //foreach (classCtrlBindData item in m_listCtrl) foreach (KeyValuePair <Control, classCtrlBindData> item in m_dictCtrl) { Control ctrl = item.Key; string szType = ctrl.GetType().ToString(); ushort val = 0; if (szType == "System.Windows.Forms.ComboBox") { val = (ushort)((ctrl as ComboBox).SelectedIndex); } else if (szType == "System.Windows.Forms.NumericUpDown") { val = (ushort)((ctrl as NumericUpDown).Value); } //将数值保存到内存数组 foreach (classPartOfReg subItem in item.Value.m_listPart) { //修改内存中的数据 Change2072RegiseterVal(nMode, subItem.nRegAddr, subItem.nBitLow, subItem.nBitHigh, val); } } } else { //将数值显示到控件 //foreach (classCtrlBindData item in m_listCtrl) foreach (KeyValuePair <Control, classCtrlBindData> item in m_dictCtrl) { Control ctrl = item.Key; classPartOfReg subItem = item.Value.m_listPart[0];//只取第一个 //取出数值 int val = GetPartOfUInt32(nMode, (ushort)subItem.nRegAddr, (byte)subItem.nBitLow, (byte)subItem.nBitHigh); if (val != -1) { string szType = ctrl.GetType().ToString(); if (szType == "System.Windows.Forms.ComboBox") { //(arrCtrl[0] as ComboBox).SelectedIndex = val; //2018-08-28 防止输入值超出范围的报错 ComboBox cb = (ComboBox)(ctrl); if (cb.Items.Count > 0) { if ((val >= 0) && (val <= cb.Items.Count - 1)) { cb.SelectedIndex = val; } else { cb.SelectedIndex = 0; } } } else if (szType == "System.Windows.Forms.NumericUpDown") { //(arrCtrl[0] as NumericUpDown).Value = val; //2018-08-28 防止输入值超出范围的报错 NumericUpDown input = (NumericUpDown)ctrl; if ((val >= input.Minimum) && (val <= input.Maximum)) { input.Value = val; } else { input.Value = input.Minimum; } } } } } }