diff --git a/Document/design.wmv b/Document/design.wmv new file mode 100644 index 0000000..43de5c0 Binary files /dev/null and b/Document/design.wmv differ diff --git a/Document/tagset.wmv b/Document/tagset.wmv new file mode 100644 index 0000000..aad0a54 Binary files /dev/null and b/Document/tagset.wmv differ diff --git a/Document/部署流程.doc b/Document/部署流程.doc index ff2f4c6..dd15328 100644 Binary files a/Document/部署流程.doc and b/Document/部署流程.doc differ diff --git a/SCADA/Example/ClientDriver.dll b/SCADA/Example/ClientDriver.dll index da28d6e..e83bb9b 100644 Binary files a/SCADA/Example/ClientDriver.dll and b/SCADA/Example/ClientDriver.dll differ diff --git a/SCADA/Example/DataHelper.dll b/SCADA/Example/DataHelper.dll index d1dc396..bba0fd8 100644 Binary files a/SCADA/Example/DataHelper.dll and b/SCADA/Example/DataHelper.dll differ diff --git a/SCADA/Example/DataService.dll b/SCADA/Example/DataService.dll index b916cdb..ce190f3 100644 Binary files a/SCADA/Example/DataService.dll and b/SCADA/Example/DataService.dll differ diff --git a/SCADA/Example/TagConfig.exe b/SCADA/Example/TagConfig.exe index ce7b5d1..8d818eb 100644 Binary files a/SCADA/Example/TagConfig.exe and b/SCADA/Example/TagConfig.exe differ diff --git a/SCADA/Program/DataService/ExtensionMethods.cs b/SCADA/Program/DataService/ExtensionMethods.cs index f27440d..d92cb40 100644 --- a/SCADA/Program/DataService/ExtensionMethods.cs +++ b/SCADA/Program/DataService/ExtensionMethods.cs @@ -1,9 +1,7 @@ using System; -using System.Text; -using System.Net; using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Data.SqlClient; +using System.Net; +using System.Text; namespace DataService { @@ -771,10 +769,12 @@ namespace DataService public static unsafe short NetToInt16(byte[] value, int startIndex) { - if (value == null || startIndex > value.Length - 2) + if (value == null || startIndex > value.Length) { throw new NotImplementedException(); } + if (startIndex > value.Length - 2) + return value[value.Length - startIndex]; fixed (byte* numRef = &(value[startIndex])) { return (short)((numRef[0] << 8) | numRef[1]); @@ -783,10 +783,12 @@ namespace DataService public static unsafe int NetToInt32(byte[] value, int startIndex) { - if (value == null || startIndex > value.Length - 4) + if (value == null || startIndex > value.Length) { throw new NotImplementedException(); } + if (startIndex > value.Length - 4) + return value[value.Length - startIndex]; fixed (byte* numRef = &(value[startIndex])) { return (int)((numRef[0] << 24) | (numRef[1] << 16) | (numRef[2] << 8) | numRef[3]); diff --git a/SCADA/Program/DataService/PLCGroup.cs b/SCADA/Program/DataService/PLCGroup.cs index cea6922..1f89da8 100644 --- a/SCADA/Program/DataService/PLCGroup.cs +++ b/SCADA/Program/DataService/PLCGroup.cs @@ -304,6 +304,7 @@ namespace DataService { lock (sync) { + _changedList.Clear(); Poll(); if (_changedList.Count > 0) Update(); @@ -363,7 +364,7 @@ namespace DataService ushort size = addr.DataSize; for (int i = 0; i < size; i++) { - if (rcvBytes[iByte1 + i] != cache[iByte + i]) + if (iByte1 + i < rcvBytes.Length && rcvBytes[iByte1 + i] != cache[iByte + i]) { _changedList.Add(index); break; @@ -417,7 +418,6 @@ namespace DataService item.Update(item.Read(), dt, QUALITIES.QUALITY_GOOD); } } - _changedList.Clear(); } public void Dispose() diff --git a/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs b/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs index 36e2509..482b59f 100644 --- a/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs +++ b/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs @@ -784,7 +784,7 @@ namespace SiemensPLCDriver ushort size = addr.DataSize; for (int i = 0; i < size; i++) { - if (rcvBytes[iByte1 + i] != cache[iByte + i]) + if (iByte1 + i < rcvBytes.Length && rcvBytes[iByte1 + i] != cache[iByte + i]) { _changedList.Add(index); break; diff --git a/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs b/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs index 30085a6..6fa7a2d 100644 --- a/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs +++ b/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs @@ -113,6 +113,7 @@ this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); + this.粘贴CSVToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -394,9 +395,10 @@ this.tspcut, this.tsppaste, this.批量删除ToolStripMenuItem, - this.事件归档ToolStripMenuItem}); + this.事件归档ToolStripMenuItem, + this.粘贴CSVToolStripMenuItem}); this.contextMenuStrip2.Name = "contextMenuStrip2"; - this.contextMenuStrip2.Size = new System.Drawing.Size(195, 202); + this.contextMenuStrip2.Size = new System.Drawing.Size(195, 224); this.contextMenuStrip2.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip2_Opening); this.contextMenuStrip2.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.contextMenuStrip2_ItemClicked); // @@ -773,6 +775,13 @@ this.tspCount.Name = "tspCount"; this.tspCount.Size = new System.Drawing.Size(0, 17); // + // 粘贴CSVToolStripMenuItem + // + this.粘贴CSVToolStripMenuItem.Name = "粘贴CSVToolStripMenuItem"; + this.粘贴CSVToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Y))); + this.粘贴CSVToolStripMenuItem.Size = new System.Drawing.Size(194, 22); + this.粘贴CSVToolStripMenuItem.Text = "粘贴CSV"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -888,6 +897,7 @@ private System.Windows.Forms.ToolStripSeparator toolStripSeparator9; private System.Windows.Forms.ToolStripButton toolStripButton5; private System.Windows.Forms.ToolStripTextBox tspOffset; + private System.Windows.Forms.ToolStripMenuItem 粘贴CSVToolStripMenuItem; } } diff --git a/SCADA/Program/TagConfig/TagConfig/Form1.cs b/SCADA/Program/TagConfig/TagConfig/Form1.cs index eba4376..1a73d17 100644 --- a/SCADA/Program/TagConfig/TagConfig/Form1.cs +++ b/SCADA/Program/TagConfig/TagConfig/Form1.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Data.SqlClient; using System.IO; using System.Linq; +using System.Text; using System.Windows.Forms; using System.Xml; using Excel = Microsoft.Office.Interop.Excel; @@ -178,10 +179,11 @@ namespace TagConfig start = true; } - private void Save() + private bool Save() { //dataGridView1.CurrentCell = null; //bindingSource1.EndEdit(); + bool result = true; TagDataReader reader = new TagDataReader(list); ConditionReader condReader = new ConditionReader(conditions); SubConditionReader subReader = new SubConditionReader(subConds); @@ -198,11 +200,12 @@ namespace TagConfig sql = string.Concat(sql, string.Format("INSERT INTO Meta_Group(GroupID,GroupName,DriverID,UpdateRate,DeadBand,IsActive) VALUES({0},'{1}',{2},{3},{4},'{5}');", grp.ID, grp.Name, grp.DriverID, grp.UpdateRate, grp.DeadBand, grp.Active)); } - DataHelper.Instance.ExecuteNonQuery(sql); - DataHelper.Instance.BulkCopy(reader, "Meta_Tag", "DELETE FROM Meta_Tag", SqlBulkCopyOptions.KeepIdentity); - DataHelper.Instance.BulkCopy(condReader, "Meta_Condition", "DELETE FROM Meta_Condition", SqlBulkCopyOptions.KeepIdentity); - DataHelper.Instance.BulkCopy(subReader, "Meta_SubCondition", "DELETE FROM Meta_SubCondition", SqlBulkCopyOptions.KeepIdentity); - DataHelper.Instance.BulkCopy(scalereader, "Meta_Scale", "DELETE FROM Meta_Scale", SqlBulkCopyOptions.KeepIdentity); + result &= DataHelper.Instance.ExecuteNonQuery(sql) >= 0; + result &= DataHelper.Instance.BulkCopy(reader, "Meta_Tag", "DELETE FROM Meta_Tag", SqlBulkCopyOptions.KeepIdentity); + result &= DataHelper.Instance.BulkCopy(condReader, "Meta_Condition", "DELETE FROM Meta_Condition", SqlBulkCopyOptions.KeepIdentity); + result &= DataHelper.Instance.BulkCopy(subReader, "Meta_SubCondition", "DELETE FROM Meta_SubCondition", SqlBulkCopyOptions.KeepIdentity); + result &= DataHelper.Instance.BulkCopy(scalereader, "Meta_Scale", "DELETE FROM Meta_Scale", SqlBulkCopyOptions.KeepIdentity); + return result; } private void LoadFromXml(string file) @@ -398,34 +401,44 @@ namespace TagConfig } } - private void LoadFromCsv(string file) + private void LoadFromCsv() { - Excel.Application app = new Excel.Application(); - Workbook book = app.Workbooks.Open(file); - Worksheet sheet = (Worksheet)book.Sheets[1]; - list.Clear(); - for (int i = 2; i < sheet.Rows.Count; i++) + if (Clipboard.ContainsText(TextDataFormat.Text)) { - if (((Range)sheet.Cells[i, 1]).Value2 == null) - break; - try - { - short id = Convert.ToInt16(((Range)sheet.Cells[i, 1]).Value2); - TagData tag = new TagData(id, Convert.ToInt16(((Range)sheet.Cells[i, 2]).Value2), ((Range)sheet.Cells[i, 3]).Value2.ToString(), - ((Range)sheet.Cells[i, 4]).Value2.ToString(), Convert.ToByte(((Range)sheet.Cells[i, 5]).Value2), Convert.ToUInt16(((Range)sheet.Cells[i, 6]).Value2), - Convert.ToBoolean(((Range)sheet.Cells[i, 7]).Value2), Convert.ToBoolean(((Range)sheet.Cells[i, 8]).Value2), Convert.ToBoolean(((Range)sheet.Cells[i, 9]).Value2), - Convert.ToBoolean(((Range)sheet.Cells[i, 10]).Value2), ((Range)sheet.Cells[i, 11]).Value2, ((Range)sheet.Cells[i, 12]).Value2 as string, - Convert.ToSingle(((Range)sheet.Cells[i, 13]).Value2), Convert.ToSingle(((Range)sheet.Cells[i, 14]).Value2), Convert.ToInt32(((Range)sheet.Cells[i, 15]).Value2)); - list.Add(tag); - } - catch (Exception e) + string data = Clipboard.GetText(TextDataFormat.Text); + if (string.IsNullOrEmpty(data)) return; + list.Clear(); + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data))) { - continue; - //Program.AddErrorLog(e); + using (var mysr = new StreamReader(stream)) + { + string strline = mysr.ReadLine(); + while ((strline = mysr.ReadLine()) != null) + { + string[] aryline = strline.Split('\t'); + try + { + var id = Convert.ToInt16(aryline[0]); + var groupid = Convert.ToInt16(aryline[1]); + var name = aryline[2]; + var address = aryline[3]; + var type = Convert.ToByte(aryline[4]); + var size = Convert.ToUInt16(aryline[5]); + var active = Convert.ToBoolean(aryline[6]); + var desp = aryline[7]; + TagData tag = new TagData(id, groupid, name, address, type, size, active, false, false, false, null, desp, 0, 0, 0); + list.Add(tag); + } + catch (Exception err) + { + continue; + } + } + } } + list.Sort(); + start = true; } - list.Sort(); - start = true; } private void LoadFromExcel(string file) @@ -644,7 +657,7 @@ namespace TagConfig public void AddNode() { TreeNode node = treeView1.SelectedNode; - if (node != null && node.Level != 2) + if (node != null) { short did = 0;// short.MinValue; if (node.Level == 0) @@ -658,7 +671,7 @@ namespace TagConfig did++; devices.Add(new Driver { ID = did }); } - else + else if (node.Level == 1) { for (int i = 0; i < groups.Count; i++) { @@ -668,7 +681,12 @@ namespace TagConfig } did++; groups.Add(new Group { ID = did, DriverID = short.Parse(node.Name) }); - }; + } + else if (node.Level == 2) + { + AddTag(); + return; + } TreeNode nwNode = node.Nodes.Add(did.ToString(), "", node.Level + 1, node.Level + 1); treeView1.SelectedNode = nwNode; treeView1.LabelEdit = true; @@ -802,6 +820,16 @@ namespace TagConfig } } + private void AddTag() + { + TagData tag = new TagData((short)(list.Count == 0 ? 1 : list.Max(x => x.ID) + 1), short.Parse(treeView1.SelectedNode.Name), "", "", 1, 1, true, false, false, false, null, "", 0, 0, 0); + bindingSource1.Add(tag); + int index = list.BinarySearch(tag); + if (index < 0) index = ~index; + list.Insert(index, tag); + dataGridView1.FirstDisplayedScrollingRowIndex = bindingSource1.Count - 1; + } + private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { switch (e.ClickedItem.Text) @@ -809,12 +837,7 @@ namespace TagConfig case "增加": if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2) { - TagData tag = new TagData((short)(list.Count == 0 ? 1 : list.Max(x => x.ID) + 1), short.Parse(treeView1.SelectedNode.Name), "", "", 1, 1, true, false, false, false, null, "", 0, 0, 0); - bindingSource1.Add(tag); - int index = list.BinarySearch(tag); - if (index < 0) index = ~index; - list.Insert(index, tag); - dataGridView1.FirstDisplayedScrollingRowIndex = bindingSource1.Count - 1; + AddTag(); } break; case "删除": @@ -825,11 +848,15 @@ namespace TagConfig } break; case "清除": - bindingSource1.Clear(); - list.Clear(); + if (MessageBox.Show("将清除所有的标签,是否确定?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + bindingSource1.Clear(); + list.Clear(); + } break; case "保存": - Save(); + if(Save()) + MessageBox.Show("保存成功!"); break; case "注册": @@ -914,7 +941,7 @@ namespace TagConfig } break; case "导入变量": - openFileDialog1.Filter = "xml文件 (*.xml)|*.xml|csv文件 (*.csv)|*.csv|excel文件 (*.xlsx)|*.xlsx|kepserver文件 (*.csv)|*.csv|All files (*.*)|*.*"; + openFileDialog1.Filter = "xml文件 (*.xml)|*.xml|excel文件 (*.xlsx)|*.xlsx|kepserver文件 (*.csv)|*.csv|All files (*.*)|*.*"; openFileDialog1.DefaultExt = "xml"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { @@ -925,12 +952,9 @@ namespace TagConfig LoadFromXml(file); break; case 2: - LoadFromCsv(file); - break; - case 3: LoadFromExcel(file); break; - case 4: + case 3: LoadFromKepserverCSV(file); break; } @@ -1170,6 +1194,9 @@ namespace TagConfig isCut = true; } break; + case "粘贴CSV": + LoadFromCsv(); + break; case "粘帖": { if (treeView1.SelectedNode == null || treeView1.SelectedNode.Level != 2) diff --git a/SCADA/Program/TagConfig/TagConfig/Form1.resx b/SCADA/Program/TagConfig/TagConfig/Form1.resx index b190ec7..1c985b2 100644 --- a/SCADA/Program/TagConfig/TagConfig/Form1.resx +++ b/SCADA/Program/TagConfig/TagConfig/Form1.resx @@ -128,7 +128,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAC6 - CAAAAk1TRnQBSQFMAgEBAwEAARABAgEQAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAwEAARgBAgEYAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/SCADA/dll/DataService.dll b/SCADA/dll/DataService.dll index 92229a8..9c34813 100644 Binary files a/SCADA/dll/DataService.dll and b/SCADA/dll/DataService.dll differ diff --git a/SCADA/dll/SiemensPLCDriver.dll b/SCADA/dll/SiemensPLCDriver.dll index 709ceca..632f720 100644 Binary files a/SCADA/dll/SiemensPLCDriver.dll and b/SCADA/dll/SiemensPLCDriver.dll differ