예제 #1
0
 private void button12_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < dgvCalcDc.Rows.Count; i++)
     {
         /*
          * if (WriteReg(2, (byte)i, (UInt16)UInt16.Parse(dgvCalcDc.Rows[i].Cells[3].Value.ToString(), System.Globalization.NumberStyles.HexNumber)) == false)
          * {
          *  MessageBox.Show("写入失败");
          *  return;
          * }
          * if (WriteReg(2, (byte)(i + 0x10), (UInt16)UInt16.Parse(dgvCalcDc.Rows[i].Cells[4].Value.ToString(), System.Globalization.NumberStyles.HexNumber)) == false)
          * {
          *  MessageBox.Show("写入失败");
          *  return;
          * }
          * */
         UInt16 val   = 0;
         byte   board = (byte)UInt16.Parse(textBoxBoardAddr.Text);
         val = UInt16.Parse(dgvCalcDc.Rows[i].Cells[3].Value.ToString(), System.Globalization.NumberStyles.HexNumber);
         if (Funs485.WriteDebugReg(board, (byte)i, val) == false)
         {
             MessageBox.Show("写入失败");
             return;
         }
         val = UInt16.Parse(dgvCalcDc.Rows[i].Cells[4].Value.ToString(), System.Globalization.NumberStyles.HexNumber);
         if (Funs485.WriteDebugReg(board, (byte)(i + 0x10), val) == false)
         {
             MessageBox.Show("写入失败");
             return;
         }
     }
     MessageBox.Show("写入完成");
 }
예제 #2
0
        private void btnCalcAndWrite_Click(object sender, EventArgs e)
        {
            try
            {
                for (int index = 0; index < this.dgvCalcDc.Rows.Count; ++index)
                {
                    this.dgvCalcDc.Rows[index].Cells[3].Value = (object)short.Parse(this.dgvCalcDc.Rows[index].Cells[0].Value.ToString()).ToString("X4");
                    int num = (int)short.Parse(this.dgvCalcDc.Rows[index].Cells[1].Value.ToString()) - (int)short.Parse(this.dgvCalcDc.Rows[index].Cells[0].Value.ToString());
                    this.dgvCalcDc.Rows[index].Cells[4].Value = (object)((int)short.Parse(this.dgvCalcDc.Rows[index].Cells[2].Value.ToString()) * 4096 / (int)(short)((int)short.Parse(this.dgvCalcDc.Rows[index].Cells[1].Value.ToString()) - (int)short.Parse(this.dgvCalcDc.Rows[index].Cells[0].Value.ToString()))).ToString("X4");
                }
            }
            catch
            {
            }
            byte boardAddr = (byte)ushort.Parse(this.textBoxBoardAddr.Text);

            Funs485.Rst(boardAddr);
            Funs485.UnLock(boardAddr);
            for (int index = 0; index < this.dgvCalcDc.Rows.Count; ++index)
            {
                ushort val1 = ushort.Parse(this.dgvCalcDc.Rows[index].Cells[3].Value.ToString(), NumberStyles.HexNumber);
                if (!Funs485.WriteDebugReg(boardAddr, (ushort)(byte)index, val1))
                {
                    int num = (int)MessageBox.Show("写入失败");
                    return;
                }
                else
                {
                    ushort val2 = ushort.Parse(this.dgvCalcDc.Rows[index].Cells[4].Value.ToString(), NumberStyles.HexNumber);
                    if (!Funs485.WriteDebugReg(boardAddr, (ushort)(byte)(index + 16), val2))
                    {
                        int num = (int)MessageBox.Show("写入失败");
                        return;
                    }
                }
            }
            this.boardAddress1 = (int)byte.Parse(this.textBoxBoardAddr.Text);
            if (!this.WriteReg(this.boardAddress1, (ushort)528, (ushort)43605))
            {
                int num1 = (int)MessageBox.Show("写入失败");
            }
            else
            {
                int num2 = (int)MessageBox.Show("写入成功");
            }
        }