矿石收音机论坛

 找回密码
 加入会员

QQ登录

只需一步,快速开始

搜索
查看: 5153|回复: 16

精确测量二极管参数应用软件源程序

[复制链接]
     
发表于 2020-2-8 11:22:36 | 显示全部楼层 |阅读模式
本帖最后由 gxg0000 于 2020-2-8 11:20 编辑

闲来无事,写上一段用c#编写的应用程序盼望交流,实际应用见本坛《精确测量二极管RD的方法》一贴
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using System.Runtime.InteropServices;
  10. using Microsoft.Win32;

  11. namespace WindowsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         Int32 V1, V2, V3, V4;
  20.         Double Id1, Id2;
  21.         Int32 Index; //
  22.         Int64[] R = new Int64[7]; //限流电阻R1, R2, R3, R4, R5, R6, R7
  23.         NumericUpDown[] numericUpDown = new NumericUpDown[7];
  24.         String[] str1 ={ "R1", "R2", "R3", "R4", "R5", "R6", "R7" };    //电阻的编号数组
  25.         Decimal[] str2 ={ 4700.0M, 1000.0M, 330.0M, 100.0M, 33.0M, 10.0M, 10000M }; //电阻初值数组
  26.         Int32 T=25;  //温度
  27.         Double IS = 171.34388778833204;   //饱和电流
  28.         Double RD = 160.40886801322117;  //零电阻
  29.         Double N = 1.0693751430533303;   //理想因子
  30.         Double VT = 0.025679647254953728;     //热电压
  31.         Double[] set1 ={ 1.0, 1.0, 1.0, 1.0 };   //IS,RD,N,VT
  32.         Double[] set2 ={ 1.0, 1.0, 1.0, 1.0 };
  33.         Double[] set3 ={ 1.0, 1.0, 1.0, 1.0 };
  34.         Double[] set4 ={ 1.0, 1.0, 1.0, 1.0 };
  35.         Double[] set5 ={ 1.0, 1.0, 1.0, 1.0 };  
  36.         Label[] lb1 = new Label[7];
  37.         Label[] lb2 = new Label[7];
  38.         Label[] lb3 = new Label[6];
  39.         Bitmap tup1;
  40.         Graphics g1;
  41.         private void Form1_Load(object sender, EventArgs e)
  42.         {
  43.             this.listBox1.LostFocus += new System.EventHandler(this.listBox1_LostFocus); //添加失去焦点事件
  44.             this.Controls.Add(panel1);
  45.             panel1.BringToFront();
  46.             panel1.Left = 522;
  47.             panel1.Top = 270;
  48.             panel1.Visible = false;
  49.             for (int i = 0; i < 7; i++)
  50.             {
  51.                 numericUpDown[i] = new NumericUpDown();
  52.                 numericUpDown[i].Cursor = Cursors.Hand;
  53.                 numericUpDown[i].Width = 57;
  54.                 numericUpDown[i].Height = 21;
  55.                 numericUpDown[i].Top = 33 + 27 * i;
  56.                 numericUpDown[i].Left = 102;
  57.                 numericUpDown[i].Minimum = 0M;
  58.                 if (i == 6)
  59.                 {
  60.                     numericUpDown[i].DecimalPlaces = 0;
  61.                     numericUpDown[i].Maximum = 20000M;
  62.                     numericUpDown[i].Increment = 1M;
  63.                 }
  64.                 else
  65.                 {
  66.                     numericUpDown[i].DecimalPlaces = 1;
  67.                     numericUpDown[i].Maximum =10000M;
  68.                     numericUpDown[i].Increment = 0.1M;
  69.                 }                  
  70.                 this.panel1.Controls.Add(numericUpDown[i]); //添加到控件集合
  71.                 numericUpDown[i].BringToFront();
  72.             }
  73.             //读取注册表保存的设置
  74.             if (null == Registry.GetValue(@"HKEY_CURRENT_USER\Software\二极管参数计算\Settings", "R1", ""))
  75.             {
  76.                 //第1次创建注册表子项,并将初值数据写入内存和注册表
  77.                 for (Int32 i = 0; i < 7; i++)
  78.                 {
  79.                     R[i] = Convert.ToInt64(str2[i]);
  80.                     numericUpDown[i].Value = str2[i];
  81.                     Registry.SetValue(@"HKEY_CURRENT_USER\Software\二极管参数计算\Settings", str1[i], str2[i]);
  82.                 }
  83.             }
  84.             else
  85.             {
  86.                 //读取注册表保存的子项内数据,并写入界面
  87.                 for (Int32 i = 0; i < 7; i++)
  88.                 {
  89.                     numericUpDown[i].Value = Convert.ToDecimal(Registry.GetValue(@"HKEY_CURRENT_USER\Software\二极管参数计算\Settings", str1[i], ""));
  90.                 }
  91.             }
  92.             Index = 3;
  93.             comboBox1.SelectedIndex = Index;
  94.             label6.Text = "电阻" + str1[Index] + ":";
  95.             listBox1.SelectedIndex = 1;
  96.             listBox1.Visible = false;
  97.             Drawing_Transfer_Characteristic(); //绘制曲线图形
  98.             System.IO.Directory.CreateDirectory("C:\\Documents and Settings\\User\\My Documents\\二极管参数表"); //创建保存数据的文件夹
  99.         }
  100.         /// <summary>
  101.         /// 计算Is,N,Rd
  102.         /// </summary>
  103.         /// <param name="sender"></param>
  104.         /// <param name="e"></param>
  105.         private void button1_Click(object sender, EventArgs e)
  106.         {
  107.             V1 = Convert.ToInt32(1000 * numericUpDown1.Value);
  108.             V2 = Convert.ToInt32(1000 * numericUpDown2.Value);
  109.             V3 = Convert.ToInt32(1000 * numericUpDown3.Value);
  110.             V4 = Convert.ToInt32(1000 * numericUpDown4.Value);
  111.             for (Int32 i = 0; i < 7; i++)
  112.             {
  113.                   R[i] = Convert.ToInt64(1000 * numericUpDown[i].Value);
  114.             }
  115.             for (Int32 i = 0; i < 6; i++)
  116.             {
  117.                 R[i] = (R[i] * R[6]) / (R[i] + R[6]);  //并联10M电阻后,修正DVM带来的误差
  118.             }
  119.             T = Convert.ToInt32(numericUpDown5.Value);
  120.             VT = ((273 + T) * 1.380649 / 1.602177) / 10000; //计算热电压
  121.             Id1 = 1000.0 * V2 / R[comboBox1.SelectedIndex] - 1000.0 * V1 / R[6]; //计算二极管电流(单位nA)
  122.             Id2 = 1000.0 * V4 / R[comboBox1.SelectedIndex] - 1000.0 * V3 / R[6];
  123.             Int32 n = 0;
  124.             Double Is1=0, Is2=0;
  125.             for (Int32 i = 0; i < 16; i++)                        //16位逐次逼近法
  126.             {
  127.                 n |= (1 << (15 - i));                                //预置转换位
  128.                 N = 0.5 + n / 21845.0;   //N(0.5~3.5)
  129.                 Is1 = Id1 / (Math.Exp(V1 / (VT * 1000000 * N)) - 1);
  130.                 Is2 = Id2 / (Math.Exp(V3 / (VT * 1000000 * N)) - 1);
  131.                 if (Is1 > Is2)                                                //
  132.                 {
  133.                     n &= ~(1 << (15 - i));                        //清零该位
  134.                     N = 0.5 + n / 21845.0;
  135.                 }                               
  136.             }
  137.             if (Is1 > Is2)
  138.             {
  139.                 if ((Is1 - Is2)/Is1 > 0.001)
  140.                     MessageBox.Show("方程无解!"); //误差超过0.1%,表示方程无法解出
  141.             }
  142.             else
  143.             {
  144.                 if ((Is2 - Is1) /Is2> 0.001)
  145.                     MessageBox.Show("方程无解!"); //显示错误
  146.             }
  147.             IS = (Is1 + Is2) / 2;
  148.             RD=1000000 * (VT * N / IS);
  149.             label26.Text = Convert.ToString(Convert.ToUInt32(IS));
  150.             label27.Text = Convert.ToString(Convert.ToUInt32(RD));
  151.             label28.Text = String.Format("{0:0.00}", N);
  152.             label16.Text = String.Format("{0:样本数据1: Vd1=0.0 mV}", Convert.ToDouble(numericUpDown1.Value));
  153.             label38.Text = String.Format("{0:Id1=0 nA}", Id1);
  154.             label17.Text = String.Format("{0:样本数据2: Vd2=0.0 mV}", Convert.ToDouble(numericUpDown3.Value));
  155.             label39.Text = String.Format("{0:Id2=0 nA}", Id2);
  156.             label18.Text = String.Format("{0:热电压:    VT=0.0 mV}", VT * 1000);
  157.             label29.Text = Convert.ToString(numericUpDown5.Value) + "℃";
  158.             Drawing_Transfer_Characteristic(); //绘制转移特性曲线
  159.         }
  160.        /// <summary>
  161.        /// 绘制二极管转移特性函数
  162.        /// </summary>
  163.        /// <param name="x">电压</param>
  164.        /// <param name="y">电流</param>
  165.         private void Drawing_Transfer_Characteristic()
  166.         {
  167.             tup1 = new Bitmap(201, 201);
  168.             g1 = Graphics.FromImage(tup1);
  169.             String[] str = new String[] { "正", "向", "电", "流", "IF", " " };
  170.             //写垂直数字刻度
  171.             for (int i = 0; i < 6; i++)
  172.             {
  173.                 lb1[i] = new Label();
  174.                 lb1[i].BackColor = this.tabPage5.BackColor; //背景颜色(取底色)
  175.                 lb1[i].Width = 30;
  176.                 lb1[i].Height = 15;
  177.                 lb1[i].TextAlign = ContentAlignment.MiddleRight;
  178.                 if (i == 5)
  179.                     lb1[i].Top = 20 + (40 * i - 3);
  180.                 else
  181.                     lb1[i].Top = 20 + 40 * i;
  182.                 lb1[i].Left = pictureBox1.Left - lb1[i].Width;
  183.                 lb1[i].Font = new Font("宋体", 9, FontStyle.Regular);
  184.                 lb1[i].Text = Convert.ToString((5 - i) * Convert.ToUInt32(numericUpDown6.Value) / 5);
  185.                 this.tabPage5.Controls.Add(lb1[i]); //添加到控件集合
  186.                 lb1[i].BringToFront();
  187.             }
  188.             for (int i = 0; i < 6; i++)
  189.             {
  190.                 lb3[i] = new Label();
  191.                 lb3[i].BackColor = this.tabPage5.BackColor; //背景颜色(取底色)
  192.                 lb3[i].Width = 35;
  193.                 lb3[i].Height = 15;
  194.                 lb3[i].TextAlign = ContentAlignment.MiddleCenter;
  195.                 lb3[i].ForeColor = Color.Green;
  196.                 lb3[i].Top = 80 + 15 * i;
  197.                 lb3[i].Left = 0;
  198.                 lb3[i].Font = new Font("宋体", 9, FontStyle.Bold);
  199.                 if (i == 5)
  200.                     lb3[i].Text = "(" + button2.Text.Substring(0, 2) + ")";
  201.                 else
  202.                     lb3[i].Text = str[i];
  203.                 this.tabPage5.Controls.Add(lb3[i]); //添加到控件集合
  204.                 lb3[i].BringToFront();
  205.             }
  206.             //写水平数字刻度
  207.             for (int i = 0; i < 7; i++)
  208.             {
  209.                 lb2[i] = new Label();
  210.                 lb2[i].BackColor = this.tabPage5.BackColor; //背景颜色(取底色)
  211.                 if (i != 6)
  212.                 {
  213.                     lb2[i].Width = 30;
  214.                     lb2[i].Height = 15;
  215.                     lb2[i].Top = 235;
  216.                     lb2[i].Left = 47 + 40 * i;  
  217.                     lb2[i].Text = Convert.ToString(i *Convert.ToUInt32(numericUpDown7.Value) / 5);
  218.                     lb2[i].Font = new Font("宋体", 9, FontStyle.Regular);
  219.                     lb2[i].ForeColor = Color.Black;
  220.                 }
  221.                 else
  222.                 {
  223.                     lb2[i].Width = 100;
  224.                     lb2[i].Height = 15;
  225.                     lb2[i].Top = 255;
  226.                     lb2[i].Left =120;
  227.                     lb2[i].Text = "正向电压VF(mV)";
  228.                     lb2[i].Font = new Font("宋体", 9, FontStyle.Bold);
  229.                     lb2[i].ForeColor = Color.Green;
  230.                 }
  231.                 lb2[i].TextAlign = ContentAlignment.MiddleCenter;              
  232.                 this.tabPage5.Controls.Add(lb2[i]); //添加到控件集合
  233.                 lb2[i].BringToFront();
  234.             }
  235.             g1.Clear(Color.AliceBlue);
  236.             //横线
  237.             for (int j = 0; j <= 200; j += 20)
  238.             {
  239.                 g1.DrawLine(new Pen(Color.Gainsboro), 0, j, 200, j);
  240.             }
  241.             //竖线
  242.             for (int j = 0; j <= 200; j += 20)
  243.             {
  244.                 g1.DrawLine(new Pen(Color.Gainsboro), j, 0, j, 200);
  245.             }
  246.             if (checkBox1.Checked == true)   //绘制叠加1
  247.             {
  248.                 Draw_Line(set1[0], set1[2], set1[3], button5.BackColor);
  249.             }
  250.             if (checkBox2.Checked == true)   //绘制叠加2
  251.             {
  252.                 Draw_Line(set2[0], set2[2], set2[3], button6.BackColor);
  253.             }
  254.             if (checkBox3.Checked == true)   //绘制叠加3
  255.             {
  256.                 Draw_Line(set3[0], set3[2], set3[3], button7.BackColor);
  257.             }
  258.             if (checkBox4.Checked == true)   //绘制叠加4
  259.             {
  260.                 Draw_Line(set4[0], set4[2], set4[3], button8.BackColor);
  261.             }
  262.             if (checkBox5.Checked == true)   //绘制叠加5
  263.             {
  264.                 Draw_Line(set5[0], set5[2], set5[3], button9.BackColor);
  265.             }
  266.             Draw_Line(IS, N, VT, Color.Green);  //绘制当前二极管伏安曲线
  267.             pictureBox1.Image = tup1;
  268.         }
  269.         private void Draw_Line(Double Is, Double n, Double vt, Color color) //绘制二极管伏安线函数
  270.         {
  271.             g1.DrawImage(tup1, 0, 0);
  272.             Double I1, I2, Vd; ;
  273.             Int32 k = Convert.ToInt32(Convert.ToString(listBox1.SelectedItem).Substring(4));
  274.             for (int V = 0; V < 200; V++)
  275.             {
  276.                 Vd = (V / 200.0) * Convert.ToUInt32(numericUpDown7.Value);   //mV            
  277.                 I1 = 200 * (Is * (Math.Exp(Vd / (1000 * vt * n)) - 1)) / (Convert.ToInt32(numericUpDown6.Value) * k); //nA
  278.                 if (I1 > 200)
  279.                     I1 = 200;
  280.                 Vd = ((V + 1) / 200.0) * Convert.ToUInt32(numericUpDown7.Value);  //mV
  281.                 I2 = 200 * (Is * (Math.Exp(Vd / (1000 * vt * n)) - 1)) / (Convert.ToInt32(numericUpDown6.Value) * k); //nA
  282.                 if (I2 > 200)
  283.                     I2 = 200;
  284.                 g1.DrawLine(new Pen(color), (float)V, (float)(200 - I1), (float)(V + 1), (float)(200 - I2));
  285.                 if ((I1 == 200) | (I2 == 200))
  286.                     break;
  287.             }
  288.         }
  289.         /// <summary>
  290.         /// 绘图XY坐标单位调整
  291.         /// </summary>
  292.         /// <param name="sender"></param>
  293.         /// <param name="e"></param>
  294.         private void button2_Click(object sender, EventArgs e)
  295.         {
  296.             listBox1.Visible = true; //显示电流单位列表
  297.             listBox1.Focus();  //设置listBox1控件焦点
  298.         }
  299.         private void listBox1_LostFocus(object sender, EventArgs e)
  300.         {
  301.             listBox1.Visible = false;  //失去焦点隐藏
  302.         }
  303.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  304.         {
  305.             button2.Text = listBox1.Text;
  306.             listBox1.Visible = false;
  307.             Drawing_Transfer_Characteristic();
  308.         }
  309.         private void numericUpDown6_ValueChanged(object sender, EventArgs e)
  310.         {
  311.             Drawing_Transfer_Characteristic();
  312.         }
  313.         private void numericUpDown7_ValueChanged(object sender, EventArgs e)
  314.         {
  315.             Drawing_Transfer_Characteristic();
  316.         }
复制代码


公开源代码;

补充内容 (2020-2-8 17:12):
谢谢老师们点赞!

补充内容 (2021-2-24 12:26):
13#是升级版

二极管参数计算.zip

261.81 KB, 下载次数: 152

评分

3

查看全部评分

     
 楼主| 发表于 2020-2-8 11:23:38 | 显示全部楼层
  1. /// <summary>
  2.         /// 保存二极管参数文件
  3.         /// </summary>
  4.         /// <param name="sender"></param>
  5.         /// <param name="e"></param>
  6.         private void button4_Click(object sender, EventArgs e)
  7.         {
  8.             saveFileDialog1.Filter = "文本文件(*.txt)|*.txt|全部文件|*.*";
  9.             saveFileDialog1.FilterIndex = 1; //指定第1个过滤器(默认的打开的方法)
  10.             saveFileDialog1.InitialDirectory = "C:\\Documents and Settings\\User\\My Documents\\二极管参数表";  //打开起始目录
  11.             if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  12.             {
  13.                 File.Delete(saveFileDialog1.FileName); //首先删除文件
  14.                 StreamWriter MyWriter = new StreamWriter(new FileStream(saveFileDialog1.FileName, FileMode.Append, FileAccess.Write)); //若无则创建新文件
  15.                 MyWriter.WriteLine(Convert.ToString(numericUpDown5.Value));  //写入温度
  16.                 MyWriter.WriteLine(Convert.ToString(IS));  //写入饱和电流IS
  17.                 MyWriter.WriteLine(Convert.ToString(RD));    //写入RD
  18.                 MyWriter.WriteLine(Convert.ToString(N));    //写入N
  19.                 MyWriter.WriteLine(Convert.ToString(VT));    //写入VT
  20.                 MyWriter.WriteLine("存放顺序第一行开始;温度T,饱和电流IS,零电阻RD,理想因子N,热电压VT");    //写入注解
  21.                 MyWriter.Close(); //关闭文件
  22.             }
  23.         }
  24.         /// <summary>
  25.         /// 读取二极管数据文件到内存
  26.         /// </summary>
  27.         /// <param name="sender"></param>
  28.         /// <param name="e"></param>
  29.         private void button5_Click(object sender, EventArgs e)
  30.         {
  31.             OpenFileDialog(1);
  32.         }
  33.         private void button6_Click(object sender, EventArgs e)
  34.         {
  35.             OpenFileDialog(2);
  36.         }
  37.         private void button7_Click(object sender, EventArgs e)
  38.         {
  39.             OpenFileDialog(3);
  40.         }
  41.         private void button8_Click(object sender, EventArgs e)
  42.         {
  43.             OpenFileDialog(4);
  44.         }
  45.         private void button9_Click(object sender, EventArgs e)
  46.         {
  47.             OpenFileDialog(5);
  48.         }
  49.         private void OpenFileDialog(Int32 k)   //读数据文件到数组
  50.         {
  51.             openFileDialog1.Filter = "文本文件(*.txt)|*.txt|全部文件|*.*";
  52.             openFileDialog1.FilterIndex = 1; //指定第1个过滤器(默认的打开的方法)
  53.             openFileDialog1.InitialDirectory = "C:\\Documents and Settings\\User\\My Documents\\二极管参数表";  //打开起始目录
  54.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  55.             {
  56.                 StreamReader MyWriter = new StreamReader(new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read)); //若无则创建新文件
  57.                 String n0 = Path.GetFileNameWithoutExtension(openFileDialog1.FileName) + "(" + MyWriter.ReadLine() + "℃)"; //读出文件名和温度
  58.                 Double n1 = Convert.ToDouble(MyWriter.ReadLine());  //读IS饱和电流
  59.                 Double n2 = Convert.ToDouble(MyWriter.ReadLine());  //读RD
  60.                 Double n3 = Convert.ToDouble(MyWriter.ReadLine());  //读N
  61.                 Double n4 = Convert.ToDouble(MyWriter.ReadLine());  //读VT
  62.                 MyWriter.Close(); //关闭文件
  63.                 if ((n1 == 0.0) | (n3 == 0.0) | (n4 == 0.0))
  64.                 {
  65.                     MessageBox.Show("二极管数据文件格式不正确", "警告!");
  66.                 }
  67.                 else
  68.                 {
  69.                     switch (k)
  70.                     {
  71.                         case 1:
  72.                             checkBox1.Text = n0;
  73.                             set1[0] = n1;
  74.                             set1[1] = n2;
  75.                             set1[2] = n3;
  76.                             set1[3] = n4;
  77.                             checkBox1.Enabled = true;
  78.                             break;
  79.                         case 2:
  80.                             checkBox2.Text = n0;
  81.                             set2[0] = n1;
  82.                             set2[1] = n2;
  83.                             set2[2] = n3;
  84.                             set2[3] = n4;
  85.                             checkBox2.Enabled = true;
  86.                             break;
  87.                         case 3:
  88.                             checkBox3.Text = n0;
  89.                             set3[0] = n1;
  90.                             set3[1] = n2;
  91.                             set3[2] = n3;
  92.                             set3[3] = n4;
  93.                             checkBox3.Enabled = true;
  94.                             break;
  95.                         case 4:
  96.                             checkBox4.Text = n0;
  97.                             set4[0] = n1;
  98.                             set4[1] = n2;
  99.                             set4[2] = n3;
  100.                             set4[3] = n4;
  101.                             checkBox4.Enabled = true;
  102.                             break;
  103.                         case 5:
  104.                             checkBox5.Text = n0;
  105.                             set5[0] = n1;
  106.                             set5[1] = n2;
  107.                             set5[2] = n3;
  108.                             set5[3] = n4;
  109.                             checkBox5.Enabled = true;
  110.                             break;
  111.                     }
  112.                 }   
  113.             }
  114.         }
  115.         /// <summary>
  116.         /// 复选框叠加绘图
  117.         /// </summary>
  118.         /// <param name="sender"></param>
  119.         /// <param name="e"></param>
  120.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  121.         {
  122.             Drawing_Transfer_Characteristic();
  123.             if (checkBox1.Checked == true)
  124.                 radioButton3.Enabled = true;
  125.             else
  126.             {
  127.                 radioButton3.Enabled = false;
  128.                 if (radioButton3.Checked == true)
  129.                     radioButton8.Checked = true;
  130.             }
  131.         }
  132.         private void checkBox2_CheckedChanged(object sender, EventArgs e)
  133.         {
  134.             Drawing_Transfer_Characteristic();
  135.             if (checkBox2.Checked == true)
  136.                 radioButton4.Enabled = true;
  137.             else
  138.             {
  139.                 radioButton4.Enabled = false;
  140.                 if (radioButton4.Checked == true)
  141.                     radioButton8.Checked = true;
  142.             }
  143.         }
  144.         private void checkBox3_CheckedChanged(object sender, EventArgs e)
  145.         {
  146.             Drawing_Transfer_Characteristic();
  147.             if (checkBox3.Checked == true)
  148.                 radioButton5.Enabled = true;
  149.             else
  150.             {
  151.                 radioButton5.Enabled = false;
  152.                 if (radioButton5.Checked == true)
  153.                     radioButton8.Checked = true;
  154.             }
  155.         }
  156.         private void checkBox4_CheckedChanged(object sender, EventArgs e)
  157.         {
  158.             Drawing_Transfer_Characteristic();
  159.             if (checkBox4.Checked == true)
  160.                 radioButton6.Enabled = true;
  161.             else
  162.             {
  163.                 radioButton6.Enabled = false;
  164.                 if (radioButton6.Checked == true)
  165.                     radioButton8.Checked = true;
  166.             }
  167.         }
  168.         private void checkBox5_CheckedChanged(object sender, EventArgs e)
  169.         {
  170.             Drawing_Transfer_Characteristic();
  171.             if (checkBox5.Checked == true)
  172.                 radioButton7.Enabled = true;
  173.             else
  174.             {
  175.                 radioButton7.Enabled = false;
  176.                 if (radioButton7.Checked == true)
  177.                     radioButton8.Checked = true;
  178.             }
  179.         }
  180.         /// <summary>
  181.         /// 鼠标指针即时Rd显示数据
  182.         /// </summary>
  183.         /// <param name="sender"></param>
  184.         /// <param name="e"></param>
  185.         private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  186.         {         
  187.             Int32 Rd=0;
  188.             Double Is,n,vt;
  189.             Bitmap tup2 = new Bitmap(201, 201);
  190.             Graphics g2 = Graphics.FromImage(tup2);
  191.             Pen pen;
  192.             Brush brush1;
  193.             Brush brush2 = new SolidBrush(pictureBox1.BackColor);
  194.             //判断跟踪曲线
  195.             if (radioButton3.Enabled & radioButton3.Checked)
  196.             {
  197.                 pen = new Pen(button5.BackColor);
  198.                 brush1 = new SolidBrush(button5.BackColor);
  199.                 Is = set1[0];
  200.                 n = set1[2];
  201.                 vt = set1[3];
  202.             }
  203.             else if (radioButton4.Enabled & radioButton4.Checked)
  204.             {
  205.                 pen = new Pen(button6.BackColor);
  206.                 brush1 = new SolidBrush(button6.BackColor);
  207.                 Is = set2[0];
  208.                 n = set2[2];
  209.                 vt = set2[3];
  210.             }
  211.             else if (radioButton5.Enabled & radioButton5.Checked)
  212.             {
  213.                 pen = new Pen(button7.BackColor);
  214.                 brush1 = new SolidBrush(button7.BackColor);
  215.                 Is = set3[0];
  216.                 n = set3[2];
  217.                 vt = set3[3];
  218.             }
  219.             else if (radioButton6.Enabled & radioButton6.Checked)
  220.             {
  221.                 pen = new Pen(button8.BackColor);
  222.                 brush1 = new SolidBrush(button8.BackColor);
  223.                 Is = set4[0];
  224.                 n = set4[2];
  225.                 vt = set4[3];
  226.             }
  227.             else if (radioButton7.Enabled & radioButton7.Checked)
  228.             {
  229.                 pen = new Pen(button9.BackColor);
  230.                 brush1 = new SolidBrush(button9.BackColor);
  231.                 Is = set5[0];
  232.                 n = set5[2];
  233.                 vt = set5[3];
  234.             }
  235.             else
  236.             {
  237.                 pen = new Pen(Color.Green);
  238.                 brush1 = new SolidBrush(Color.Green);
  239.                 Is = IS;
  240.                 n = N;
  241.                 vt = VT;
  242.             }
  243.             Double Vd=(e.X / 200.0) * Convert.ToUInt32(numericUpDown7.Value);    //正向电压mV
  244.             Double Id = Is * (Math.Exp(Vd / (1000 * vt * n)) - 1); //正向电压对于的正向电流nA
  245.             Int32 k = Convert.ToInt32(Convert.ToString(listBox1.SelectedItem).Substring(4)); //纵坐标单位
  246.             Int32 I = (int)(200 * (Id / (Convert.ToInt32(numericUpDown6.Value) * k))); //纵坐标
  247.             if (I > 200) I = 200;
  248.             if (Id == 0.0) Id = 1;
  249.             //鼠标靠近曲线悬停字符串显示
  250.             if (((e.Y - (200 - I)) < 5)&(( (200 - I)- e.Y) <5))
  251.             {
  252.                 Rd = (Convert.ToInt32(1000000000 * ((n * vt / Id) * Math.Log((Id / Is) + 1, Math.E))));    //计算动态电阻Rd
  253.                 String str;
  254.                 if (Rd < 1000)
  255.                     str = "Rd=" + Rd.ToString() + "Ω";
  256.                 else
  257.                 {
  258.                     Rd = Rd / 1000;
  259.                     str = "Rd=" + Rd.ToString() + "kΩ";
  260.                 }
  261.                 //绘制悬停字符串
  262.                 g2.DrawImage(tup1, 0, 0);  //复制
  263.                 int x1 = 0;
  264.                 int y1 = 0;
  265.                 SizeF sizeF = g2.MeasureString(str, new Font("宋体", 9, FontStyle.Regular));//测量字符串长度
  266.                 if (e.X > (int)sizeF.Width) //区分在鼠标左或右显示字符串
  267.                     x1 = e.X - (int)sizeF.Width;
  268.                 else
  269.                     x1 = e.X + 5;
  270.                 if (e.Y < (int)sizeF.Height)//区分在鼠标上或下显示字符串
  271.                     y1 = e.Y;
  272.                 else
  273.                     y1 = e.Y - (int)sizeF.Height;
  274.                 g2.DrawString(str, new Font("宋体", 9, FontStyle.Regular),brush1, x1, y1);
  275.                 g2.FillEllipse(brush2, e.X - 2, (200 - I) - 2, 4, 4);  //绘制实心圆
  276.                 g2.DrawEllipse(pen, e.X - 2, (200 - I) - 2, 4, 4); //绘制圆圈
  277.                
  278.                 pictureBox1.Image = tup2;
  279.             }
  280.             else
  281.             {
  282.                 pictureBox1.Image = tup1;//回复原图
  283.             }
  284.         }
  285.         private void pictureBox1_MouseLeave(object sender, EventArgs e)
  286.         {
  287.             pictureBox1.Image = tup1;
  288.         }
  289.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  290.         {
  291.             if (comboBox1.Text == "校电阻")
  292.             {
  293.                 panel1.Visible = true;
  294.                 panel1.Focus();
  295.                 for (Int32 i = 0; i < 7; i++)
  296.                 {
  297.                     numericUpDown[i].Value = Convert.ToDecimal(Registry.GetValue(@"HKEY_CURRENT_USER\Software\二极管参数计算\Settings", str1[i], ""));
  298.                 }
  299.                 groupBox1.Enabled = false;
  300.             }
  301.             else
  302.             {
  303.                 Index = comboBox1.SelectedIndex;
  304.                 label6.Text = "电阻" + str1[Index] + ":";
  305.             }
  306.         }
  307.         /// <summary>
  308.         /// 保存退出
  309.         /// </summary>
  310.         /// <param name="sender"></param>
  311.         /// <param name="e"></param>
  312.         private void button10_Click(object sender, EventArgs e)
  313.         {         
  314.             //数据写入注册表子项
  315.             for (Int32 i = 0; i < 7; i++)
  316.             {
  317.                 Registry.SetValue(@"HKEY_CURRENT_USER\Software\二极管参数计算\Settings", str1[i], numericUpDown[i].Value);
  318.             }
  319.             panel1.Visible = false;
  320.             groupBox1.Enabled = true;
  321.             comboBox1.SelectedIndex = Index;
  322.             label6.Text = "电阻" + str1[Index] + ":"; //恢复原来的comboBox1选项
  323.         }
  324.         /// <summary>
  325.         /// 放弃
  326.         /// </summary>
  327.         /// <param name="sender"></param>
  328.         /// <param name="e"></param>
  329.         private void button11_Click(object sender, EventArgs e)
  330.         {
  331.             panel1.Visible = false;
  332.             groupBox1.Enabled = true;
  333.             comboBox1.SelectedIndex = Index;
  334.             label6.Text = "电阻" + str1[Index] + ":";
  335.         }
  336.     }
  337. }
复制代码




评分

2

查看全部评分

回复 支持 反对

使用道具 举报

     
发表于 2020-2-8 13:04:28 来自手机 | 显示全部楼层
下位机是使用单片机测量吗?然后传到电脑上处理数据?

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2020-2-8 17:09:52 | 显示全部楼层
分立元件 发表于 2020-2-8 13:04
下位机是使用单片机测量吗?然后传到电脑上处理数据?

独立的软件,与测试装置不产生通信
回复 支持 反对

使用道具 举报

     
发表于 2020-2-9 10:33:29 | 显示全部楼层
gxg0000 发表于 2020-2-8 17:09
独立的软件,与测试装置不产生通信

lz的编程水平很高,借机会学习啦,谢谢!

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2020-2-9 11:30:20 | 显示全部楼层
peiguoqing 发表于 2020-2-9 10:33
lz的编程水平很高,借机会学习啦,谢谢!

业余的,与.net高手比起来漏洞百出
回复 支持 反对

使用道具 举报

     
发表于 2020-3-23 09:58:22 | 显示全部楼层
好厉害!我也想学学c编程,就是贪玩每次都找理由干其他事了。lz值得我学习!

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

     
发表于 2020-3-26 12:10:32 | 显示全部楼层
不错不错,要是能做成自动切换量程的电路就好了。

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2020-5-5 16:42:34 | 显示全部楼层
drzhu 发表于 2020-3-23 09:58
好厉害!我也想学学c编程,就是贪玩每次都找理由干其他事了。lz值得我学习!

有基础的学起来比较容易,但学会都是一些皮毛的东西,精通则需要长年累月
回复 支持 反对

使用道具 举报

     
发表于 2020-5-5 17:21:54 | 显示全部楼层
gxg0000 发表于 2020-5-5 16:42
有基础的学起来比较容易,但学会都是一些皮毛的东西,精通则需要长年累月

嗯,认真做好一件事真不容易!需要长期积累,需要热情,需要~~~
回复 支持 反对

使用道具 举报

     
发表于 2020-12-31 19:46:26 来自手机 | 显示全部楼层
非常好的工作,为楼主点赞。

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2020-12-31 21:02:54 来自手机 | 显示全部楼层
mike 发表于 2020-12-31 19:46
非常好的工作,为楼主点赞。

多谢捧场!
回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2021-2-24 12:20:33 | 显示全部楼层
本帖最后由 gxg0000 于 2021-2-24 12:24 编辑

对应用程序进行升级,主要两个方面;
1.修改了一个漏洞,当程序长时间连续循环执行是,会不断对动态生成的控件类实例化,长期运行会造成内存泄漏,而使应用程序卡死。
2.增加了新的选项卡内容

应用程序(安装版):
Debug.zip (430.06 KB, 下载次数: 39)

公开源代码:
二极管参数计算(升级).zip (233.22 KB, 下载次数: 44)


打开的应用程序界面:
Image 1.png






回复 支持 反对

使用道具 举报

     
发表于 2021-2-25 12:16:10 | 显示全部楼层
gxg0000 发表于 2021-2-24 12:20
对应用程序进行升级,主要两个方面;
1.修改了一个漏洞,当程序长时间连续循环执行是,会不断对动态生成的 ...

不是这个.NET系统有个垃圾回收机制,只管new objectJ()就行吗?
楼主敞亮,公开的源代码很好。

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2021-2-25 14:24:57 | 显示全部楼层
peiguoqing 发表于 2021-2-25 12:16
不是这个.NET系统有个垃圾回收机制,只管new objectJ()就行吗?
楼主敞亮,公开的源代码很 ...

在作用域内,对象实例被声明在循环体内部,每次执行循环体时,都会为对象重新分配内存,并初始化对象实例,重复执行会不断的消耗内存,回收发生在出了作用域以后
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 加入会员

本版积分规则

小黑屋|手机版|矿石收音机 ( 蒙ICP备05000029号-1 )

蒙公网安备 15040402000005号

GMT+8, 2024-4-25 07:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表