private void State() { try { for (int i = 0; i < btnArray.Length; i++) { if (Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM_B, btnArray[i].StateAddress) == 1) { btnArray[i].BackColor = Color.GreenYellow; } else { btnArray[i].BackColor = Color.FromArgb(212, 208, 200); } } for (int i = 0; i < lblArray.Length; i++) { lblArray[i].Text = DoubleConvert.Dint_to_Real((uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].StateAddress) , (uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].Address)).ToString("0.00"); Thread.Sleep(10); } } catch (Exception ex) { LogHelper.WriteLog(ex); //MessageBox.Show(ex.ToString()); } }
private void InfoDisplay() { for (int i = 0; i < lblArray.Length; i++) { lblArray[i].Text = DoubleConvert.Dint_to_Real((uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].StateAddress) , (uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].Address)).ToString("0.00"); Thread.Sleep(10); } }
/*** * * private void DrawGraph(IKsOpenGLContext ctx, GraphBase graph, Rectangle Bounds) * { * double x; * double y; * * Point PPaint; * Point PPaintLast = new Point(); ; * * bool PlotFlag = false; * * Pen pen = null; * * try * { * pen = new Pen(graph.GraphColor); * pen.Width = DefaultCurveWidth; * * switch (graph.GraphType) * { * case GraphTypes.gtIntegral: * * IntegralBase integral = (IntegralBase)graph; * * pen.Color = System.Drawing.Color.FromArgb(128, pen.Color); * * for (int i = 0; i < Bounds.Width; i++) * { * x = Client2PointX(i, Bounds); * * if (x >= integral.MinX.X && x <= integral.MaxX.X) * { * PPaintLast = Point2Client(x, (double)integral.FXYMin(x), Bounds); * PPaint = Point2Client(x, (double)integral.FXYMax(x), Bounds); * * try * { * g.DrawLine(pen, PPaintLast, PPaint); * } * catch { } * } * } * * break; * * case GraphTypes.gtSpecialPoints: * // wird separat gezeichnet, s.u. * break; * * case GraphTypes.gtStatsMean: * * pen.Color = System.Drawing.Color.FromArgb(172, pen.Color); * pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; * * switch (graph.GraphSubType) * { * case GraphSubTypes.gstMedian: * int iMedianX = Point2ClientX((double)graph.FX(0.0), Bounds); * * try * { * g.DrawLine(pen, iMedianX, 0, iMedianX, Bounds.Height); * } * catch { } * * break; * * case GraphSubTypes.gstMeanAverage: * * int iMeanAverageY = Point2ClientY((double)graph.FX(0.0), Bounds); * * try * { * g.DrawLine(pen, 0, iMeanAverageY, Bounds.Width, iMeanAverageY); * } * catch { } * * break; * } * * break; * * case GraphTypes.gtInterpolation: * * SplineBase spline = (SplineBase)graph; * * int iMin; * int iMax; * if (spline.DrawExtrapolate) * { * iMin = 0; * iMax = Bounds.Width; * } * else * { * iMin = Math.Max(0, Point2ClientX((double)spline.XMin, Bounds)); * iMax = Math.Min(Bounds.Width, Point2ClientX((double)spline.XMax, Bounds)); * } * * for (int i = iMin; i <= iMax; i++) * { * x = Client2PointX(i, Bounds); * y = (double)graph.FX(x); * * PPaint = Point2Client(x, y, Bounds); * * if (PlotFlag && (PPaint.Y >= 0 || PPaintLast.Y >= 0) && (PPaint.Y <= Bounds.Height || PPaintLast.Y <= Bounds.Height)) * { * try * { * g.DrawLine(pen, PPaintLast, PPaint); * } * catch { } * } * * PPaintLast = PPaint; * * PlotFlag = true; * } * * break; * * default: * * for (int i = 0; i < Bounds.Width; i++) * { * x = Client2PointX(i, Bounds); * y = (double)graph.FX(x); * * PPaint = Point2Client(x, y, Bounds); * * if (PlotFlag && (PPaint.Y >= 0 || PPaintLast.Y >= 0) && (PPaint.Y <= Bounds.Height || PPaintLast.Y <= Bounds.Height)) * { * try * { * g.DrawLine(pen, PPaintLast, PPaint); * } * catch { } * } * * PPaintLast = PPaint; * * PlotFlag = true; * } * * break; * } * * if (graph.Points != null) * { * int Diag = 5; * Point PC; * * pen.Color = System.Drawing.Color.FromArgb(200, pen.Color); * * foreach (GraphPoint p in graph.Points) * { * PC = Point2Client(p.X.DoubleValue, p.Y.DoubleValue, Bounds); * * try * { * g.DrawLine(pen, PC.X - Diag, PC.Y - Diag, PC.X + Diag, PC.Y + Diag); * g.DrawLine(pen, PC.X - Diag, PC.Y + Diag, PC.X + Diag, PC.Y - Diag); * } * catch { } * } * } * } * catch (Exception) * { * } * finally * { * if (pen != null) * { * pen.Dispose(); * pen = null; * } * } * * //if (ShowCross && bMouseHover) * //{ * // try * // { * // int yValue = Point2ClientY((double)graph.FX(Client2PointX(CurrentMousePosition.X, Bounds)), Bounds); * * // g.DrawLine(Pens.Cyan, CurrentMousePosition.X, 0, CurrentMousePosition.X, Bounds.Height); * * // if (yValue >= 0 && yValue <= Bounds.Height) * // g.DrawLine(Pens.Cyan, 0, yValue, Bounds.Width, yValue); * // } * // catch (Exception) * // { * // } * //} * } ***/ // 0 = X; 1 = Y private string FormatLabel(double value, int Axis) { // auf signifikante stellen runden if (Axis == 0 && StringFormatX.Length > 0) { try { if (XAxisDataType == AxisDataTypes.axDateTime) { return(DoubleConvert.Double2Date(value).ToString(StringFormatX)); } return(value.ToString(StringFormatX)); } catch (Exception) { return("format-error"); } } else if (Axis == 1 && StringFormatY.Length > 0) { try { return(value.ToString(StringFormatY)); } catch (Exception) { return("format-error"); } } else { string S = value.ToString(); if (value % 10 != 0) { while (S.Substring(S.Length - 1, 1) == "0") { S = S.Substring(0, S.Length - 1); } string c = S.Substring(S.Length - 1, 1); if (c == "." || c == ",") { S = S.Substring(0, S.Length - 1); } } return(S); } }
/// <summary> /// 将整型数据转换成浮点数写入plc中(两个寄存器) /// </summary> /// <param name="address"></param> /// <param name="data"></param> private void WriteMemory(MemoryAddress address, int data) { uint[] dataReturn = DoubleConvert.Real_to_2Int(data); try { Global.kv.WriteMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, ((int)address).ToString(), (int)dataReturn[1]); Global.kv.WriteMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, ((int)(address) + 1).ToString(), (int)dataReturn[0]); } catch (Exception ex) { LogHelper.WriteLog(ex); //MessageBox.Show(ex.ToString()); } }
/// <summary> /// 界面显示 /// </summary> private void Display() { try { for (int i = 0; i < lblArray.Length; i++) { lblArray[i].Text = DoubleConvert.Dint_to_Real((uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].StateAddress) , (uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].Address)).ToString("0.00"); Thread.Sleep(10); } for (int i = 0; i < btnArray.Length; i++) { if ((Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_RLY_B, btnArray[i].StateAddress) == 1)) { if (btnArray[i].StateAddress == "162112") { if (Global.workState) { btnArray[i].BackColor = Color.Green; } else { btnArray[i].BackColor = Color.Red; } } else { btnArray[i].BackColor = Color.Green; } } else { btnArray[i].BackColor = Color.Red; } } } catch (Exception ex) { LogHelper.WriteLog(ex); for (int i = 0; i < lblArray.Length; i++) { lblArray[i].Text = "erro"; } } }
private void State() { try { for (int i = 0; i < lblArray.Length; i++) { lblArray[i].Text = DoubleConvert.Dint_to_Real((uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].StateAddress) , (uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].Address)).ToString("0.00"); } for (int i = 0; i < btnArray.Length; i++) { if (Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM_B, btnArray[i].StateAddress) == 1) { btnArray[i].BackColor = Color.GreenYellow; } else { btnArray[i].BackColor = Color.FromArgb(212, 208, 200); } } switch (Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_DM, LblTestPhase.Address)) { case 1: LblTestPhase.Text = "A相"; break; case 2: LblTestPhase.Text = "B相"; break; case 3: LblTestPhase.Text = "C相"; break; default: break; } } catch (Exception ex) { LogHelper.WriteLog(ex); } }
/// <summary> /// 界面显示 /// </summary> private void Display() { try { for (int i = 0; i < lblArray.Length; i++) { lblArray[i].Text = DoubleConvert.Dint_to_Real((uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].StateAddress) , (uint)Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_EM, lblArray[i].Address)).ToString("0.00"); } for (int i = 0; i < btnArray.Length; i++) { if ((Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_RLY_B, btnArray[i].StateAddress) == 1)) { if (btnArray[i].StateAddress == "142112") { if (Global.workState) { btnArray[i].BackColor = Color.Green; } else { btnArray[i].BackColor = Color.Red; } } else { btnArray[i].BackColor = Color.Green; } } else { btnArray[i].BackColor = Color.Red; } } switch (Global.kv.ReadMemory(DATABUILDERAXLibLB.DBPlcDevice.DKV7K_DM, LblTestPhase.Address)) { case 1: LblTestPhase.Text = "A相"; break; case 2: LblTestPhase.Text = "B相"; break; case 3: LblTestPhase.Text = "C相"; break; default: break; } } catch (Exception ex) { LogHelper.WriteLog(ex); for (int i = 0; i < lblArray.Length; i++) { lblArray[i].Text = "erro"; } } }