Compare commits

...
6 Commits
Author SHA1 Message Date
gf zhou eb64a3fc2f 写入冷却加热时间
测试模式切换时对应的定时器也要开启关闭
读到3触发字,关闭扫码页面
2025-06-02 16:43:09 +08:00
gf zhou 817b66ad53 5.12 OEE相关日志放到右侧
螺丝添加NG的统计
2025-05-12 14:01:46 +08:00
zhougf e8001a81bb PLC时间对接
定时器测试
s7通讯加辅助方法
4.21 测试
2025-04-21 15:29:57 +08:00
gf zhou 76cd069435 4.18 checkin不管成功失败都写sn
加上needwork的判定
datacollection 判断dcinfo为空,不传mes,事件不显示在事件列表,只记录日志
状态上传定时器重新修改上传逻辑
文件上传定时器
2025-04-20 18:15:30 +08:00
gf zhou 4419a4de3c oee相关修改 2025-04-17 18:37:22 +08:00
gf zhou 9c5ef7bb31 416 添加OEE报警相关 2025-04-17 09:20:19 +08:00
18 changed files with 2190 additions and 505 deletions

No files matched your search

+18 -2
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="CsvHelper">
<HintPath>..\..\CsvHelper.dll</HintPath>
<HintPath>Z:\WHProjects\CsvHelper.dll</HintPath>
</Reference>
<Reference Include="HslCommunication, Version=7.0.1.0, Culture=neutral, PublicKeyToken=cdb2261fa039ed67, processorArchitecture=MSIL">
<HintPath>..\packages\HslCommunication.7.0.1\lib\net451\HslCommunication.dll</HintPath>
@@ -103,6 +103,10 @@
<Compile Include="form\editForm\Angleaddress_Insert.Designer.cs">
<DependentUpon>Angleaddress_Insert.cs</DependentUpon>
</Compile>
<Compile Include="form\editForm\OEEaddress_Insert.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="form\editForm\OEEaddress_Insert.Designer.cs" />
<Compile Include="form\editForm\Torqueaddress_Insert.cs">
<SubType>Form</SubType>
</Compile>
@@ -175,6 +179,12 @@
<Compile Include="form\LoadingForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="form\OEEaddress_Manage.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="form\OEEaddress_Manage.Designer.cs">
<DependentUpon>OEEaddress_Manage.cs</DependentUpon>
</Compile>
<Compile Include="form\ScanForm_DZ.cs">
<SubType>Form</SubType>
</Compile>
@@ -250,6 +260,7 @@
<Compile Include="form\MaterialScanForm.Designer.cs">
<DependentUpon>MaterialScanForm.cs</DependentUpon>
</Compile>
<Compile Include="mod\database\t_oeeaddress.cs" />
<Compile Include="mod\database\t_imageposition.cs" />
<Compile Include="mod\database\t_lineplc.cs" />
<Compile Include="mod\database\t_materialcall.cs" />
@@ -333,6 +344,11 @@
<EmbeddedResource Include="form\Angleaddress_Manage.resx">
<DependentUpon>Angleaddress_Manage.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="form\OEEaddress_Manage.resx">
<DependentUpon>OEEaddress_Manage.cs</DependentUpon>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>OEEaddress_Manage1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="form\ScanForm_DZ.resx">
<DependentUpon>ScanForm_DZ.cs</DependentUpon>
</EmbeddedResource>
+96 -86
View File
@@ -114,6 +114,7 @@ namespace WindowsFormsApp1
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.oEE地址管理ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.plcStatusGroupBox.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
@@ -135,9 +136,9 @@ namespace WindowsFormsApp1
this.plcStatusGroupBox.Controls.Add(this.plcStatusTableLayout);
this.plcStatusGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.plcStatusGroupBox.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
this.plcStatusGroupBox.Location = new System.Drawing.Point(3, 931);
this.plcStatusGroupBox.Location = new System.Drawing.Point(3, 969);
this.plcStatusGroupBox.Name = "plcStatusGroupBox";
this.plcStatusGroupBox.Size = new System.Drawing.Size(1754, 90);
this.plcStatusGroupBox.Size = new System.Drawing.Size(1754, 94);
this.plcStatusGroupBox.TabIndex = 9;
this.plcStatusGroupBox.TabStop = false;
this.plcStatusGroupBox.Text = "PLC连接状态";
@@ -151,7 +152,7 @@ namespace WindowsFormsApp1
this.plcStatusTableLayout.Dock = System.Windows.Forms.DockStyle.Fill;
this.plcStatusTableLayout.Location = new System.Drawing.Point(3, 40);
this.plcStatusTableLayout.Name = "plcStatusTableLayout";
this.plcStatusTableLayout.Size = new System.Drawing.Size(1748, 47);
this.plcStatusTableLayout.Size = new System.Drawing.Size(1748, 51);
this.plcStatusTableLayout.TabIndex = 0;
//
// menuStrip1
@@ -279,7 +280,8 @@ namespace WindowsFormsApp1
this.扭力角度扭矩设置ToolStripMenuItem,
this.螺丝枪扭力设置ToolStripMenuItem,
this.扭力曲线配置ToolStripMenuItem,
this.压力曲线设置ToolStripMenuItem});
this.压力曲线设置ToolStripMenuItem,
this.oEE地址管理ToolStripMenuItem});
this.扫码枪配置ToolStripMenuItem.Enabled = false;
this.扫码枪配置ToolStripMenuItem.Name = "扫码枪配置ToolStripMenuItem";
this.扫码枪配置ToolStripMenuItem.Size = new System.Drawing.Size(230, 45);
@@ -371,13 +373,13 @@ namespace WindowsFormsApp1
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 6;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 101F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 105F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 59.66998F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 35.03736F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 96F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 5.292663F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(1760, 1068);
this.tableLayoutPanel1.Size = new System.Drawing.Size(1760, 1112);
this.tableLayoutPanel1.TabIndex = 6;
//
// tableLayoutPanel3
@@ -390,12 +392,12 @@ namespace WindowsFormsApp1
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel3.Controls.Add(this.tableLayoutPanel2, 0, 0);
this.tableLayoutPanel3.Location = new System.Drawing.Point(5, 54);
this.tableLayoutPanel3.Location = new System.Drawing.Point(5, 56);
this.tableLayoutPanel3.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.tableLayoutPanel3.Name = "tableLayoutPanel3";
this.tableLayoutPanel3.RowCount = 1;
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel3.Size = new System.Drawing.Size(1750, 89);
this.tableLayoutPanel3.Size = new System.Drawing.Size(1750, 93);
this.tableLayoutPanel3.TabIndex = 4;
//
// tableLayoutPanel2
@@ -424,7 +426,7 @@ namespace WindowsFormsApp1
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 1;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(1740, 77);
this.tableLayoutPanel2.Size = new System.Drawing.Size(1740, 81);
this.tableLayoutPanel2.TabIndex = 3;
//
// linemode
@@ -436,7 +438,7 @@ namespace WindowsFormsApp1
this.linemode.Location = new System.Drawing.Point(975, 1);
this.linemode.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.linemode.Name = "linemode";
this.linemode.Size = new System.Drawing.Size(245, 75);
this.linemode.Size = new System.Drawing.Size(245, 79);
this.linemode.TabIndex = 16;
this.linemode.Text = "MachineID";
this.linemode.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -449,7 +451,7 @@ namespace WindowsFormsApp1
this.当前时间.Location = new System.Drawing.Point(1487, 1);
this.当前时间.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.当前时间.Name = "当前时间";
this.当前时间.Size = new System.Drawing.Size(247, 75);
this.当前时间.Size = new System.Drawing.Size(247, 79);
this.当前时间.TabIndex = 11;
this.当前时间.Text = "当前状态:";
this.当前时间.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -462,7 +464,7 @@ namespace WindowsFormsApp1
this.操作人员ID.Location = new System.Drawing.Point(1231, 1);
this.操作人员ID.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.操作人员ID.Name = "操作人员ID";
this.操作人员ID.Size = new System.Drawing.Size(245, 75);
this.操作人员ID.Size = new System.Drawing.Size(245, 79);
this.操作人员ID.TabIndex = 6;
this.操作人员ID.Text = "操作人员ID:";
this.操作人员ID.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -476,7 +478,7 @@ namespace WindowsFormsApp1
this.linetype.Location = new System.Drawing.Point(719, 1);
this.linetype.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.linetype.Name = "linetype";
this.linetype.Size = new System.Drawing.Size(245, 75);
this.linetype.Size = new System.Drawing.Size(245, 79);
this.linetype.TabIndex = 5;
this.linetype.Text = "StationID";
this.linetype.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -490,7 +492,7 @@ namespace WindowsFormsApp1
this.linecode.Location = new System.Drawing.Point(463, 1);
this.linecode.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.linecode.Name = "linecode";
this.linecode.Size = new System.Drawing.Size(245, 75);
this.linecode.Size = new System.Drawing.Size(245, 79);
this.linecode.TabIndex = 4;
this.linecode.Text = "Line";
this.linecode.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -503,7 +505,7 @@ namespace WindowsFormsApp1
this.linename.Location = new System.Drawing.Point(207, 1);
this.linename.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.linename.Name = "linename";
this.linename.Size = new System.Drawing.Size(245, 75);
this.linename.Size = new System.Drawing.Size(245, 79);
this.linename.TabIndex = 3;
this.linename.Text = "线别:";
this.linename.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -514,7 +516,7 @@ namespace WindowsFormsApp1
this.开始处理.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.开始处理.Location = new System.Drawing.Point(4, 4);
this.开始处理.Name = "开始处理";
this.开始处理.Size = new System.Drawing.Size(194, 69);
this.开始处理.Size = new System.Drawing.Size(194, 73);
this.开始处理.TabIndex = 17;
this.开始处理.Text = "开始处理";
this.开始处理.UseVisualStyleBackColor = true;
@@ -531,13 +533,13 @@ namespace WindowsFormsApp1
this.tableLayoutPanel4.Controls.Add(this.原料包装LOT号, 0, 0);
this.tableLayoutPanel4.Controls.Add(this.tableLayoutPanel6, 0, 1);
this.tableLayoutPanel4.Controls.Add(this.tableLayoutPanel9, 1, 0);
this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 153);
this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 159);
this.tableLayoutPanel4.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tableLayoutPanel4.Name = "tableLayoutPanel4";
this.tableLayoutPanel4.RowCount = 2;
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 40F));
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 60F));
this.tableLayoutPanel4.Size = new System.Drawing.Size(1754, 483);
this.tableLayoutPanel4.Size = new System.Drawing.Size(1754, 503);
this.tableLayoutPanel4.TabIndex = 8;
//
// 原料包装LOT号
@@ -549,7 +551,7 @@ namespace WindowsFormsApp1
this.原料包装LOT号.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.原料包装LOT号.Name = "原料包装LOT号";
this.原料包装LOT号.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.原料包装LOT号.Size = new System.Drawing.Size(1397, 185);
this.原料包装LOT号.Size = new System.Drawing.Size(1397, 193);
this.原料包装LOT号.TabIndex = 0;
this.原料包装LOT号.TabStop = false;
this.原料包装LOT号.Text = "产品信息:";
@@ -574,7 +576,7 @@ namespace WindowsFormsApp1
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33334F));
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33334F));
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33334F));
this.tableLayoutPanel5.Size = new System.Drawing.Size(1391, 140);
this.tableLayoutPanel5.Size = new System.Drawing.Size(1391, 148);
this.tableLayoutPanel5.TabIndex = 0;
//
// 材料值
@@ -582,9 +584,9 @@ namespace WindowsFormsApp1
this.材料值.AutoSize = true;
this.材料值.Dock = System.Windows.Forms.DockStyle.Fill;
this.材料值.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.材料值.Location = new System.Drawing.Point(350, 46);
this.材料值.Location = new System.Drawing.Point(350, 49);
this.材料值.Name = "材料值";
this.材料值.Size = new System.Drawing.Size(1038, 46);
this.材料值.Size = new System.Drawing.Size(1038, 49);
this.材料值.TabIndex = 7;
this.材料值.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@@ -593,9 +595,9 @@ namespace WindowsFormsApp1
this.材料.AutoSize = true;
this.材料.Dock = System.Windows.Forms.DockStyle.Fill;
this.材料.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.材料.Location = new System.Drawing.Point(3, 46);
this.材料.Location = new System.Drawing.Point(3, 49);
this.材料.Name = "材料";
this.材料.Size = new System.Drawing.Size(341, 46);
this.材料.Size = new System.Drawing.Size(341, 49);
this.材料.TabIndex = 6;
this.材料.Text = "材 料:";
this.材料.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -607,7 +609,7 @@ namespace WindowsFormsApp1
this.LOT号显示.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.LOT号显示.Location = new System.Drawing.Point(3, 0);
this.LOT号显示.Name = "LOT号显示";
this.LOT号显示.Size = new System.Drawing.Size(341, 46);
this.LOT号显示.Size = new System.Drawing.Size(341, 49);
this.LOT号显示.TabIndex = 2;
this.LOT号显示.Text = "产品 SN:";
this.LOT号显示.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -617,9 +619,9 @@ namespace WindowsFormsApp1
this.MES提示.AutoSize = true;
this.MES提示.Dock = System.Windows.Forms.DockStyle.Fill;
this.MES提示.Font = new System.Drawing.Font("宋体", 15F);
this.MES提示.Location = new System.Drawing.Point(3, 92);
this.MES提示.Location = new System.Drawing.Point(3, 98);
this.MES提示.Name = "MES提示";
this.MES提示.Size = new System.Drawing.Size(341, 48);
this.MES提示.Size = new System.Drawing.Size(341, 50);
this.MES提示.TabIndex = 4;
this.MES提示.Text = "托 盘 码:";
this.MES提示.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -629,9 +631,9 @@ namespace WindowsFormsApp1
this.Tray盘二维码.AutoSize = true;
this.Tray盘二维码.Dock = System.Windows.Forms.DockStyle.Fill;
this.Tray盘二维码.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.Tray盘二维码.Location = new System.Drawing.Point(350, 92);
this.Tray盘二维码.Location = new System.Drawing.Point(350, 98);
this.Tray盘二维码.Name = "Tray盘二维码";
this.Tray盘二维码.Size = new System.Drawing.Size(1038, 48);
this.Tray盘二维码.Size = new System.Drawing.Size(1038, 50);
this.Tray盘二维码.TabIndex = 2;
this.Tray盘二维码.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@@ -642,7 +644,7 @@ namespace WindowsFormsApp1
this.LOT号.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.LOT号.Location = new System.Drawing.Point(350, 0);
this.LOT号.Name = "LOT号";
this.LOT号.Size = new System.Drawing.Size(1038, 46);
this.LOT号.Size = new System.Drawing.Size(1038, 49);
this.LOT号.TabIndex = 0;
this.LOT号.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@@ -661,12 +663,12 @@ namespace WindowsFormsApp1
this.tableLayoutPanel6.Controls.Add(this.MES提示信息, 2, 1);
this.tableLayoutPanel6.Controls.Add(this.eventTableLayout, 0, 1);
this.tableLayoutPanel6.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel6.Location = new System.Drawing.Point(3, 196);
this.tableLayoutPanel6.Location = new System.Drawing.Point(3, 204);
this.tableLayoutPanel6.Name = "tableLayoutPanel6";
this.tableLayoutPanel6.RowCount = 2;
this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F));
this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 50F));
this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel6.Size = new System.Drawing.Size(1748, 284);
this.tableLayoutPanel6.Size = new System.Drawing.Size(1748, 296);
this.tableLayoutPanel6.TabIndex = 3;
//
// label1
@@ -676,7 +678,7 @@ namespace WindowsFormsApp1
this.label1.Font = new System.Drawing.Font("宋体", 10.125F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(4, 1);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(430, 48);
this.label1.Size = new System.Drawing.Size(430, 50);
this.label1.TabIndex = 0;
this.label1.Text = "MES事件";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -688,7 +690,7 @@ namespace WindowsFormsApp1
this.label2.Font = new System.Drawing.Font("宋体", 10.125F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.Location = new System.Drawing.Point(441, 1);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(430, 48);
this.label2.Size = new System.Drawing.Size(430, 50);
this.label2.TabIndex = 1;
this.label2.Text = "MES事件结果";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -700,7 +702,7 @@ namespace WindowsFormsApp1
this.label3.Font = new System.Drawing.Font("宋体", 10.125F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(878, 1);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(866, 48);
this.label3.Size = new System.Drawing.Size(866, 50);
this.label3.TabIndex = 2;
this.label3.Text = "MES信息提示";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -710,9 +712,9 @@ namespace WindowsFormsApp1
this.事件结果.AutoSize = true;
this.事件结果.Dock = System.Windows.Forms.DockStyle.Fill;
this.事件结果.Font = new System.Drawing.Font("宋体", 25.875F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.事件结果.Location = new System.Drawing.Point(441, 50);
this.事件结果.Location = new System.Drawing.Point(441, 52);
this.事件结果.Name = "事件结果";
this.事件结果.Size = new System.Drawing.Size(430, 233);
this.事件结果.Size = new System.Drawing.Size(430, 243);
this.事件结果.TabIndex = 3;
this.事件结果.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
@@ -721,9 +723,9 @@ namespace WindowsFormsApp1
this.MES提示信息.AutoSize = true;
this.MES提示信息.Dock = System.Windows.Forms.DockStyle.Fill;
this.MES提示信息.Font = new System.Drawing.Font("宋体", 22.125F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.MES提示信息.Location = new System.Drawing.Point(878, 50);
this.MES提示信息.Location = new System.Drawing.Point(878, 52);
this.MES提示信息.Name = "MES提示信息";
this.MES提示信息.Size = new System.Drawing.Size(866, 233);
this.MES提示信息.Size = new System.Drawing.Size(866, 243);
this.MES提示信息.TabIndex = 4;
this.MES提示信息.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
@@ -743,7 +745,7 @@ namespace WindowsFormsApp1
this.eventTableLayout.Controls.Add(this.label8, 0, 3);
this.eventTableLayout.Controls.Add(this.label9, 0, 4);
this.eventTableLayout.Dock = System.Windows.Forms.DockStyle.Fill;
this.eventTableLayout.Location = new System.Drawing.Point(4, 53);
this.eventTableLayout.Location = new System.Drawing.Point(4, 55);
this.eventTableLayout.Name = "eventTableLayout";
this.eventTableLayout.RowCount = 5;
this.eventTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
@@ -751,7 +753,7 @@ namespace WindowsFormsApp1
this.eventTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.eventTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.eventTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.eventTableLayout.Size = new System.Drawing.Size(430, 227);
this.eventTableLayout.Size = new System.Drawing.Size(430, 237);
this.eventTableLayout.TabIndex = 5;
//
// panel1
@@ -760,46 +762,46 @@ namespace WindowsFormsApp1
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(333, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(94, 39);
this.panel1.Size = new System.Drawing.Size(94, 41);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.Location = new System.Drawing.Point(38, 45);
this.panel2.Location = new System.Drawing.Point(38, 47);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(200, 39);
this.panel2.Size = new System.Drawing.Size(200, 41);
this.panel2.TabIndex = 1;
//
// panel4
//
this.panel4.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel4.Location = new System.Drawing.Point(333, 48);
this.panel4.Location = new System.Drawing.Point(333, 50);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(94, 39);
this.panel4.Size = new System.Drawing.Size(94, 41);
this.panel4.TabIndex = 2;
//
// panel3
//
this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel3.Location = new System.Drawing.Point(333, 93);
this.panel3.Location = new System.Drawing.Point(333, 97);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(94, 39);
this.panel3.Size = new System.Drawing.Size(94, 41);
this.panel3.TabIndex = 1;
//
// panel5
//
this.panel5.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel5.Location = new System.Drawing.Point(333, 138);
this.panel5.Location = new System.Drawing.Point(333, 144);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(94, 39);
this.panel5.Size = new System.Drawing.Size(94, 41);
this.panel5.TabIndex = 3;
//
// panel6
//
this.panel6.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel6.Location = new System.Drawing.Point(333, 183);
this.panel6.Location = new System.Drawing.Point(333, 191);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(94, 41);
this.panel6.Size = new System.Drawing.Size(94, 43);
this.panel6.TabIndex = 4;
//
// label5
@@ -809,7 +811,7 @@ namespace WindowsFormsApp1
this.label5.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
this.label5.Location = new System.Drawing.Point(3, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(324, 45);
this.label5.Size = new System.Drawing.Size(324, 47);
this.label5.TabIndex = 5;
this.label5.Text = "label5";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -819,9 +821,9 @@ namespace WindowsFormsApp1
this.label6.AutoSize = true;
this.label6.Dock = System.Windows.Forms.DockStyle.Fill;
this.label6.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label6.Location = new System.Drawing.Point(3, 45);
this.label6.Location = new System.Drawing.Point(3, 47);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(324, 45);
this.label6.Size = new System.Drawing.Size(324, 47);
this.label6.TabIndex = 6;
this.label6.Text = "label6";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -831,9 +833,9 @@ namespace WindowsFormsApp1
this.label7.AutoSize = true;
this.label7.Dock = System.Windows.Forms.DockStyle.Fill;
this.label7.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label7.Location = new System.Drawing.Point(3, 90);
this.label7.Location = new System.Drawing.Point(3, 94);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(324, 45);
this.label7.Size = new System.Drawing.Size(324, 47);
this.label7.TabIndex = 7;
this.label7.Text = "label7";
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -843,9 +845,9 @@ namespace WindowsFormsApp1
this.label8.AutoSize = true;
this.label8.Dock = System.Windows.Forms.DockStyle.Fill;
this.label8.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label8.Location = new System.Drawing.Point(3, 135);
this.label8.Location = new System.Drawing.Point(3, 141);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(324, 45);
this.label8.Size = new System.Drawing.Size(324, 47);
this.label8.TabIndex = 8;
this.label8.Text = "label8";
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -855,9 +857,9 @@ namespace WindowsFormsApp1
this.label9.AutoSize = true;
this.label9.Dock = System.Windows.Forms.DockStyle.Fill;
this.label9.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label9.Location = new System.Drawing.Point(3, 180);
this.label9.Location = new System.Drawing.Point(3, 188);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(324, 47);
this.label9.Size = new System.Drawing.Size(324, 49);
this.label9.TabIndex = 9;
this.label9.Text = "label9";
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -873,9 +875,9 @@ namespace WindowsFormsApp1
this.tableLayoutPanel9.Location = new System.Drawing.Point(1406, 3);
this.tableLayoutPanel9.Name = "tableLayoutPanel9";
this.tableLayoutPanel9.RowCount = 2;
this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F));
this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 50F));
this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel9.Size = new System.Drawing.Size(345, 187);
this.tableLayoutPanel9.Size = new System.Drawing.Size(345, 195);
this.tableLayoutPanel9.TabIndex = 4;
//
// label4
@@ -885,7 +887,7 @@ namespace WindowsFormsApp1
this.label4.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.Location = new System.Drawing.Point(3, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(339, 48);
this.label4.Size = new System.Drawing.Size(339, 50);
this.label4.TabIndex = 0;
this.label4.Text = "胶水寿命";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -895,9 +897,9 @@ namespace WindowsFormsApp1
this.剩余寿命.AutoSize = true;
this.剩余寿命.Dock = System.Windows.Forms.DockStyle.Fill;
this.剩余寿命.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.剩余寿命.Location = new System.Drawing.Point(3, 48);
this.剩余寿命.Location = new System.Drawing.Point(3, 50);
this.剩余寿命.Name = "剩余寿命";
this.剩余寿命.Size = new System.Drawing.Size(339, 139);
this.剩余寿命.Size = new System.Drawing.Size(339, 145);
this.剩余寿命.TabIndex = 1;
this.剩余寿命.Text = "label5";
this.剩余寿命.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -910,7 +912,7 @@ namespace WindowsFormsApp1
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox1.Size = new System.Drawing.Size(1752, 38);
this.groupBox1.Size = new System.Drawing.Size(1752, 40);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "处理界面";
@@ -936,12 +938,12 @@ namespace WindowsFormsApp1
this.tableLayoutPanel8.Controls.Add(this.btnToggleTestMode, 9, 0);
this.tableLayoutPanel8.Controls.Add(this.button1, 8, 0);
this.tableLayoutPanel8.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel8.Location = new System.Drawing.Point(3, 1028);
this.tableLayoutPanel8.Location = new System.Drawing.Point(3, 1070);
this.tableLayoutPanel8.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tableLayoutPanel8.Name = "tableLayoutPanel8";
this.tableLayoutPanel8.RowCount = 1;
this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel8.Size = new System.Drawing.Size(1754, 36);
this.tableLayoutPanel8.Size = new System.Drawing.Size(1754, 38);
this.tableLayoutPanel8.TabIndex = 7;
//
// 底部注释1
@@ -950,7 +952,7 @@ namespace WindowsFormsApp1
this.底部注释1.AutoSize = true;
this.底部注释1.Location = new System.Drawing.Point(3, 6);
this.底部注释1.Name = "底部注释1";
this.底部注释1.Size = new System.Drawing.Size(118, 24);
this.底部注释1.Size = new System.Drawing.Size(108, 25);
this.底部注释1.TabIndex = 0;
this.底部注释1.Text = "底部注释1";
//
@@ -960,7 +962,7 @@ namespace WindowsFormsApp1
this.底部注释2.AutoSize = true;
this.底部注释2.Location = new System.Drawing.Point(178, 6);
this.底部注释2.Name = "底部注释2";
this.底部注释2.Size = new System.Drawing.Size(118, 24);
this.底部注释2.Size = new System.Drawing.Size(108, 25);
this.底部注释2.TabIndex = 1;
this.底部注释2.Text = "底部注释2";
//
@@ -970,7 +972,7 @@ namespace WindowsFormsApp1
this.底部注释3.AutoSize = true;
this.底部注释3.Location = new System.Drawing.Point(353, 6);
this.底部注释3.Name = "底部注释3";
this.底部注释3.Size = new System.Drawing.Size(118, 24);
this.底部注释3.Size = new System.Drawing.Size(108, 25);
this.底部注释3.TabIndex = 2;
this.底部注释3.Text = "底部注释3";
//
@@ -980,7 +982,7 @@ namespace WindowsFormsApp1
this.底部注释4.AutoSize = true;
this.底部注释4.Location = new System.Drawing.Point(528, 6);
this.底部注释4.Name = "底部注释4";
this.底部注释4.Size = new System.Drawing.Size(118, 24);
this.底部注释4.Size = new System.Drawing.Size(108, 25);
this.底部注释4.TabIndex = 3;
this.底部注释4.Text = "底部注释4";
//
@@ -990,7 +992,7 @@ namespace WindowsFormsApp1
this.底部注释5.AutoSize = true;
this.底部注释5.Location = new System.Drawing.Point(703, 6);
this.底部注释5.Name = "底部注释5";
this.底部注释5.Size = new System.Drawing.Size(118, 24);
this.底部注释5.Size = new System.Drawing.Size(108, 25);
this.底部注释5.TabIndex = 4;
this.底部注释5.Text = "底部注释5";
//
@@ -1000,7 +1002,7 @@ namespace WindowsFormsApp1
this.btnToggleTestMode.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnToggleTestMode.Location = new System.Drawing.Point(1578, 3);
this.btnToggleTestMode.Name = "btnToggleTestMode";
this.btnToggleTestMode.Size = new System.Drawing.Size(173, 30);
this.btnToggleTestMode.Size = new System.Drawing.Size(173, 32);
this.btnToggleTestMode.TabIndex = 5;
this.btnToggleTestMode.Text = "调试模式";
this.btnToggleTestMode.UseVisualStyleBackColor = false;
@@ -1011,7 +1013,7 @@ namespace WindowsFormsApp1
this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
this.button1.Location = new System.Drawing.Point(1403, 3);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(169, 30);
this.button1.Size = new System.Drawing.Size(169, 32);
this.button1.TabIndex = 6;
this.button1.Text = "螺丝开盖";
this.button1.UseVisualStyleBackColor = true;
@@ -1025,12 +1027,12 @@ namespace WindowsFormsApp1
this.tableLayoutPanel7.Controls.Add(this.richTextBox1, 0, 0);
this.tableLayoutPanel7.Controls.Add(this.richTextBox2, 1, 0);
this.tableLayoutPanel7.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel7.Location = new System.Drawing.Point(3, 643);
this.tableLayoutPanel7.Location = new System.Drawing.Point(3, 669);
this.tableLayoutPanel7.Name = "tableLayoutPanel7";
this.tableLayoutPanel7.RowCount = 1;
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 19F));
this.tableLayoutPanel7.Size = new System.Drawing.Size(1754, 282);
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel7.Size = new System.Drawing.Size(1754, 294);
this.tableLayoutPanel7.TabIndex = 10;
//
// richTextBox1
@@ -1038,7 +1040,7 @@ namespace WindowsFormsApp1
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Location = new System.Drawing.Point(3, 3);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(871, 276);
this.richTextBox1.Size = new System.Drawing.Size(871, 288);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
@@ -1047,15 +1049,22 @@ namespace WindowsFormsApp1
this.richTextBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox2.Location = new System.Drawing.Point(880, 3);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.Size = new System.Drawing.Size(871, 276);
this.richTextBox2.Size = new System.Drawing.Size(871, 288);
this.richTextBox2.TabIndex = 1;
this.richTextBox2.Text = "";
//
// oEE地址管理ToolStripMenuItem
//
this.oEE地址管理ToolStripMenuItem.Name = "oEE地址管理ToolStripMenuItem";
this.oEE地址管理ToolStripMenuItem.Size = new System.Drawing.Size(379, 50);
this.oEE地址管理ToolStripMenuItem.Text = "OEE地址管理";
this.oEE地址管理ToolStripMenuItem.Click += new System.EventHandler(this.oEE地址管理ToolStripMenuItem_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1760, 1068);
this.ClientSize = new System.Drawing.Size(1760, 1112);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.tableLayoutPanel1);
this.MainMenuStrip = this.menuStrip1;
@@ -1173,6 +1182,7 @@ namespace WindowsFormsApp1
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Button btnToggleTestMode;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ToolStripMenuItem oEE地址管理ToolStripMenuItem;
}
}
+436 -208
View File
@@ -17,12 +17,14 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using HslCommunication.LogNet;
using Newtonsoft.Json.Linq;
using WindowsFormsApp1.db;
using WindowsFormsApp1.form;
using WindowsFormsApp1.mod;
using WindowsFormsApp1.mod.database;
using WindowsFormsApp1.mod.server;
using WindowsFormsApp1.server;
using static System.Collections.Specialized.BitVector32;
using static SQLite.SQLite3;
using static WindowsFormsApp1.server.ApiClient;
using Label = System.Windows.Forms.Label;
@@ -48,6 +50,11 @@ namespace WindowsFormsApp1
// 在MainForm类的成员变量部分添加一个定时器
private System.Windows.Forms.Timer statusReportTimer = new System.Windows.Forms.Timer();
private System.Windows.Forms.Timer screwReportTimer = new System.Windows.Forms.Timer();
private System.Windows.Forms.Timer fileUploadTimer = new System.Windows.Forms.Timer();
private ApiClient statusApiClient = new ApiClient(); // 专用于状态上报的API客户端
private object curingLock = new object();
private Dictionary<int, int> OldPlcTrigger = new Dictionary<int, int>();
@@ -57,6 +64,8 @@ namespace WindowsFormsApp1
private List<Panel> eventPanels = new List<Panel>();
private Queue<EventInfo> eventHistory = new Queue<EventInfo>();
private const int MAX_EVENT_DISPLAY = 5;
private int beginScrewReportTimer = -100;
#endregion 内部变量
public MainForm()
@@ -119,8 +128,15 @@ namespace WindowsFormsApp1
开始处理_Click(this, EventArgs.Empty);
// 初始化状态上报定时器
statusReportTimer.Interval = int.Parse(Init.t_Keyvalues.First(x => x.key == "StatusTime").value) * 1000; // 15秒
//statusReportTimer.Interval = int.Parse(Init.t_Keyvalues.First(x => x.key == "StatusTime").value) * 1000; // 15秒
statusReportTimer.Interval = 1000 * 15;
statusReportTimer.Tick += StatusReportTimer_Tick;
screwReportTimer.Interval = 1000 * 60 * 5;
screwReportTimer.Tick += ScrewReportTimer_Tick;
fileUploadTimer.Interval = 1000 * 60 * 2;
fileUploadTimer.Tick += FileUploadTimer_Tick;
}
public void build(t_plc Plc, CancellationToken token)
@@ -162,7 +178,7 @@ namespace WindowsFormsApp1
// 更新对应PLC的状态指示器为红色
UpdatePlcStatus(Plc.id, false);
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}建立S7连接失败");
//LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}建立S7连接失败");
continue;
}
@@ -170,6 +186,7 @@ namespace WindowsFormsApp1
List<t_angleaddress> angleaddress = Init.t_Angleaddresses.FindAll(a => a.plcid == Plc.id);
List<t_torqueaddress> torqueaddress = Init.t_Torqueaddresses.FindAll(a => a.plcid == Plc.id);
List<t_pressurecurve> pressurecurveaddress = Init.t_Pressurecurves.FindAll(a => a.plcid == Plc.id);
List<t_oeeaddress> oeeaddresses = Init.t_Oeeaddresses.ToList();
plcdata PlcData = new plcdata();
@@ -182,18 +199,17 @@ namespace WindowsFormsApp1
continue;
}
/*
* //写入心跳 在主线程取消,单独开线程 写plc心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳错误:处理停止");
continue;
}*/
/*
* //写入心跳 在主线程取消,单独开线程 写plc心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳错误:处理停止");
continue;
}*/
if (Init.t_Lineplcs.Count >= 2 && Plc.id == Init.t_Lineplcs.First().plcid)
{
@@ -222,9 +238,9 @@ namespace WindowsFormsApp1
snHelper.Insert(t_sn);
}
*/
}
if(Init.t_Lineplcs.Count == 1)
if (Init.t_Lineplcs.Count == 1)
{
LOT号.Text = PlcData.Write_stSN;
Tray盘二维码.Text = PlcData.Read_MaterialCode1;
@@ -250,13 +266,15 @@ namespace WindowsFormsApp1
PlcData.Write_Other0 = 1;
}
var okNgresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!okNgresult.Success)
if (PlcData.Write_Other0 == 1)
{
LogExecute.logNet.WriteError($"{Plc.plcip}写入OK/NG:处理停止");
continue;
var okNgresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!okNgresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcip}写入OK/NG:处理停止");
continue;
}
}
var imageFormIsOpened = false;
foreach (Form form in Application.OpenForms)
{
@@ -270,7 +288,8 @@ namespace WindowsFormsApp1
{
if (!imageFormIsOpened)
{
this.Invoke(new Action(() => {
this.Invoke(new Action(() =>
{
ImageDisplayForm imageDisplayForm = new ImageDisplayForm();
imageDisplayForm.Show();
}));
@@ -289,91 +308,110 @@ namespace WindowsFormsApp1
ApiClient apiClient = new ApiClient();
otherdata otherdata = new otherdata();
//Init.SN = PlcData.Read_MaterialCode0;
#region 机台状态及报警
//机台状态
//机台状态.Text = "机台状态:" + Enum.GetName(typeof(plcstatus), Init.Plcstatus);
Init.Plcstatus = PlcData.Read_Status;
int oldstatus = Init.Plcstatus;
//if (PlcData.Read_Status != 0)
if (false)
//Init.Plcstatus = PlcData.Read_Status;
// 多个plc 只有一个报警
if (Plc.id == Init.t_Lineplcs.First().plcid)
{
//状态+报警
if (oldstatus != PlcData.Read_Status)
int oldstatus = Init.Plcstatus;
if (PlcData.Read_Status != 0)
{
//反馈状态
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
otherdata.Plc_Status = PlcData.Read_Status;
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
if (statusresult.Success)
//状态+报警
if (oldstatus != PlcData.Read_Status)
{
//MES链接状态.Text = "MES链接状态:OK";
//MES链接状态.BackColor = SystemColors.Control;
//MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
MES_MsgfORM("Status", statusresult, statusresult.Requesttime);
if (statusresult.Mesresult != mesresult.PASS)
{
PlcData.Write_Status = 1001;
siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
else
{
//MES链接状态.Text = "MES链接状态:NG";
//MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
PlcData.Write_Status = 1002;
var errresult = siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
}
//机台报警
if (PlcData.Read_Status == (short)plcstatus.停机)
{
//机台状态.BackColor = Color.Red;
if (oldstatus != (short)plcstatus.停机)
{
//反馈报警
List<string> list = new List<string>();
///////////////////////////////测试用
list.Add("M03CVSO-01");
otherdata.Plc_ErrorMsgs = list;
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
var statusresult = apiClient.CallFunctionByName("Alarm", PlcData, otherdata);
if (statusresult.Success)
{
//MES链接状态.Text = "MES链接状态:OK";
//MES链接状态.BackColor = SystemColors.Control;
//MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
MES_MsgfORM("Alarm", statusresult, statusresult.Requesttime);
if (statusresult.Mesresult != mesresult.PASS)
{
PlcData.Write_Status = 1001;
siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
else
{
//MES链接状态.Text = "MES链接状态:NG";
//MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
PlcData.Write_Status = 1002;
siemensHelp.WriteAddress(plcaddress, PlcData);
}
}
continue;
}
else
{
//机台状态.BackColor = SystemColors.Control;
}
//反馈状态
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
otherdata.Plc_Status = PlcData.Read_Status.ToString();
if (PlcData.Read_Status == 2)
{
// 报警的时候 赋值报警代码
var oeeresult1 = siemensHelp.ReadAddress(oeeaddresses);
Init.ErrorCode = oeeresult1.Data.FirstOrDefault(x => x.value.ToLower() == "true")?.code;
otherdata.Plc_Status = $"{PlcData.Read_Status}_{Init.ErrorCode}";
}
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
if (statusresult.Success)
{
LogExecute.OEElogNet.WriteDebug($"上报机台状态成功: {plcstatus.GetName(typeof(plcstatus), Init.Plcstatus)} {otherdata.Plc_Status}");
//beginScrewReportTimer = 0;
if (!statusReportTimer.Enabled)
{
this.Invoke(new Action(() =>
{
statusReportTimer.Start();
}));
}
else
{
this.Invoke(new Action(() =>
{
statusReportTimer.Stop();
statusReportTimer.Start();
}));
}
//MES_MsgfORM("Status", statusresult, statusresult.Requesttime);
if (statusresult.Mesresult != mesresult.PASS)
{
PlcData.Write_Status = 1001;
siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
else
{
LogExecute.logNet.WriteError($"MES通讯异常!");
PlcData.Write_Status = 1002;
var errresult = siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
}
//机台报警
if (PlcData.Read_Status == (short)plcstatus.停机)
{
//机台状态.BackColor = Color.Red;
if (oldstatus != (short)plcstatus.停机)
{
//反馈报警
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
var statusresult = apiClient.CallFunctionByName("Alarm", PlcData, otherdata);
if (statusresult.Success)
{
LogExecute.OEElogNet.WriteDebug($"上报机台报警成功: {Init.ErrorCode}");
MES_MsgfORM("Alarm", statusresult, statusresult.Requesttime);
if (statusresult.Mesresult != mesresult.PASS)
{
PlcData.Write_Status = 1001;
siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
else
{
//MES链接状态.Text = "MES链接状态:NG";
//MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
PlcData.Write_Status = 1002;
siemensHelp.WriteAddress(plcaddress, PlcData);
}
}
//continue;
}
else
{
//机台状态.BackColor = SystemColors.Control;
}
}
#endregion
#region 判断及查找流程
@@ -388,6 +426,8 @@ namespace WindowsFormsApp1
OldPlcTrigger[Plc.id] = PlcData.Read_Trigger;
}
LogExecute.logNet.WriteDebug($"读取状态字{Plc.plcname}:{Plc.id}-{PlcData.Read_Trigger}");
if (PlcData.Read_Trigger == 0 && PlcData.Write_Status == 0)
{
continue;
@@ -406,9 +446,10 @@ namespace WindowsFormsApp1
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
}
LogExecute.logNet.WriteDebug($"写入状态字0");
continue;
}
LogExecute.logNet.WriteDebug($"读取状态字{Plc.id}-{PlcData.Read_Trigger}");
var nowflow = Init.t_Flows.FirstOrDefault(a => a.hopestatus == PlcData.Read_Trigger);
if (nowflow == null)
@@ -462,62 +503,62 @@ namespace WindowsFormsApp1
{
continue;
}
/*
//扫码
var stationid = Init.t_Line.lineremark2;
// ccd扫码
if ("Assy1,".Contains(stationid))
{
SQLiteHelper<t_keyvalue> sQLiteHelper_key = new db.SQLiteHelper<t_keyvalue>();
var key_sqlresult = sQLiteHelper_key.QueryAll();
/*
//扫码
var stationid = Init.t_Line.lineremark2;
// ccd扫码
if ("Assy1,".Contains(stationid))
{
SQLiteHelper<t_keyvalue> sQLiteHelper_key = new db.SQLiteHelper<t_keyvalue>();
var key_sqlresult = sQLiteHelper_key.QueryAll();
var result1 = apiClient.CallFunctionByName("SN_FeedingCheck", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result1.Success && result1.Mesresult == mesresult.PASS)
{
//继续调用接口
var result2 = apiClient.CallFunctionByName("Link_Comp", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result2.Success && result2.Mesresult == mesresult.PASS)
{
// 写数据到 主页的barcode 数据库改,缓存改
var txt = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode1");
txt.value = PlcData.Read_MaterialCode2;
var result1 = apiClient.CallFunctionByName("SN_FeedingCheck", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result1.Success && result1.Mesresult == mesresult.PASS)
{
//继续调用接口
var result2 = apiClient.CallFunctionByName("Link_Comp", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result2.Success && result2.Mesresult == mesresult.PASS)
{
// 写数据到 主页的barcode 数据库改,缓存改
var txt = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode1");
txt.value = PlcData.Read_MaterialCode2;
var code = key_sqlresult.Data.First(x => x.key == txt.key);
code.value = PlcData.Read_MaterialCode2;
sQLiteHelper_key.Update(code);
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}绑定NG");
}
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}核对NG");
}
}
else
{
ScanForm_DZ scanForm = new ScanForm_DZ();
DialogResult scan_result = scanForm.ShowDialog();
}
ChangeBarcode();
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
continue;
}
else
{
//MES链接状态.Text = "MES链接状态:OK";
//MES链接状态.BackColor = SystemColors.Control;
//MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
}
continue;
*/
var code = key_sqlresult.Data.First(x => x.key == txt.key);
code.value = PlcData.Read_MaterialCode2;
sQLiteHelper_key.Update(code);
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}绑定NG");
}
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}核对NG");
}
}
else
{
ScanForm_DZ scanForm = new ScanForm_DZ();
DialogResult scan_result = scanForm.ShowDialog();
}
ChangeBarcode();
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
continue;
}
else
{
//MES链接状态.Text = "MES链接状态:OK";
//MES链接状态.BackColor = SystemColors.Control;
//MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
}
continue;
*/
//if (scan_result == DialogResult.OK)
//{
// string returnValue = scanForm.ReturnValue;
@@ -544,23 +585,21 @@ namespace WindowsFormsApp1
}
otherdata.FinalPressureCurve = pressurecurveaddress_result.Data;
}
//if (nowflow.finaltorquecurve)
//{
// //扭力曲线(这里不处理,后端API获取)
//}
//螺丝扭力
if (nowflow.finaltorquevalue)
{
//螺丝枪扭力数据
var finaltorquevalue_result = siemensHelp.ReadAddress(torqueaddress);
if (!finaltorquevalue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪扭力数据地址处理错误:处理停止");
continue;
}
otherdata.FinalTorqueValue = finaltorquevalue_result.Data;
/* var finaltorquevalue_result = siemensHelp.ReadAddress(torqueaddress);
if (!finaltorquevalue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪扭力数据地址处理错误:处理停止");
continue;
}
otherdata.FinalTorqueValue = finaltorquevalue_result.Data;
*/
}
//气密
if (nowflow.airtight)
@@ -575,17 +614,29 @@ namespace WindowsFormsApp1
var finalanglevaluue_result = siemensHelp.ReadAddress(angleaddress);
if (!finalanglevaluue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪角度数据地址处理错误:处理停止");
continue;
}
otherdata.FinalAngleValue = finalanglevaluue_result.Data;
otherdata.FinalAngleValue = Enumerable
.Range(0, (finalanglevaluue_result.Data.Count + 3) / 4) // 计算组数
.Select(i => finalanglevaluue_result.Data.Skip(i * 4).Take(4).ToList())
.ToList();
}
if (nowflow.fileupload)
{
//文件上传
}
// oeedatacollection
try
{
var oeeresult = siemensHelp.ReadAddress(oeeaddresses);
otherdata.Oeeaddresses = oeeaddresses;
}
catch
{
LogExecute.logNet.WriteError("读取PLC OEE失败!");
}
#endregion
#region 判断物料调用次数 固化站,抽真空
@@ -722,7 +773,7 @@ namespace WindowsFormsApp1
{
ChangeBarcode();
MES_MsgfORM(nowinterface.code, result, result.Requesttime);
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
@@ -733,7 +784,8 @@ namespace WindowsFormsApp1
{
if (result.Mesresult != mesresult.PASS)
{
if (result.Msg.Contains("机台上料数量不够扣料"))
if (result.Msg.Contains("机台上料数量不够扣料")
|| result.Msg.Contains("没有上料"))
{
PlcData.Write_Status = 1003;
}
@@ -746,7 +798,7 @@ namespace WindowsFormsApp1
PlcData.Write_Status = 1001;
}
siemensHelp.WriteAddress(plcaddress, PlcData);
LogExecute.logNet.WriteDebug($"上位机写入触发字:{PlcData.Write_Status}");
LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}上位机写入触发字:{PlcData.Write_Status}");
continue;
}
else
@@ -757,7 +809,8 @@ namespace WindowsFormsApp1
PlcData.Write_stSN = "";
}
}
LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}上位机写入触发字:{PlcData.Write_Status}");
}
}
else
@@ -844,6 +897,14 @@ namespace WindowsFormsApp1
return;
}
SQLiteHelper<t_oeeaddress> sQLiteHelper_oee = new db.SQLiteHelper<t_oeeaddress>();
var oee_result = sQLiteHelper_oee.QueryAll();
if (!oee_result.Success)
{
MessageBox.Show("无法初始化报警信息,无法开始处理!");
return;
}
SQLiteHelper<t_interface> sQLiteHelper_interface = new db.SQLiteHelper<t_interface>();
var interface_result = sQLiteHelper_interface.QueryAll();
if (!interface_result.Success)
@@ -862,7 +923,7 @@ namespace WindowsFormsApp1
foreach (var item in Init.t_Lineplcs)
{
if(!OldPlcTrigger.ContainsKey(item.plcid))
if (!OldPlcTrigger.ContainsKey(item.plcid))
OldPlcTrigger.Add(item.plcid, 0);
}
@@ -873,6 +934,7 @@ namespace WindowsFormsApp1
Init.t_Angleaddresses = angleaddress_result.Data;
Init.t_Torqueaddresses = torqueaddress_result.Data;
Init.t_Pressurecurves = pressurecurve_result.Data;
Init.t_Oeeaddresses = oee_result.Data;
Init.t_Interfaces = interface_result.Data;
Init.t_Keyvalues = key_sqlresult.Data;
Init.t_plcs = plc_result;
@@ -883,6 +945,15 @@ namespace WindowsFormsApp1
// 启动状态上报定时器
statusReportTimer.Start();
//测试环境不上传数据
if (Init.t_Keyvalues.FirstOrDefault(x => x.key == "TestMode").value == "0")
{
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
screwReportTimer.Start();
}
fileUploadTimer.Start();
}
#endregion
#region 初始化COM口服务
@@ -965,7 +1036,7 @@ namespace WindowsFormsApp1
Init.threadHelps.Add(threadHelp1);
}
if(Init.t_User.username.ToLower() != "admin")
if (Init.t_User.username.ToLower() != "admin")
{
this.btnToggleTestMode.Enabled = false;
}
@@ -1048,6 +1119,8 @@ namespace WindowsFormsApp1
{
// 停止状态上报定时器
statusReportTimer.Stop();
screwReportTimer.Stop();
fileUploadTimer.Stop();
// 停止所有线程
if (Init.threadHelps != null)
@@ -1066,9 +1139,11 @@ namespace WindowsFormsApp1
}
}
thread.isrunning1 = false;
thread.Dispose();
}
catch { /* 忽略异常 */ }
}
Init.threadHelps.Clear();
}
// 安全关闭串口
@@ -1115,6 +1190,12 @@ namespace WindowsFormsApp1
torqueaddress_Manage.ShowDialog();
}
private void oEE地址管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
OEEaddress_Manage oeeManage = new OEEaddress_Manage();
oeeManage.ShowDialog();
}
private void 流程管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
Flow_Manage fLOW_Mange = new Flow_Manage();
@@ -1613,6 +1694,7 @@ namespace WindowsFormsApp1
{
//后一台气密
//<01>:(OK): 0.032 ml/min
//LogExecute.logNet.WriteDebug(ReturnValue);
Init.airtight.Leak_Value = ReturnValue.Substring(11, 5);
Init.airtight.LastTime = DateTime.Now;
}
@@ -1715,7 +1797,27 @@ namespace WindowsFormsApp1
};
kvHelper.Insert(newSetting);
}
if (newMode)
{
//调试
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
if (screwReportTimer.Enabled)
screwReportTimer.Stop();
}
if (fileUploadTimer.Enabled)
fileUploadTimer.Stop();
}
else
{
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
if(!screwReportTimer.Enabled)
screwReportTimer.Start();
}
if(!fileUploadTimer.Enabled)
fileUploadTimer.Start();
}
// 更新按钮状态
UpdateTestModeButtonState();
@@ -1744,22 +1846,30 @@ namespace WindowsFormsApp1
{
try
{
//beginScrewReportTimer++;
// 如果没有PLC数据或者状态为0,则不上报
if (Init.Plcstatus == 0 || Init.Plcstatus == -1)
{
return;
}
otherdata statusOtherData = new otherdata();
statusOtherData.Plc_Status = Init.Plcstatus;
statusOtherData.Plc_Status = Init.Plcstatus.ToString();
if (Init.Plcstatus == 2)
{
//报警
statusOtherData.Plc_Status = $"{Init.Plcstatus}_{Init.ErrorCode}";
}
var statusResult = statusApiClient.CallFunctionByName("Status", new plcdata(), statusOtherData);
if (statusResult.Success)
{
MES_MsgfORM("Status", statusResult, statusResult.Requesttime);
beginScrewReportTimer = 0;
//MES_MsgfORM("Status", statusResult, statusResult.Requesttime);
// 更新最后上报时间
Init.Plcstatus_LastTime = DateTime.Now;
LogExecute.OEElogNet.WriteDebug($"定时上报机台状态成功: {plcstatus.GetName(typeof(plcstatus), Init.Plcstatus)}");
LogExecute.OEElogNet.WriteDebug($"定时上报机台状态成功: {plcstatus.GetName(typeof(plcstatus), Init.Plcstatus)},{statusOtherData.Plc_Status}");
}
else
{
@@ -1772,7 +1882,94 @@ namespace WindowsFormsApp1
}
}
//螺丝扭力上传定时器
private void ScrewReportTimer_Tick(object sender, EventArgs e)
{
// 螺丝站
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
SQLiteHelper<t_materialupload> sQLiteHelper_upload = new db.SQLiteHelper<t_materialupload>();
var material_sqlresult = sQLiteHelper_upload
.Query(x => x.datacollectionUploaded == 1 && x.sn != "");
if (material_sqlresult.Success)
{
ApiClient apiClient = new ApiClient();
var materialList = material_sqlresult.Data.Where(x => (DateTime.Now - x.outtime).TotalMinutes > 20).Take(5);
foreach (var material in materialList)
{
otherdata OtherData = new otherdata();
OtherData.material = material;
var result = apiClient.CallFunctionByName("Data_Collection", new plcdata(), OtherData);
if (result.Success)
{
//MES_MsgfORM("Data_Collection", result, result.Requesttime);
if (result.Mesresult == mesresult.PASS)
{
//标记该物料已上传
material.datacollectionUploaded = 2;
sQLiteHelper_upload.Update(material);
LogExecute.logNet.WriteDebug($"{material.sn} 扭力上报成功!");
}
else if (result.Mesresult == mesresult.NONE)
{
material.datacollectionUploaded = 3;
sQLiteHelper_upload.Update(material);
}
}
}
}
}
}
// 定时扫描 周期扫描未上传 图片,视频等 sn,然后调用上传文件接口 todo
private void FileUploadTimer_Tick(object sender, EventArgs e)
{
//LogExecute.logNet.WriteDebug($"定时器文件执行!");
SQLiteHelper<t_materialupload> sQLiteHelper_upload = new db.SQLiteHelper<t_materialupload>();
var material_sqlresult = sQLiteHelper_upload
.Query(x => (x.imageUploaded == 1 || x.vedioUploaded == 1)
&& x.sn != ""
&& x.sn != "TEST MODE testsn");
if (material_sqlresult.Success)
{
ApiClient apiClient = new ApiClient();
var materialList = material_sqlresult.Data.Take(5);
foreach (var material in materialList)
{
otherdata OtherData = new otherdata();
OtherData.material = material;
OtherData.FileUploadAddress = Init.t_Keyvalues.First(x => x.key == "UploadPath").value;
OtherData.ImageAddress = Init.t_Keyvalues.First(x => x.key == "ImageFilePath").value;
OtherData.VedioAddress = Init.t_Keyvalues.First(x => x.key == "VedioFilePath").value;
var result = apiClient.CallFunctionByName("SN_FileUpload", new plcdata(), OtherData);
if (result.Success)
{
//MES_MsgfORM("Data_Collection", result, result.Requesttime);
if (result.Mesresult == mesresult.PASS)
{
//标记该物料已上传
if (material.imageUploaded == 1)
material.imageUploaded = 2;
if (material.vedioUploaded == 1)
material.vedioUploaded = 2;
sQLiteHelper_upload.Update(material);
LogExecute.logNet.WriteDebug($"{material.sn} 文件上传成功!");
}
else if (result.Mesresult == mesresult.NONE)
{
//标记该物料已上传
if (material.imageUploaded == 1)
material.imageUploaded = 3;
if (material.vedioUploaded == 1)
material.vedioUploaded = 3;
sQLiteHelper_upload.Update(material);
}
}
}
}
}
#endregion 定时器
/// <summary>
@@ -1825,43 +2022,74 @@ namespace WindowsFormsApp1
}
}
}
//plc心跳
private void plcheart(t_plc Plc, CancellationToken token)
{
while (!token.IsCancellationRequested)
Task.Factory.StartNew(() =>
{
try
while (!token.IsCancellationRequested)
{
SiemensHelp siemensHelp = Plc.plchelp;
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id);
plcdata PlcData = new plcdata();
var resdresult = siemensHelp.ReadAddress(plcaddress, PlcData);
if (!resdresult.Success)
try
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}读取全部地址处理错误!");
SiemensHelp siemensHelp = Plc.plchelp;
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id
&& a.code == "Write_Heartbeat" || a.code == "Read_Trigger");
List<t_plcaddress> timeplcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id
&& a.code == "NowDateTime");
plcdata PlcData = new plcdata();
var resdresult = siemensHelp.ReadAddress(plcaddress, PlcData);
if (!resdresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}读取全部地址处理错误!");
}
if(PlcData.Read_Trigger == 3 && Application.OpenForms.Count > 1)
{
foreach (Form form in Application.OpenForms)
{
if (form.Name == "ScanForm")
{
this.Invoke(new Action(() =>
{
form.Close();
}));
}
}
}
//写入心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳失败!");
}
//写入时间
var timeData = new plcdata
{
NowDateTime = DateTime.Now.AddSeconds(3)
};
var timeresult = siemensHelp.WriteAddress(timeplcaddress, timeData);
if (!timeresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入时间失败!");
}
}
//写入心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
//LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}写入心跳{PlcData.Write_Heartbeat}!");
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
catch (Exception)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳错误!");
}
finally
{
Thread.Sleep(1000);
}
}
catch (Exception)
{
}
finally
{
Thread.Sleep(1000);
}
}
}, token, TaskCreationOptions.LongRunning, TaskScheduler.Default
);
}
}
}
+2
View File
@@ -48,6 +48,7 @@ namespace WindowsFormsApp1
public static List<t_angleaddress> t_Angleaddresses;
public static List<t_torqueaddress> t_Torqueaddresses;
public static List<t_pressurecurve> t_Pressurecurves;
public static List<t_oeeaddress> t_Oeeaddresses;
public static List<t_keyvalue> t_Keyvalues;
@@ -58,6 +59,7 @@ namespace WindowsFormsApp1
public static string DZString;
//PLC状态存储
public static short Plcstatus = -1;
public static string ErrorCode = "";
//PLC最后状态事件(用于计时15秒状态不变回传)
public static DateTime Plcstatus_LastTime = DateTime.Now;
+36
View File
@@ -45,6 +45,42 @@ namespace WindowsFormsApp1.db
}
/// <summary>
/// 数据插入
/// </summary>
/// <param name="item">要插入的数据项</param>
/// <returns></returns>
public BllResult InsertAll(List<T> item)
{
if (_connection.InsertAll(item) > 0)
{
return BllResult.Sucess();
}
else
{
return BllResult.Error();
}
}
/// <summary>
/// 数据删除
/// </summary>
/// <param name="item">要插入的数据项</param>
/// <returns></returns>
public BllResult DeleteAll()
{
if (_connection.DeleteAll<T>() > 0)
{
return BllResult.Sucess();
}
else
{
return BllResult.Error();
}
}
/// <summary>
/// 数据删除
/// </summary>
+218
View File
@@ -0,0 +1,218 @@
namespace WindowsFormsApp1.form
{
partial class OEEaddress_Manage
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.plcid = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.code = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.type = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.dbaddress = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.addresstype = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.addresstypelegth = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.addressoffset = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.addressdecimal = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.remark = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.button1 = new System.Windows.Forms.Button();
this.查询 = new System.Windows.Forms.Button();
this.清空 = new System.Windows.Forms.Button(); // 将保存改为清空
this.关闭 = new System.Windows.Forms.Button();
this.导入 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.id,
this.plcid,
this.code,
this.type,
this.dbaddress,
this.addresstype,
this.addresstypelegth,
this.addressoffset,
this.addressdecimal,
this.remark});
this.dataGridView1.Location = new System.Drawing.Point(12, 41);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(1200, 397);
this.dataGridView1.TabIndex = 0;
//
// id
//
this.id.DataPropertyName = "id";
this.id.HeaderText = "id";
this.id.Name = "id";
//
// plcid
//
this.plcid.DataPropertyName = "plcid";
this.plcid.HeaderText = "plcid";
this.plcid.Name = "plcid";
//
// code
//
this.code.DataPropertyName = "code";
this.code.HeaderText = "code";
this.code.Name = "code";
//
// type
//
this.type.DataPropertyName = "type";
this.type.HeaderText = "类型";
this.type.Name = "type";
//
// dbaddress
//
this.dbaddress.DataPropertyName = "dbaddress";
this.dbaddress.HeaderText = "地址";
this.dbaddress.Name = "dbaddress";
//
// addresstype
//
this.addresstype.DataPropertyName = "addresstype";
this.addresstype.HeaderText = "地址类型";
this.addresstype.Name = "addresstype";
//
// addresstypelegth
//
this.addresstypelegth.DataPropertyName = "addresstypelegth";
this.addresstypelegth.HeaderText = "地址长度";
this.addresstypelegth.Name = "addresstypelegth";
//
// addressoffset
//
this.addressoffset.DataPropertyName = "addressoffset";
this.addressoffset.HeaderText = "地址偏移";
this.addressoffset.Name = "addressoffset";
//
// addressdecimal
//
this.addressdecimal.DataPropertyName = "addressdecimal";
this.addressdecimal.HeaderText = "位地址";
this.addressdecimal.Name = "addressdecimal";
//
// remark
//
this.remark.DataPropertyName = "remark";
this.remark.HeaderText = "备注";
this.remark.Name = "remark";
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "新增";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// 查询
//
this.查询.Location = new System.Drawing.Point(93, 12);
this.查询.Name = "查询";
this.查询.Size = new System.Drawing.Size(75, 23);
this.查询.TabIndex = 2;
this.查询.Text = "查询";
this.查询.UseVisualStyleBackColor = true;
this.查询.Click += new System.EventHandler(this.查询_Click);
//
// 清空
//
this.清空.Location = new System.Drawing.Point(174, 12);
this.清空.Name = "清空";
this.清空.Size = new System.Drawing.Size(75, 23);
this.清空.TabIndex = 3;
this.清空.Text = "清空";
this.清空.UseVisualStyleBackColor = true;
this.清空.Click += new System.EventHandler(this.清空_Click);
//
// 关闭
//
this.关闭.Location = new System.Drawing.Point(255, 12);
this.关闭.Name = "关闭";
this.关闭.Size = new System.Drawing.Size(75, 23);
this.关闭.TabIndex = 4;
this.关闭.Text = "关闭";
this.关闭.UseVisualStyleBackColor = true;
this.关闭.Click += new System.EventHandler(this.关闭_Click);
//
// 导入
//
this.导入.Location = new System.Drawing.Point(336, 12);
this.导入.Name = "导入";
this.导入.Size = new System.Drawing.Size(75, 23);
this.导入.TabIndex = 5;
this.导入.Text = "导入";
this.导入.UseVisualStyleBackColor = true;
this.导入.Click += new System.EventHandler(this.导入_Click);
//
// OEEaddress_Manage
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1210, 450);
this.Controls.Add(this.导入);
this.Controls.Add(this.关闭);
this.Controls.Add(this.清空);
this.Controls.Add(this.查询);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGridView1);
this.Name = "OEEaddress_Manage";
this.Text = "OEE地址管理";
this.Load += new System.EventHandler(this.OEEaddress_Manage_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button 查询;
private System.Windows.Forms.Button 清空; // 将保存改为清空
private System.Windows.Forms.Button 关闭;
private System.Windows.Forms.Button 导入;
private System.Windows.Forms.DataGridViewTextBoxColumn id;
private System.Windows.Forms.DataGridViewTextBoxColumn plcid;
private System.Windows.Forms.DataGridViewTextBoxColumn code;
private System.Windows.Forms.DataGridViewComboBoxColumn type;
private System.Windows.Forms.DataGridViewTextBoxColumn dbaddress;
private System.Windows.Forms.DataGridViewComboBoxColumn addresstype;
private System.Windows.Forms.DataGridViewTextBoxColumn addresstypelegth;
private System.Windows.Forms.DataGridViewTextBoxColumn addressoffset;
private System.Windows.Forms.DataGridViewTextBoxColumn addressdecimal;
private System.Windows.Forms.DataGridViewTextBoxColumn remark;
}
}
+396
View File
@@ -0,0 +1,396 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp1.db;
using WindowsFormsApp1.mod;
namespace WindowsFormsApp1.form
{
public partial class OEEaddress_Manage : Form
{
public OEEaddress_Manage()
{
InitializeComponent();
}
private void 查询_Click(object sender, EventArgs e)
{
GetInfo();
}
private void 关闭_Click(object sender, EventArgs e)
{
this.Close();
}
private void OEEaddress_Manage_Load(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = false;
SQLiteHelper<t_plc> sQLiteHelper1 = new db.SQLiteHelper<t_plc>();
var result_combox = sQLiteHelper1.QueryAll();
if (!result_combox.Success)
{
MessageBox.Show("查询失败");
return;
}
var result1 = new List<object>
{
new {name = "read",value = "read"},
new {name = "write",value = "write"}
};
var result2 = new List<object>
{
new {name = "real",value = "real"},
new {name = "string",value = "string"},
new {name = "uint",value = "uint"},
new {name = "bool",value = "bool"},
new {name = "int",value = "int"},
new {name = "dint",value = "dint"},
new {name = "byte",value = "byte"},
};
var comboBoxColumn = (DataGridViewComboBoxColumn)dataGridView1.Columns[3];
// 绑定数据源到 ComboBox
comboBoxColumn.DataSource = result1;
comboBoxColumn.DisplayMember = "name";
comboBoxColumn.ValueMember = "value";
comboBoxColumn.DataPropertyName = "type";
var comboBoxColumn1 = (DataGridViewComboBoxColumn)dataGridView1.Columns[5];
// 绑定数据源到 ComboBox
comboBoxColumn1.DataSource = result2;
comboBoxColumn1.DisplayMember = "name";
comboBoxColumn1.ValueMember = "value";
comboBoxColumn1.DataPropertyName = "addresstype";
DataGridViewButtonColumn modifyColumn = new DataGridViewButtonColumn();
modifyColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
modifyColumn.Name = "ModifyColumn";
modifyColumn.HeaderText = "修改";
modifyColumn.Text = "修改";
modifyColumn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(modifyColumn);
// 添加删除按钮列
DataGridViewButtonColumn deleteColumn = new DataGridViewButtonColumn();
deleteColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
deleteColumn.Name = "DeleteColumn";
deleteColumn.HeaderText = "删除";
deleteColumn.Text = "删除";
deleteColumn.UseColumnTextForButtonValue = true;
dataGridView1.CellContentClick += DataGridView1_CellContentClick;
dataGridView1.Columns.Add(deleteColumn);
GetInfo();
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// 检查点击的是否为按钮列
if (e.RowIndex >= 0)
{
DataGridView dataGridView = (DataGridView)sender;
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
int selectid = int.Parse(row.Cells[0].Value.ToString());
if (e.ColumnIndex == 10)
{
OEEaddress_Insert oeeInsert = new OEEaddress_Insert();
oeeInsert.dataid = selectid;
oeeInsert.Operation = OperationType.Edit;
oeeInsert.ShowDialog();
GetInfo();
}
else if (e.ColumnIndex == 11)
{
DialogResult result = MessageBox.Show("你确定要删除数据吗?", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
SQLiteHelper<t_oeeaddress> sQLiteHelper = new db.SQLiteHelper<t_oeeaddress>();
var delresult = sQLiteHelper.Delete(selectid);
if (delresult.Success)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show("删除失败");
}
GetInfo();
}
}
}
}
public void GetInfo()
{
try
{
dataGridView1.DataSource = null;
SQLiteHelper<t_oeeaddress> sQLiteHelper = new db.SQLiteHelper<t_oeeaddress>();
var result = sQLiteHelper.QueryAll();
if (result.Success)
{
List<object> list = new List<object>();
foreach (var plcaddress in result.Data)
{
list.Add(new
{
id = plcaddress.id,
plcid = plcaddress.plcid,
code = plcaddress.code,
type = plcaddress.type,
dbaddress = plcaddress.dbaddress,
addresstype = plcaddress.addresstype,
addresstypelegth = plcaddress.addresstypelegth,
addressoffset = plcaddress.addressoffset,
remark = plcaddress.remark,
value = plcaddress.value,
addressdecimal = plcaddress.addressdecimal
});
}
dataGridView1.DataSource = list;
dataGridView1.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show($"查询失败,错误原因:{ex.Message}");
}
}
private void button1_Click(object sender, EventArgs e)
{
OEEaddress_Insert oeeInsert = new OEEaddress_Insert();
oeeInsert.ShowDialog();
GetInfo();
}
// 添加导入按钮点击事件处理
private void 导入_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "CSV文件|*.csv";
openFileDialog.Title = "选择要导入的CSV文件";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = openFileDialog.FileName;
ImportFromCSV(filePath);
}
}
catch (Exception ex)
{
MessageBox.Show($"导入失败,错误原因:{ex.Message}");
}
}
private void ImportFromCSV(string filePath)
{
try
{
List<t_oeeaddress> addressList = new List<t_oeeaddress>();
// 读取CSV文件 - 修改编码方式
// 尝试使用UTF-8编码读取
string[] lines = System.IO.File.ReadAllLines(filePath, Encoding.UTF8);
// 如果检测到乱码,可以尝试其他编码
if (ContainsGarbledText(lines))
{
// 尝试使用GB2312编码
lines = System.IO.File.ReadAllLines(filePath, Encoding.GetEncoding("gb2312"));
// 如果仍然乱码,再尝试其他编码
if (ContainsGarbledText(lines))
{
// 尝试使用GBK编码
lines = System.IO.File.ReadAllLines(filePath, Encoding.GetEncoding("gbk"));
}
}
// 从第2行开始读取数据(假设第1行是标题)
for (int i = 1; i < lines.Length; i++)
{
string line = lines[i];
if (string.IsNullOrWhiteSpace(line))
continue;
// 分割CSV行并去除双引号
string[] values = SplitCsvLineAndRemoveQuotes(line);
if (values.Length < 10)
{
MessageBox.Show($"第{i + 1}行数据格式不正确,请检查CSV文件格式");
break;
}
var test = values[0];
try
{
t_oeeaddress address = new t_oeeaddress
{
plcid = Convert.ToInt32(values[0]),
code = values[1],
type = values[2],
dbaddress = values[3],
addresstype = values[4],
addresstypelegth = Convert.ToInt32(values[5]),
addressoffset = Convert.ToInt32(values[6]),
addressdecimal = Convert.ToInt32(values[7]),
remark = values[8] ?? "",
};
addressList.Add(address);
}
catch (FormatException)
{
MessageBox.Show($"第{i + 1}行数据格式转换错误,请检查数据类型是否正确");
break;
}
}
SaveImportedData(addressList);
}
catch (Exception ex)
{
MessageBox.Show($"CSV导入失败,错误原因:{ex.Message}");
}
}
// 添加一个方法来分割CSV行并去除双引号
private string[] SplitCsvLineAndRemoveQuotes(string line)
{
// 使用正则表达式处理CSV,考虑引号内的逗号
List<string> result = new List<string>();
bool inQuotes = false;
StringBuilder field = new StringBuilder();
for (int i = 0; i < line.Length; i++)
{
char c = line[i];
if (c == '"')
{
// 如果是引号,切换引号状态
inQuotes = !inQuotes;
// 不将引号添加到结果中
}
else if (c == ',' && !inQuotes)
{
// 如果是逗号且不在引号内,则添加当前字段并重置
result.Add(field.ToString().Trim());
field.Clear();
}
else
{
// 其他字符直接添加
field.Append(c);
}
}
// 添加最后一个字段
result.Add(field.ToString().Trim());
return result.ToArray();
}
// 添加一个辅助方法检测文本是否包含乱码
private bool ContainsGarbledText(string[] lines)
{
// 简单检测:如果包含特定的乱码字符,则认为是乱码
// 这里只是一个简单的示例,可能需要根据实际情况调整
string pattern = @"[\u0000-\u001F\u007F-\u009F]"; // 控制字符
foreach (string line in lines)
{
if (System.Text.RegularExpressions.Regex.IsMatch(line, pattern))
{
return true;
}
}
return false;
}
private void SaveImportedData(List<t_oeeaddress> addressList)
{
if (addressList.Count == 0)
{
MessageBox.Show("没有有效数据可导入");
return;
}
try
{
SQLiteHelper<t_oeeaddress> sQLiteHelper = new db.SQLiteHelper<t_oeeaddress>();
var result = sQLiteHelper.InsertAll(addressList);
if (result.Success)
{
// 更新缓存
var allAddresses = sQLiteHelper.QueryAll();
if (allAddresses.Success)
{
Init.t_Oeeaddresses = allAddresses.Data;
}
MessageBox.Show($"成功导入{addressList.Count}条数据");
GetInfo(); // 刷新数据显示
}
else
{
MessageBox.Show($"导入失败:{result.Msg}");
}
}
catch (Exception ex)
{
MessageBox.Show($"保存导入数据失败,错误原因:{ex.Message}");
}
}
// 添加清空按钮点击事件处理
private void 清空_Click(object sender, EventArgs e)
{
try
{
DialogResult result = MessageBox.Show("确定要删除所有数据吗?此操作不可恢复!", "警告",
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == DialogResult.OK)
{
SQLiteHelper<t_oeeaddress> sQLiteHelper = new db.SQLiteHelper<t_oeeaddress>();
var deleteResult = sQLiteHelper.DeleteAll();
if (deleteResult.Success)
{
MessageBox.Show("所有数据已成功删除!");
GetInfo(); // 刷新数据显示
}
else
{
MessageBox.Show($"删除失败:{deleteResult.Msg}");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"清空数据失败,错误原因:{ex.Message}");
}
}
}
}
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,276 @@
namespace WindowsFormsApp1.form
{
partial class OEEaddress_Insert
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.comboBox3 = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label9 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 12);
this.label1.TabIndex = 0;
this.label1.Text = "PLC:";
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(47, 12);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 12);
this.label2.TabIndex = 2;
this.label2.Text = "编码:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(47, 38);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(121, 21);
this.textBox1.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 68);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 12);
this.label3.TabIndex = 4;
this.label3.Text = "类型:";
//
// comboBox2
//
this.comboBox2.FormattingEnabled = true;
this.comboBox2.Location = new System.Drawing.Point(47, 65);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 20);
this.comboBox2.TabIndex = 5;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 95);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(35, 12);
this.label4.TabIndex = 6;
this.label4.Text = "地址:";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(47, 92);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(121, 21);
this.textBox2.TabIndex = 7;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 122);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(59, 12);
this.label5.TabIndex = 8;
this.label5.Text = "地址类型:";
//
// comboBox3
//
this.comboBox3.FormattingEnabled = true;
this.comboBox3.Location = new System.Drawing.Point(77, 119);
this.comboBox3.Name = "comboBox3";
this.comboBox3.Size = new System.Drawing.Size(91, 20);
this.comboBox3.TabIndex = 9;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(12, 149);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(59, 12);
this.label6.TabIndex = 10;
this.label6.Text = "地址长度:";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(77, 146);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(91, 21);
this.textBox3.TabIndex = 11;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(12, 176);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(59, 12);
this.label7.TabIndex = 12;
this.label7.Text = "地址偏移:";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(77, 173);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(91, 21);
this.textBox4.TabIndex = 13;
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(12, 206);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(59, 12);
this.label8.TabIndex = 14;
this.label8.Text = "位地址值:";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(77, 203);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(91, 21);
this.textBox6.TabIndex = 15;
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(12, 236);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(59, 12);
this.label9.TabIndex = 16;
this.label9.Text = "备注:";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(77, 233);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(91, 21);
this.textBox5.TabIndex = 17;
//
// button1
//
this.button1.Location = new System.Drawing.Point(14, 264);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 18;
this.button1.Text = "确定";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(95, 264);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 19;
this.button2.Text = "取消";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// OEEaddress_Insert
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(184, 299);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.label9);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.label8);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.label7);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label6);
this.Controls.Add(this.comboBox3);
this.Controls.Add(this.label5);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label4);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Name = "OEEaddress_Insert";
this.Text = "OEE地址编辑";
this.Load += new System.EventHandler(this.OEEaddress_Insert_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox comboBox3;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
}
@@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp1.db;
using WindowsFormsApp1.mod;
namespace WindowsFormsApp1.form
{
public partial class OEEaddress_Insert : Form
{
public int dataid { get; set; }
public OperationType Operation { get; set; } = OperationType.Add;
public OEEaddress_Insert()
{
InitializeComponent();
}
private void OEEaddress_Insert_Load(object sender, EventArgs e)
{
SQLiteHelper<t_plc> sQLiteHelper = new db.SQLiteHelper<t_plc>();
var result = sQLiteHelper.QueryAll();
if (result.Success)
{
comboBox1.DataSource = result.Data;
comboBox1.DisplayMember = "plcname";
comboBox1.ValueMember = "id";
comboBox1.SelectedValue = Init.t_Line.plcid;
}
comboBox2.Items.Add("read");
comboBox2.Items.Add("write");
comboBox2.SelectedIndex = 0;
comboBox3.Items.Add("bool");
comboBox3.Items.Add("real");
comboBox3.Items.Add("string");
comboBox3.Items.Add("uint");
comboBox3.Items.Add("int");
comboBox3.Items.Add("dint");
comboBox3.Items.Add("byte");
comboBox3.SelectedIndex = 0;
if (Operation == OperationType.Edit)
{
SQLiteHelper<t_oeeaddress> sQLiteHelper1 = new db.SQLiteHelper<t_oeeaddress>();
var result1 = sQLiteHelper1.QuerySingle(x => x.id == dataid);
if (result1.Success)
{
comboBox1.SelectedValue = result1.Data.plcid;
textBox1.Text = result1.Data.code;
comboBox2.Text = result1.Data.type;
textBox2.Text = result1.Data.dbaddress;
comboBox3.Text = result1.Data.addresstype;
textBox3.Text = result1.Data.addresstypelegth.ToString();
textBox4.Text = result1.Data.addressoffset.ToString();
textBox6.Text = result1.Data.addressdecimal.ToString();
textBox5.Text = result1.Data.remark;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
t_oeeaddress t_Oeeaddress = new t_oeeaddress();
t_Oeeaddress.plcid = (int)comboBox1.SelectedValue;
t_Oeeaddress.code = textBox1.Text;
t_Oeeaddress.type = comboBox2.Text;
t_Oeeaddress.dbaddress = textBox2.Text;
t_Oeeaddress.addresstype = comboBox3.Text;
t_Oeeaddress.addresstypelegth = int.Parse(textBox3.Text);
t_Oeeaddress.addressoffset = int.Parse(textBox4.Text);
t_Oeeaddress.remark = textBox5.Text;
// 处理位地址
if (!string.IsNullOrEmpty(textBox6.Text) && int.TryParse(textBox6.Text, out int bitOffset))
{
t_Oeeaddress.addressdecimal = bitOffset;
}
SQLiteHelper<t_oeeaddress> sQLiteHelper = new db.SQLiteHelper<t_oeeaddress>();
if (Operation == OperationType.Add)
{
var result = sQLiteHelper.Insert(t_Oeeaddress);
if (result.Success)
{
MessageBox.Show("添加成功");
this.Close();
}
else
{
MessageBox.Show("添加失败");
}
}
else
{
t_Oeeaddress.id = dataid;
var result = sQLiteHelper.Update(t_Oeeaddress);
if (result.Success)
{
// 更新缓存
var cacheIndex = Init.t_Oeeaddresses.FindIndex(x => x.id == dataid);
if (cacheIndex != -1)
{
Init.t_Oeeaddresses[cacheIndex] = t_Oeeaddress;
}
MessageBox.Show("修改成功");
this.Close();
}
else
{
MessageBox.Show("修改失败");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"操作失败,错误原因:{ex.Message}");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
@@ -16,5 +16,6 @@ namespace WindowsFormsApp1.mod
public int vedioUploaded { get; set; }
public int datacollectionUploaded { get; set; }
public string date { get; set; }
public DateTime outtime { get; set; }
}
}
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SQLite;
namespace WindowsFormsApp1.mod
{
[Table("oeeaddress")]
public class t_oeeaddress
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public int plcid { get; set; }
public string code { get; set; }
public string type { get; set; }
public string dbaddress { get; set; }
public string addresstype { get; set; }
public int addresstypelegth { get; set; }
public int addressoffset { get; set; }
// 添加位地址支持,用于存储布尔类型的位偏移
public int addressdecimal { get; set; }
public string remark { get; set; }
public string value { get; set; }
}
}
+7 -2
View File
@@ -11,7 +11,7 @@ namespace WindowsFormsApp1.mod.server
/// <summary>
/// PLC反馈的机台状态
/// </summary>
public int Plc_Status { get; set; }
public string Plc_Status { get; set; }
/// <summary>
/// PLC反馈的机台报警(默认获取0位)
@@ -51,7 +51,7 @@ namespace WindowsFormsApp1.mod.server
/// <summary>
/// 螺丝枪角度
/// </summary>
public List<float> FinalAngleValue { get; set; }
public List<List<dynamic>> FinalAngleValue { get; set; }
/// <summary>
/// 螺丝枪扭力曲线
@@ -80,6 +80,11 @@ namespace WindowsFormsApp1.mod.server
public int plcid { get; set; }
public t_materialupload material { get; set; }
/// <summary>
/// oee
/// </summary>
public List<t_oeeaddress> Oeeaddresses { get; set; }
}
+1
View File
@@ -187,5 +187,6 @@ namespace WindowsFormsApp1.mod.server
/// 写入PLC的时间
/// </summary>
public DateTime Write_Time2 { get; set; }
public DateTime NowDateTime { get; set; }
}
}
+255 -197
View File
@@ -143,7 +143,14 @@ namespace WindowsFormsApp1.server
PlcData.Write_Status = (short)statusCode;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = "TEST MODE testsn";
LogExecute.logNet.WriteDebug($"{eventName} 测试接口请求成功\n请求:{jsonPayload}\n");
if (eventName == "Status" || eventName == "Alarm" || eventName == "OEEDataCollection")
{
LogExecute.OEElogNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n");
}
else
{
LogExecute.logNet.WriteDebug($"{eventName} 测试接口请求成功\n请求:{jsonPayload}\n");
}
return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
}
#endregion test
@@ -157,7 +164,8 @@ namespace WindowsFormsApp1.server
var response = _httpClient.PostAsync(url, httpContent).Result;
// 检查响应状态码
if (response.StatusCode == System.Net.HttpStatusCode.OK)
if (response.StatusCode == System.Net.HttpStatusCode.OK
|| response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
// 读取响应内容
string responseContent = response.Content.ReadAsStringAsync().Result;
@@ -168,20 +176,28 @@ namespace WindowsFormsApp1.server
// 访问动态对象的属性
if (res != null)
{
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
//oee相关日志单独存
if (eventName == "Status" || eventName == "Alarm" || eventName == "OEEDataCollection")
{
LogExecute.OEElogNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
}
else
{
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
}
// 成功!
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Value))
{
var result = res.Result.Value == "PASS";
if (!string.IsNullOrEmpty(res?.Need_Work?.Value) && res?.Need_Work?.Value == "PASS")
result = true;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = res.SN.Value;
if (result)
{
// 回写对应PLC
if (statusCode > 0)
PlcData.Write_Status = (short)statusCode;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = res.SN.Value;
if (eventName == "SN_FeedingCheck")
{
var station = Init.t_Line.lineremark2.ToLower();
@@ -447,7 +463,7 @@ namespace WindowsFormsApp1.server
//判断站
var station = Init.t_Line.lineremark2.ToLower();
var fixsn_1 = "";
var locationindex = 1;
var locationindex = "";
switch (station)
{
case "potting"://灌胶
@@ -457,7 +473,7 @@ namespace WindowsFormsApp1.server
break;
default:
fixsn_1 = "CompSN";
locationindex = OtherData.locationindex;
locationindex = OtherData.locationindex.ToString();
break;
}
@@ -468,13 +484,13 @@ namespace WindowsFormsApp1.server
StationID = _stationID,
MachineID = _machineID,
OPID = OtherData.opindex,
Token = locationindex.ToString() ?? "",//判断站,胶水不用传
Token = locationindex ?? "",//判断站,胶水不用传
FixSN = fixsn_1,//判断站,胶水不用传
SN = OtherData.JS_SN ?? "",
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
};
return CallApi(url, request, "Glue_CheckOut", PlcData, PLC_Status.Glue_CheckOut);
return CallApi(url, request, "Glue_CheckOut", PlcData, 0);
}
/// <summary>
@@ -525,14 +541,14 @@ namespace WindowsFormsApp1.server
else if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(station))
{
// 扭力 读马头服务器
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark3}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date.Substring(0, 10)}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark2}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
//var geturl = "http://10.50.12.41/getdata/v2/tighteningresults?startTime=2025-04-11&endTime=2025-04-12&vin=ok&controllerName=OP1260%4010.50.247.110&includeCurve=true&includeSteps=false";
var res = _httpClient.GetAsync(geturl).Result;
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
//var getresult = JsonConvert.DeserializeObject(res.Content.ReadAsStringAsync().Result);
// 扭力 读马头服务器 todo
// 扭力 读马头服务器
try
{
// 反序列化 JSON 数据
@@ -579,18 +595,20 @@ namespace WindowsFormsApp1.server
}
catch (Exception ex)
{
Console.WriteLine($"发生错误: {ex.Message}");
LogExecute.logNet.WriteError($"解析马头数据,发生错误: {ex.Message}");
}
}
else
{
return ApiFormResult.Sucess(mesresult.FAIL, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
}
if (request.DC_INFO.Count == 0)
{
return ApiFormResult.Sucess(mesresult.NONE, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
}
}
return CallApi(url, request, "Data_Collection", PlcData, statusCode);
//if(result.Success && result.Mesresult == mesresult.PASS)
//{
// OtherData.material.datacollectionUploaded = 2;
// var dbhelper = new SQLiteHelper<t_materialupload>();
// dbhelper.Update(OtherData.material);
//}
}
public ApiFormResult Status(string url, plcdata PlcData, otherdata OtherData)
@@ -620,7 +638,7 @@ namespace WindowsFormsApp1.server
StationID = _stationID,
MachineID = _machineID,
OPID = _opID,
AlarmID = OtherData.Plc_ErrorMsgs[0],
AlarmID = Init.ErrorCode ?? "",
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
ResetTime = ""
};
@@ -638,21 +656,41 @@ namespace WindowsFormsApp1.server
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
{
// 准备文件 视频/图片 目的路径拼接
var month = DateTime.Now.ToString("yyyyMM");
var day = DateTime.Now.ToString("dd");
var month = "";
var day = "";
if (OtherData.material.imageUploaded == 1)
{
month = OtherData.material.date.Replace("-", "").Substring(0, 6);
day = OtherData.material.date.Replace("-", "").Substring(6, 2);
}
else
{
var monthList = OtherData.material.date.Split('-');
month = $"{monthList[0]}{monthList[1]}";
day = monthList[2];
}
var monthDay = DateTime.Now.ToString("MMdd");
var time = DateTime.Now.ToString("HHmmss");
var result = PlcData.Read_Result == 1 ? "OK" : "NG";
var result = OtherData.material.result;
var targetDirectory = $"{OtherData.FileUploadAddress}{_line.Substring(0, 2)}\\{month}\\{day}\\Line{_line.Substring(_line.Length - 2)}\\{_stationID}\\{_machineID}\\{result}";
var fileName = "";
try
{
string[] sourceFolders = new string[] {
string[] sourceFolders = new string[]
{
OtherData.ImageAddress,
OtherData.VedioAddress
};
if (OtherData.material.imageUploaded != 1)
{
sourceFolders[0] = "";
}
if (OtherData.material.vedioUploaded != 1)
{
sourceFolders[1] = "";
}
// 使用分号分隔多个源文件夹
string targetFolder = targetDirectory;
List<string> fileList = new List<string>();
@@ -666,11 +704,6 @@ namespace WindowsFormsApp1.server
return ApiFormResult.Error(mesresult.FAIL, false, "SN号为空", PlcData, DateTime.Now);
}
if (!Directory.Exists(targetFolder))
{
Directory.CreateDirectory(targetFolder);
}
foreach (string folder in sourceFolders)
{
if (string.IsNullOrEmpty(folder))
@@ -678,32 +711,32 @@ namespace WindowsFormsApp1.server
continue;
}
//判断此sn需要传哪些数据 图片 或视频 todo
string sourceFolder = sourceFolders[0];
if (sourceFolder == folder)
string sourceFolder = "";
if (OtherData.ImageAddress == folder)
{
// 图片
// 组装路径 可能需要从数据库读 result和sn和日期
sourceFolder = Path.Combine(sourceFolder, OtherData.material.date, "DCDC", result);
sourceFolder = Path.Combine(OtherData.ImageAddress, OtherData.material.date.Replace("-", ""), "DCDC", result);
}
else
{
// 视频
sourceFolder = Path.Combine(sourceFolder, DateTime.Now.ToString("yyyy-MM-dd"));
sourceFolder = Path.Combine(OtherData.VedioAddress, OtherData.material.date);
}
if (Directory.Exists(sourceFolder.Trim()))
{
string[] files = Directory.GetFiles(sourceFolder.Trim());
int num = 1;
var extensionstr = "";
foreach (string file in files)
foreach (string file in files.Where(x => x.Contains(snNumber)))
{
string fileName1 = Path.GetFileName(file);
string filePath = "";
if (!fileName1.Contains(snNumber))
{
continue;
}
extensionstr = Path.GetExtension(file);
var datetime = Directory.GetLastWriteTime(file);
monthDay = datetime.ToString("MMdd");
time = datetime.ToString("HHmmss");
fileName = $"{month}{day}_{_stationID}_{result}_{snNumber}_{monthDay}_{time}_{_machineID}_01_Detection_{num}{extensionstr}";
filePath = Path.Combine(sourceFolder, fileName1);
CopyFileToDirectory(filePath, targetFolder, fileName);
@@ -722,7 +755,7 @@ namespace WindowsFormsApp1.server
{
//标记sn的回传状态,以免下次定时器还能查到这种
LogExecute.logNet.WriteDebug($"在所有源文件夹中未找到包含SN号 {snNumber} 的文件");
return ApiFormResult.Error(mesresult.FAIL, false, "", PlcData, DateTime.Now);
return ApiFormResult.Sucess(mesresult.NONE, false, "", PlcData, DateTime.Now);
}
// 组装 request json
@@ -736,7 +769,7 @@ namespace WindowsFormsApp1.server
{
new
{
SN = PlcData.Write_stSN,
SN = snNumber,
FileInfo = fileList.Select(x => new
{
FileName = x,
@@ -747,7 +780,7 @@ namespace WindowsFormsApp1.server
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
};
return CallApi(url, request, "SN_FileUpload", PlcData, PLC_Status.SN_FileUpload);
return CallApi(url, request, "SN_FileUpload", PlcData, 0);
}
catch (Exception ex)
{
@@ -784,7 +817,7 @@ namespace WindowsFormsApp1.server
var result = PlcData.Read_Result == 1 ? "PASS" : "FAIL";
var logresult = PlcData.Read_Result == 1 ? "OK" : "NG";
// 基础请求对象
var request = new CheckOutObject()
{
@@ -852,55 +885,63 @@ namespace WindowsFormsApp1.server
//扭力,角度
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".Contains(stationid))
{
var count = OtherData.FinalAngleValue.Count(x => x > 0);
for (int i = 0; i < count; i++)
{
CsvLogger.Log($"{PlcData.Write_stSN},{OtherData.FinalAngleValue[i]},{OtherData.FinalTorqueValue[i]}");
}
Dictionary<int, int> countDict = new Dictionary<int, int>();
var AngleCount = 1;
foreach (var item in OtherData.FinalAngleValue.Where(x => x > 0))
foreach (var item in OtherData.FinalAngleValue)
{
//角度
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Angle{AngleCount}";
dcInfo.Value = item.ToString();
dcInfo.Result = result;
sninfo.DC_INFO.Add(dcInfo);
AngleCount++;
}
var TorqueCount = 1;
foreach (var item in OtherData.FinalTorqueValue.Where(x => x > 0))
{
//扭力
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Torque{TorqueCount}";
dcInfo.Value = item.ToString();
dcInfo.Result = result;
sninfo.DC_INFO.Add(dcInfo);
TorqueCount++;
}
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
{
material = new t_materialupload
if (item[0] > 0)
{
sn = PlcData.Write_stSN,
CarrierID = PlcData.Write_stSN,
datacollectionUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd")
};
materialuploadHelper.Insert(material);
var value = item[3];
if (!countDict.ContainsKey(value))
{
countDict[value] = 1;
}
else
{
countDict[value]++;
}
var scewResult = item[2] == 1 ? "PASS" : "FAIL";
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Angle{item[3]}_{countDict[value]}";
dcInfo.Value = item[1].ToString();
dcInfo.Result = scewResult;
sninfo.DC_INFO.Add(dcInfo);
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Torque{item[3]}_{countDict[value]}";
dcInfo.Value = item[0].ToString();
dcInfo.Result = scewResult;
sninfo.DC_INFO.Add(dcInfo);
CsvLogger.Log($"{PlcData.Write_stSN},{item[1]},{item[0]}");
}
}
else
if (!_isTestMode)
{
material.datacollectionUploaded = 1;
materialuploadHelper.Update(material);
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
{
material = new t_materialupload
{
sn = PlcData.Write_stSN,
CarrierID = PlcData.Read_MaterialCode1,
datacollectionUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd"),
outtime = DateTime.Now
};
materialuploadHelper.Insert(material);
}
else
{
material.datacollectionUploaded = 1;
materialuploadHelper.Update(material);
}
}
}
@@ -918,7 +959,7 @@ namespace WindowsFormsApp1.server
}
//LogExecute.SNlogNet.WriteDebug($"追溯码:{PlcData.Read_MaterialCode0},检测结果:{logresult}");
}
//抽真空 压力
if ("Vacuum".Contains(stationid))
{
@@ -941,7 +982,7 @@ namespace WindowsFormsApp1.server
str += $",{dcInfo.Value},";
CsvLogger.Log(str);
}
//固化 时间
if ("Curing".Contains(stationid))
{
@@ -967,6 +1008,12 @@ namespace WindowsFormsApp1.server
Result = result
});
CsvLogger.Log($"{PlcData.Write_stSN},{PlcData.Read_UploadData0.ToString()},{jrTime}");
var jrtime = ((TimeSpan)((material.Data.checkin2 ?? new DateTime()) - (material.Data.checkout1 ?? new DateTime()))).TotalSeconds;
PlcData.Write_ReceiveData0 = (float)jrtime;
var lqtime = ((TimeSpan)((material.Data.checkin3 ?? new DateTime()) - (material.Data.checkout2 ?? new DateTime()))).TotalSeconds;
PlcData.Write_ReceiveData1 = (float)lqtime;
}
else
{
@@ -1027,51 +1074,59 @@ namespace WindowsFormsApp1.server
sninfo.CompList.Add(compListItem);
}
//图片上传
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
if (!_isTestMode)
{
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
//图片上传 Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
{
material = new t_materialupload
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
{
sn = PlcData.Write_stSN,
imageUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyyMMdd")
};
materialuploadHelper.Insert(material);
material = new t_materialupload
{
sn = PlcData.Write_stSN,
imageUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd"),
outtime = DateTime.Now
};
materialuploadHelper.Insert(material);
}
else
{
material.imageUploaded = 1;
materialuploadHelper.Update(material);
}
}
else
//视频上传 WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel
if ("WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel".Contains(stationid))
{
material.imageUploaded = 1;
materialuploadHelper.Update(material);
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
{
material = new t_materialupload
{
sn = PlcData.Write_stSN,
vedioUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd"),
outtime = DateTime.Now
};
materialuploadHelper.Insert(material);
}
else
{
material.vedioUploaded = 1;
materialuploadHelper.Update(material);
}
}
}
//视频上传
if ("WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel".Contains(stationid))
{
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
{
material = new t_materialupload
{
sn = PlcData.Write_stSN,
vedioUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd")
};
materialuploadHelper.Insert(material);
}
else
{
material.vedioUploaded = 1;
materialuploadHelper.Update(material);
}
}
//调用OEEDataCollection
//CallFunctionByName("OEEDataCollection", PlcData, OtherData);
return CallApi(url, request, "SN_Checkout", PlcData, PLC_Status.SN_Checkout);
}
@@ -1082,6 +1137,64 @@ namespace WindowsFormsApp1.server
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
}
public ApiFormResult OEEDataCollection(string url, plcdata PlcData, otherdata OtherData)
{
var request = new
{
EventID = "OEEDataCollection",
Line = _line,
StationID = _stationID,
MachineID = _machineID,
OPID = _opID,
SN = PlcData.Write_stSN,
CarrierID = PlcData.Read_MaterialCode1,
DC_INFO = new List<DataDCInfoItem>(),
CompList = new List<CompListItem>(),
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
};
// 工位最长ct
request.DC_INFO.Add(new DataDCInfoItem()
{
Item = "Cycle_Time",
Value = OtherData.Oeeaddresses.FirstOrDefault(x => x.code == "uiMAXCT")?.value //跟PLC定义好值从哪里获取
});
// 机台ct
request.DC_INFO.Add(new DataDCInfoItem()
{
Item = "Takt_Time",
Value = OtherData.Oeeaddresses.FirstOrDefault(x => x.code == "uiNEWCT")?.value //跟PLC定义好值从哪里获取
});
var tossing = DataListManager.DataList.Any(x => x.Name == _stationID);
if (tossing)
{
var materialList = DataListManager.DataList.First(x => x.Name == _stationID).Components;
var num = 0;
foreach (var material in materialList)
{
request.DC_INFO.Add(
new DataDCInfoItem()
{
Item = $"Toss_Count_{material}",
Value = OtherData.Oeeaddresses.FirstOrDefault(x => x.code == $"uiUnloadingNG[{num}]")?.value //跟PLC定义好值从哪里获取
}
);
request.DC_INFO.Add(
new DataDCInfoItem()
{
Item = $"TossRate_{material}",
Value = OtherData.Oeeaddresses.FirstOrDefault(x => x.code == $"uiUnloadingNGX[{num}]")?.value //跟PLC定义好值从哪里获取
}
);
num++;
}
}
return CallApi(url, request, "OEEDataCollection", PlcData, 0);
}
#region 暂时不用
public ApiFormResult Test(string url, plcdata PlcData, otherdata OtherData)
{
@@ -1098,68 +1211,6 @@ namespace WindowsFormsApp1.server
return CallApi(url, request, "Test", PlcData, PLC_Status.Test);
}
public ApiFormResult OEEDataCollection(string url, plcdata PlcData, otherdata OtherData)
{
//模穴 真空站两个穴位
var model = 1;
if (_stationID.ToLower() == "vacuum")
{
model = OtherData.plcid;
}
var request = new
{
EventID = "OEEDataCollection",
Line = _line,
StationID = _stationID,
MachineID = _machineID,
OPID = _opID,
SN = PlcData.Write_stSN,
CarrierID = PlcData.Read_MaterialCode1,
DC_INFO = new List<DataDCInfoItem>(),
CompList = new List<CompListItem>(),
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
};
request.DC_INFO.Add(new DataDCInfoItem()
{
Item = "Eq_Active_Rate",
Value = "0"
});
// 工位最长ct
request.DC_INFO.Add(new DataDCInfoItem()
{
Item = "Cycle_Time",
Value = "0" //跟PLC定义好值从哪里获取
});
// 机台ct
request.DC_INFO.Add(new DataDCInfoItem()
{
Item = "Takt_Time",
Value = "0" //跟PLC定义好值从哪里获取
});
var tossing = DataListManager.DataList.Any(x => x.Name == _stationID);
if (tossing)
{
var materialList = DataListManager.DataList.First(x => x.Name == _stationID).Components;
foreach(var material in materialList)
{
request.DC_INFO.Add(
new DataDCInfoItem()
{
Item = $"Tossing_{material}",
Value = "1" //跟PLC定义好值从哪里获取
}
);
}
}
return CallApi(url, request, "OEEDataCollection", PlcData, PLC_Status.OEEDataCollection);
}
public ApiFormResult Get_Para(string url, plcdata PlcData, otherdata OtherData)
{
var request = new
@@ -1233,7 +1284,7 @@ namespace WindowsFormsApp1.server
try
{
// 打印调用开始日志
LogExecute.logNet.WriteDebug($"开始调用API: {functionName}...");
//LogExecute.logNet.WriteDebug($"开始调用API: {functionName}...");
// 检查API URL是否存在
if (!apiUrlDict.ContainsKey(functionName))
@@ -1245,13 +1296,13 @@ namespace WindowsFormsApp1.server
// 使用同步方法调用API,并结合重试策略
var result = retryPolicy.Execute(() =>
{
LogExecute.logNet.WriteDebug($"正在尝试调用API: {functionName}...");
//LogExecute.logNet.WriteDebug($"正在尝试调用API: {functionName}...");
// 调用该方法
return (ApiFormResult)methodInfo.Invoke(this, new object[] { apiUrlDict[functionName], plcdata, otherdata });
});
// 打印调用结束日志
LogExecute.logNet.WriteDebug($"API调用成功: {functionName}");
//LogExecute.logNet.WriteDebug($"API调用成功: {functionName}");
return result;
}
catch (Exception ex)
@@ -1262,6 +1313,7 @@ namespace WindowsFormsApp1.server
}
}
#region 辅助实体类
/// <summary>
/// checkout dcinfo item
/// </summary>
@@ -1333,10 +1385,10 @@ namespace WindowsFormsApp1.server
};
}
#endregion
#region checkout class
// 根对象类
public class CheckOutObject
// 根对象类
public class CheckOutObject
{
public List<SNInfoItem> SNInfo { get; set; }
public string Qty { get; set; }
@@ -1429,7 +1481,9 @@ namespace WindowsFormsApp1.server
public double angle { get; set; }
}
#endregion 马头扭力角度数据 类
#endregion 辅助实体类
// 文件copy方法
public bool CopyFileToDirectory(string sourceFilePath, string targetDirectory, string fileName)
{
@@ -1444,7 +1498,11 @@ namespace WindowsFormsApp1.server
{
Directory.CreateDirectory(targetDirectory);
}
// 判断是否重复上传
if (Directory.GetFiles(targetDirectory).Any(x => x.Contains(fileName)))
{
return true;
}
string targetPath = Path.Combine(targetDirectory, fileName);
try
+1 -1
View File
@@ -13,7 +13,7 @@ namespace WindowsFormsApp1.server
public static ILogNet PlclogNet = new LogNetDateTime("C:\\Log\\PlcLogs", GenerateMode.ByEveryDay);
public static ILogNet ApilogNet = new LogNetDateTime("C:\\Log\\Apilogs", GenerateMode.ByEveryHour);
public static ILogNet SNlogNet = new LogNetDateTime("C:\\Log\\SNlogs", GenerateMode.ByEveryDay);
public static ILogNet OEElogNet = new LogNetDateTime("C:\\Log\\Apilogs", GenerateMode.ByEveryDay);
public static ILogNet OEElogNet = new LogNetDateTime("C:\\Log\\OEElogs", GenerateMode.ByEveryDay);
public static HslCommunication.BasicFramework.SoftNumericalOrder softNumericalOrder = new HslCommunication.BasicFramework.SoftNumericalOrder("", "yyyyMMdd", 4, @"\numericalOrder.txt");
+172 -6
View File
@@ -244,7 +244,7 @@ namespace WindowsFormsApp1.server
case "byte":
address[i].value = ByteTransform.TransByte(read.Content, index).ToString();
break;
case "real":
address[i].value = ByteTransform.TransSingle(read.Content, index).ToString();
break;
@@ -280,6 +280,10 @@ namespace WindowsFormsApp1.server
.ToArray());
break;
case "dtl":
address[i].value = GetDTLTime(read.Content, index).ToString();
break;
default:
return BllResult.Error("找不到未知的数据类型");
}
@@ -359,6 +363,12 @@ namespace WindowsFormsApp1.server
stringBytes.CopyTo(writebyte, index);
break;
case "dtl":
DateTime totime = Convert.ToDateTime(value);
byte[] totime_byte = GetBytesFromDTLTime(totime);
totime_byte.CopyTo(writebyte, index);
break;
default:
return BllResult.Error("找不到未知的数据类型");
}
@@ -477,7 +487,7 @@ namespace WindowsFormsApp1.server
#endregion
#region 读取角度
public BllResult<List<float>> ReadAddress(List<t_angleaddress> address)
public BllResult<List<dynamic>> ReadAddress(List<t_angleaddress> address)
{
var ulist = address.GroupBy(a => a.dbaddress).ToList();
foreach (var u in ulist)
@@ -485,15 +495,18 @@ namespace WindowsFormsApp1.server
var readresult = ReadOneDB(u.ToList());
if (!readresult.Success)
{
return BllResult<List<float>>.Error(readresult.Msg);
return BllResult<List<dynamic>>.Error(readresult.Msg);
}
}
List<float> list = new List<float>();
List<dynamic> list = new List<dynamic>();
foreach (var add in address.OrderBy(a => a.addressoffset))
{
list.Add(float.Parse(add.value));
if(add.addresstype == "real")
list.Add(float.Parse(add.value));
else
list.Add(short.Parse(add.value));
}
return BllResult<List<float>>.Sucess(list, "成功");
return BllResult<List<dynamic>>.Sucess(list, "成功");
}
private BllResult ReadOneDB(List<t_angleaddress> address)
{
@@ -685,5 +698,158 @@ namespace WindowsFormsApp1.server
}
}
#endregion
#region 读取报警
private BllResult ReadOneDB(List<t_oeeaddress> address)
{
address = address.OrderBy(a => a.dbaddress)
.ThenBy(x => x.addressoffset)
.ToList();
OperateResult<byte[]> read;
if (address.Count == 1)
{
string startaddress = address[0].dbaddress + "." + address[0].addressoffset.ToString();
read = siemensS7Net.Read(startaddress, (ushort)address[0].addressdecimal);
}
else
{
double admax = address.Select(a => a.addressoffset).Max();
double admin = address.Select(a => a.addressoffset).Min();
ushort length = (ushort)(Math.Floor(admax - admin) + address.Last().addresstypelegth);
string startaddress = address[0].dbaddress + "." + admin.ToString();
read = siemensS7Net.Read(startaddress, length);
}
if (read.IsSuccess)
{
if (TransforWCSDataToAddressData(address, read).Success)
{
return BllResult.Sucess(address, "成功");
}
else
{
return BllResult.Sucess(address, "成功");
}
}
else
{
return BllResult.Error(read.Message);
}
}
public BllResult<List<t_oeeaddress>> ReadAddress(List<t_oeeaddress> address)
{
List<List<t_oeeaddress>> i_Device_s = new List<List<t_oeeaddress>>();
var ulist = address.GroupBy(a => a.dbaddress).ToList();
foreach (var u in ulist)
{
var readresult = ReadOneDB(u.ToList());
if (!readresult.Success)
{
return BllResult<List<t_oeeaddress>>.Error(readresult.Msg);
}
}
List<t_oeeaddress> list = new List<t_oeeaddress>();
foreach (var add in address.OrderBy(a => a.addressoffset))
{
list.Add(new t_oeeaddress {code = add.code, value = add.value});
}
return BllResult<List<t_oeeaddress>>.Sucess(list, "成功");
}
public BllResult TransforWCSDataToAddressData(List<t_oeeaddress> address, OperateResult<byte[]> read)
{
try
{
//按偏移量排序
address = address.OrderBy(a => a.dbaddress)
.ThenBy(x => x.addressoffset).ToList();
int startindex = address[0].addressoffset;
for (int i = 0; i < address.Count; i++)
{
int index = address[i].addressoffset - startindex;
switch (address[i].addresstype)
{
case "BYTE":
address[i].value = ByteTransform.TransByte(read.Content, index).ToString();
break;
case "real":
address[i].value = ByteTransform.TransSingle(read.Content, index).ToString();
break;
case "uint":
address[i].value = ByteTransform.TransInt16(read.Content, index).ToString();
break;
case "LWORD":
address[i].value = Convert.ToString(ByteTransform.TransInt64(read.Content, index), 16); ;
break;
case "bool":
address[i].value = ByteTransform.TransBool(read.Content, index, 1)[address[i].addressdecimal].ToString();
break;
case "INT":
address[i].value = ByteTransform.TransInt16(read.Content, index).ToString();
break;
case "DINT":
address[i].value = Convert.ToString(ByteTransform.TransInt32(read.Content, index), 10);
break;
case "CHAR":
address[i].value = Encoding.ASCII.GetString(read.Content, index, 20).Replace(" ", "").Replace("\0", "").Replace("\u0003", "");
break;
default:
return BllResult.Error("找不到未知的数据类型");
}
}
return BllResult.Sucess(address);
}
catch (Exception ex)
{
return BllResult.Error($"转换WCS数据失败{ex.Message}");
}
}
#endregion
#region
public byte[] GetBytesFromDTLTime(DateTime dateTime)
{
byte[] array = new byte[12];
ByteTransform.TransByte((short)dateTime.Year).CopyTo(array, 0);
array[2] = (byte)dateTime.Month;
array[3] = (byte)dateTime.Day;
array[4] = 5;
array[5] = (byte)dateTime.Hour;
array[6] = (byte)dateTime.Minute;
array[7] = (byte)dateTime.Second;
ByteTransform.TransByte(dateTime.Millisecond * 1000 * 1000).CopyTo(array, 8);
return array;
}
public DateTime GetDTLTime(byte[] buffer, int index)
{
int year = (int)ByteTransform.TransInt16(buffer, index);
int month = (int)buffer[index + 2];
int day = (int)buffer[index + 3];
int hour = (int)buffer[index + 5];
int minute = (int)buffer[index + 6];
int second = (int)buffer[index + 7];
int millisecond = ByteTransform.TransInt32(buffer, index + 8) / 1000 / 1000;
if (year == 0 && month == 0 && day == 0)
{
year = 1900;
month = 1;
day = 1;
}
return new DateTime(year, month, day, hour, minute, second, millisecond);
}
#endregion
}
}
+9 -3
View File
@@ -7,10 +7,16 @@ using System.Threading.Tasks;
namespace WindowsFormsApp1.server
{
public class ThreadHelp
public class ThreadHelp :IDisposable
{
public Thread Thread { get; set; }
public bool isrunning1 = false;
public CancellationTokenSource cancellationTokenSource1;
public bool isrunning1 {get;set;}= false;
public CancellationTokenSource cancellationTokenSource1{get;set;}
public void Dispose()
{
cancellationTokenSource1?.Cancel();
cancellationTokenSource1?.Dispose();
Thread = null;
}
}
}