//timer2的函数,用于得到电压 private void timer2_Tick(object sender, EventArgs e) { DateTime time_record = DateTime.Now; //记录每次采集数据时的时间,目的在于形成时间戳。 TimeSpan timespan = time_record - start; timespanList.Add((timespan.TotalSeconds).ToString("G")); int deviceTempID = DllClass.GetYavData(0, ref dataBuffer[0], 512, ref YavParam[0], ref CNTBuffer[0], ref IOBuffer[0]); Console.WriteLine("dataBuffer[1]: " + dataBuffer[1]); // val1 = (dataBuffer[1] * 30.0 / 4095) * 1.011 + 0.01; //最小二乘函数 val1 = (dataBuffer[1] * 30.0 / 4095) * 1.011 + 0.002; //最小二乘函数 voltList.Add(val1.ToString()); this.Invoke(textVoltChanged, new string[] { val1 + "" }); Console.WriteLine("val1: " + val1); }
private void stopExp() { end_cancel = DateTime.Now; button2.Enabled = true; button3.Enabled = false; timer1.Enabled = false; timer2.Enabled = false; timer3.Enabled = false; //到达规定的时间后,计时器停止。 sp2.Close(); int cyd = DllClass.CloseYavDevice(0); Console.WriteLine("cyd " + cyd); if (cyd != 1) //1代表设备正常关闭,来源:厂商技术人员说的。 { MessageBox.Show("采集卡设备未正常关闭!"); } saveSpectralAndVoltData(); }
//点击开始按钮发生的事件 private void button2_Click(object sender, EventArgs e) { //每次点击开始测试时,都将flag的值置为false flag = false; //表示先采集亮度的数据 //获取最大电流密度 int I_intensity = Convert.ToInt32(textBox6.Text); int len = Convert.ToInt32(textBox4.Text); int width = Convert.ToInt32(textBox5.Text); double d = (I_intensity / (len * width)) * 1000; I_maxIntensity = d.ToString("G"); label14.Text = I_maxIntensity; //设置计时器的时间间隔 time = int.Parse(textBox1.Text) * 1000; timer1.Interval = time; //用于测试亮度的计时器 timer2.Interval = time; //用于测试电压的计时器 String timer3_interval = textBox7.Text; timer3.Interval = int.Parse(timer3_interval) * 60000; //分钟转为毫秒 start = DateTime.Now; illuminaceList = new List <string>(); voltList = new List <string>(); timespanList = new List <string>(); button2.Enabled = false; button3.Enabled = true; if (!sp2.IsOpen) { sp2.Open(); sp2.Close(); Thread.Sleep(1000); sp2.Open(); String command = "d\n"; sp2.WriteLine(command); String command0 = "S,,,,,,,1\n"; sp2.WriteLine(command0); } else { sp2.Close(); Thread.Sleep(1000); sp2.Open(); String command = "d\n"; sp2.WriteLine(command); String command0 = "S,,,,,,,1\n"; sp2.WriteLine(command0); } int num = DllClass.FindDevice(); Console.WriteLine("设备数: " + num); if (num > 0) { int openFlag = DllClass.OpenYavDevice(0); if (openFlag == 1) { Byte[] param = { 0x07, 0, 0, 0 }; //设置设备 0 的采样率为 1K int result = DllClass.SetYavParam(0, 0xFA, ref param[0]); //只有配置正确后,才能进行测试电压和亮度 timer1.Enabled = true; timer2.Enabled = true; timer3.Enabled = true; } else { MessageBox.Show("usb设备未打开"); } } else { MessageBox.Show("没有发现usb设备"); } }