private void btParamSet_Click(object sender, EventArgs e) { tbDateTime.Text = DateTime.Now.ToString(); if (!WFNetLib.WFGlobal.OpenSerialPort(ref serialPort1, "调试串口")) { return; } byte[] tx = new byte[16]; tx[0] = (byte)(DateTime.Now.Year - 2000); tx[1] = (byte)(DateTime.Now.Month); tx[2] = (byte)(DateTime.Now.Day); tx[3] = (byte)(DateTime.Now.DayOfWeek); tx[4] = (byte)(DateTime.Now.Hour); tx[5] = (byte)(DateTime.Now.Minute); tx[6] = (byte)(DateTime.Now.Second); CP68Packet ret = CP68Packet.CP68ComProc(ref serialPort1, CommandConst.CP68_UserCommand_WriteDeviceParams, tx); if (ret != null) { if (ret.Header.ControlCode == (byte)(CommandConst.CP68_UserCommand_WriteDeviceParams | 0x80)) { MessageBox.Show("设定成功"); } else { MessageBox.Show("设定失败"); } } serialPort1.Close(); }
private void btQCalc_Click(object sender, EventArgs e) { double x1, x2, x3, x4; x1 = double.Parse(listView2.Items[3].SubItems[1].Text); x2 = double.Parse(listView2.Items[4].SubItems[1].Text); x3 = double.Parse(listView2.Items[5].SubItems[1].Text); x4 = double.Parse(listView2.Items[6].SubItems[1].Text); double[] x = new double[25] { 1, 0, 0, 0, 0, 1, x1, x1 *x1, x1 *x1 *x1, x1 *x1 *x1 *x1, 1, x2, x2 *x2, x2 *x2 *x2, x2 *x2 *x2 *x2, 1, x3, x3 *x3, x3 *x3 *x3, x3 *x3 *x3 *x3, 1, x4, x4 *x4, x4 *x4 *x4, x4 *x4 *x4 *x4, }; double[] Q = new double[5] { 0, 70, 350, 3500, 7000 }; Matrix A = Matrix.Create(5, 5, x); GaussElimination ge = new GaussElimination(A, Q); // double[] Q1 = new double[4]; // Q1[0] = ge.X[0] + ge.X[1] * x1 + ge.X[2] * x1 * x1 + ge.X[3] * x1 * x1 * x1; // Q1[1] = ge.X[0] + ge.X[1] * x2 + ge.X[2] * x2 * x2 + ge.X[3] * x2 * x2 * x2; // Q1[2] = ge.X[0] + ge.X[1] * x3 + ge.X[2] * x3 * x3 + ge.X[3] * x3 * x3 * x3; // Q1[3] = ge.X[0] + ge.X[1] * x4 + ge.X[2] * x4 * x4 + ge.X[3] * x4 * x4 * x4; if (!WFNetLib.WFGlobal.OpenSerialPort(ref serialPort1, "调试串口")) { return; } byte[] a0B = BitConverter.GetBytes(((float)ge.X[1])); byte[] a1B = BitConverter.GetBytes(((float)ge.X[2])); byte[] a2B = BitConverter.GetBytes(((float)ge.X[3])); byte[] a3B = BitConverter.GetBytes(((float)ge.X[4])); byte[] tx = new byte[16]; for (int i = 0; i < 4; i++) { tx[i] = a0B[i]; tx[4 + i] = a1B[i]; tx[8 + i] = a2B[i]; tx[12 + i] = a3B[i]; } CP68Packet ret = CP68Packet.CP68ComProc(ref serialPort1, CommandConst.CP68_UserCommand_WriteQCalc, tx); if (ret != null) { if (ret.Header.ControlCode == (byte)(CommandConst.CP68_UserCommand_WriteTCalc | 0x80)) { MessageBox.Show("设定成功"); } else { MessageBox.Show("设定失败"); } } serialPort1.Close(); }
private void button3_Click(object sender, EventArgs e) { if (!WFNetLib.WFGlobal.OpenSerialPort(ref serialPort1, "调试串口")) { return; } float t1 = 0.0f; float t2 = 100.0f; float adin1 = float.Parse(listView1.Items[12].SubItems[1].Text); float adin2 = float.Parse(listView1.Items[15].SubItems[1].Text); float adout1 = float.Parse(listView1.Items[13].SubItems[1].Text); float adout2 = float.Parse(listView1.Items[16].SubItems[1].Text); float kin = (t2 - t1) / (adin2 - adin1); float bin = t1 - kin * adin1; float kout = (t2 - t1) / (adout2 - adout1); float bout = t1 - kout * adout1; // float kin = 1.987f; // float bin = 2.365f; // float kout = -5.687f; // float bout = -7.668f; byte[] k1B = BitConverter.GetBytes(kin); byte[] b1B = BitConverter.GetBytes(bin); byte[] k2B = BitConverter.GetBytes(kout); byte[] b2B = BitConverter.GetBytes(bout); byte[] tx = new byte[16]; for (int i = 0; i < 4; i++) { tx[i] = k1B[i]; tx[4 + i] = b1B[i]; tx[8 + i] = k2B[i]; tx[12 + i] = b2B[i]; } CP68Packet ret = CP68Packet.CP68ComProc(ref serialPort1, CommandConst.CP68_UserCommand_WriteTCalc, tx); if (ret != null) { if (ret.Header.ControlCode == (byte)(CommandConst.CP68_UserCommand_WriteTCalc | 0x80)) { MessageBox.Show("设定成功"); } else { MessageBox.Show("设定失败"); } } serialPort1.Close(); }
private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; CP68Packet ret = CP68Packet.CP68ComProc(ref serialPort1, CommandConst.CP68_UserCommand_ReadAD, null); this.Invoke((EventHandler)(delegate { if (ret != null) { t1ad = BytesOP.MakeShort(ret.Data[1], ret.Data[0]); listView1.Items[0].SubItems[1].Text = t1ad.ToString(); t2ad = BytesOP.MakeShort(ret.Data[3], ret.Data[2]); listView1.Items[4].SubItems[1].Text = t2ad.ToString(); // vinad = BytesOP.MakeShort(ret.Data[5], ret.Data[4]); // listView1.Items[8].SubItems[1].Text = vinad.ToString(); // vrefad = BytesOP.MakeShort(ret.Data[7], ret.Data[6]); // listView1.Items[9].SubItems[1].Text = vrefad.ToString(); // double power = 3.0 * vrefad/vinad; // listView1.Items[10].SubItems[1].Text = power.ToString("F4"); // t1v = (float)(power * t1ad / 4096); // listView1.Items[1].SubItems[1].Text = t1v.ToString("F4"); // // t2v = (float)(power * t2ad / 4096); // listView1.Items[5].SubItems[1].Text = t2v.ToString("F4"); float tin = BitConverter.ToSingle(ret.Data, 8); float tout = BitConverter.ToSingle(ret.Data, 12); listView1.Items[2].SubItems[1].Text = tin.ToString("F4"); listView1.Items[6].SubItems[1].Text = tout.ToString("F4"); progressBar1.PerformStep(); if (progressBar1.Value == progressBar1.Maximum) { progressBar1.Value = progressBar1.Minimum; } } })); timer1.Enabled = true; }
private void timer2_Tick(object sender, EventArgs e) { timer2.Enabled = false; CP68Packet ret = CP68Packet.CP68ComProc(ref serialPort1, CommandConst.CP68_UserCommand_ReadPress, null); this.Invoke((EventHandler)(delegate { if (ret != null) { press = BitConverter.ToSingle(ret.Data, 0); QFlow = BitConverter.ToSingle(ret.Data, 4); listView2.Items[0].SubItems[1].Text = press.ToString("F2"); listView2.Items[1].SubItems[1].Text = QFlow.ToString("F2"); progressBar1.PerformStep(); if (progressBar1.Value == progressBar1.Maximum) { progressBar1.Value = progressBar1.Minimum; } } })); timer2.Enabled = true; }