yangjingzhao123 9 years ago
parent
commit
7a594d9194
  1. BIN
      Document/design.wmv
  2. BIN
      Document/tagset.wmv
  3. BIN
      Document/部署流程.doc
  4. BIN
      SCADA/Example/ClientDriver.dll
  5. BIN
      SCADA/Example/DataHelper.dll
  6. BIN
      SCADA/Example/DataService.dll
  7. BIN
      SCADA/Example/TagConfig.exe
  8. 14
      SCADA/Program/DataService/ExtensionMethods.cs
  9. 4
      SCADA/Program/DataService/PLCGroup.cs
  10. 2
      SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs
  11. 14
      SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs
  12. 119
      SCADA/Program/TagConfig/TagConfig/Form1.cs
  13. 2
      SCADA/Program/TagConfig/TagConfig/Form1.resx
  14. BIN
      SCADA/dll/DataService.dll
  15. BIN
      SCADA/dll/SiemensPLCDriver.dll

BIN
Document/design.wmv

Binary file not shown.

BIN
Document/tagset.wmv

Binary file not shown.

BIN
Document/部署流程.doc

Binary file not shown.

BIN
SCADA/Example/ClientDriver.dll

Binary file not shown.

BIN
SCADA/Example/DataHelper.dll

Binary file not shown.

BIN
SCADA/Example/DataService.dll

Binary file not shown.

BIN
SCADA/Example/TagConfig.exe

Binary file not shown.

14
SCADA/Program/DataService/ExtensionMethods.cs

@ -1,9 +1,7 @@
using System; using System;
using System.Text;
using System.Net;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Net;
using System.Data.SqlClient; using System.Text;
namespace DataService namespace DataService
{ {
@ -771,10 +769,12 @@ namespace DataService
public static unsafe short NetToInt16(byte[] value, int startIndex) 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(); throw new NotImplementedException();
} }
if (startIndex > value.Length - 2)
return value[value.Length - startIndex];
fixed (byte* numRef = &(value[startIndex])) fixed (byte* numRef = &(value[startIndex]))
{ {
return (short)((numRef[0] << 8) | numRef[1]); return (short)((numRef[0] << 8) | numRef[1]);
@ -783,10 +783,12 @@ namespace DataService
public static unsafe int NetToInt32(byte[] value, int startIndex) 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(); throw new NotImplementedException();
} }
if (startIndex > value.Length - 4)
return value[value.Length - startIndex];
fixed (byte* numRef = &(value[startIndex])) fixed (byte* numRef = &(value[startIndex]))
{ {
return (int)((numRef[0] << 24) | (numRef[1] << 16) | (numRef[2] << 8) | numRef[3]); return (int)((numRef[0] << 24) | (numRef[1] << 16) | (numRef[2] << 8) | numRef[3]);

4
SCADA/Program/DataService/PLCGroup.cs

@ -304,6 +304,7 @@ namespace DataService
{ {
lock (sync) lock (sync)
{ {
_changedList.Clear();
Poll(); Poll();
if (_changedList.Count > 0) if (_changedList.Count > 0)
Update(); Update();
@ -363,7 +364,7 @@ namespace DataService
ushort size = addr.DataSize; ushort size = addr.DataSize;
for (int i = 0; i < size; i++) 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); _changedList.Add(index);
break; break;
@ -417,7 +418,6 @@ namespace DataService
item.Update(item.Read(), dt, QUALITIES.QUALITY_GOOD); item.Update(item.Read(), dt, QUALITIES.QUALITY_GOOD);
} }
} }
_changedList.Clear();
} }
public void Dispose() public void Dispose()

2
SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs

@ -784,7 +784,7 @@ namespace SiemensPLCDriver
ushort size = addr.DataSize; ushort size = addr.DataSize;
for (int i = 0; i < size; i++) 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); _changedList.Add(index);
break; break;

14
SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs

@ -113,6 +113,7 @@
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.CSVToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
@ -394,9 +395,10 @@
this.tspcut, this.tspcut,
this.tsppaste, this.tsppaste,
this.ToolStripMenuItem, this.ToolStripMenuItem,
this.ToolStripMenuItem}); this.ToolStripMenuItem,
this.CSVToolStripMenuItem});
this.contextMenuStrip2.Name = "contextMenuStrip2"; 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.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip2_Opening);
this.contextMenuStrip2.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.contextMenuStrip2_ItemClicked); this.contextMenuStrip2.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.contextMenuStrip2_ItemClicked);
// //
@ -773,6 +775,13 @@
this.tspCount.Name = "tspCount"; this.tspCount.Name = "tspCount";
this.tspCount.Size = new System.Drawing.Size(0, 17); 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 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@ -888,6 +897,7 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator9; private System.Windows.Forms.ToolStripSeparator toolStripSeparator9;
private System.Windows.Forms.ToolStripButton toolStripButton5; private System.Windows.Forms.ToolStripButton toolStripButton5;
private System.Windows.Forms.ToolStripTextBox tspOffset; private System.Windows.Forms.ToolStripTextBox tspOffset;
private System.Windows.Forms.ToolStripMenuItem CSVToolStripMenuItem;
} }
} }

119
SCADA/Program/TagConfig/TagConfig/Form1.cs

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml; using System.Xml;
using Excel = Microsoft.Office.Interop.Excel; using Excel = Microsoft.Office.Interop.Excel;
@ -178,10 +179,11 @@ namespace TagConfig
start = true; start = true;
} }
private void Save() private bool Save()
{ {
//dataGridView1.CurrentCell = null; //dataGridView1.CurrentCell = null;
//bindingSource1.EndEdit(); //bindingSource1.EndEdit();
bool result = true;
TagDataReader reader = new TagDataReader(list); TagDataReader reader = new TagDataReader(list);
ConditionReader condReader = new ConditionReader(conditions); ConditionReader condReader = new ConditionReader(conditions);
SubConditionReader subReader = new SubConditionReader(subConds); 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}');", 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)); grp.ID, grp.Name, grp.DriverID, grp.UpdateRate, grp.DeadBand, grp.Active));
} }
DataHelper.Instance.ExecuteNonQuery(sql); result &= DataHelper.Instance.ExecuteNonQuery(sql) >= 0;
DataHelper.Instance.BulkCopy(reader, "Meta_Tag", "DELETE FROM Meta_Tag", SqlBulkCopyOptions.KeepIdentity); result &= DataHelper.Instance.BulkCopy(reader, "Meta_Tag", "DELETE FROM Meta_Tag", SqlBulkCopyOptions.KeepIdentity);
DataHelper.Instance.BulkCopy(condReader, "Meta_Condition", "DELETE FROM Meta_Condition", SqlBulkCopyOptions.KeepIdentity); result &= DataHelper.Instance.BulkCopy(condReader, "Meta_Condition", "DELETE FROM Meta_Condition", SqlBulkCopyOptions.KeepIdentity);
DataHelper.Instance.BulkCopy(subReader, "Meta_SubCondition", "DELETE FROM Meta_SubCondition", SqlBulkCopyOptions.KeepIdentity); result &= 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.BulkCopy(scalereader, "Meta_Scale", "DELETE FROM Meta_Scale", SqlBulkCopyOptions.KeepIdentity);
return result;
} }
private void LoadFromXml(string file) 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(); if (Clipboard.ContainsText(TextDataFormat.Text))
Workbook book = app.Workbooks.Open(file);
Worksheet sheet = (Worksheet)book.Sheets[1];
list.Clear();
for (int i = 2; i < sheet.Rows.Count; i++)
{ {
if (((Range)sheet.Cells[i, 1]).Value2 == null) string data = Clipboard.GetText(TextDataFormat.Text);
break; if (string.IsNullOrEmpty(data)) return;
try list.Clear();
{ using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
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)
{ {
continue; using (var mysr = new StreamReader(stream))
//Program.AddErrorLog(e); {
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) private void LoadFromExcel(string file)
@ -644,7 +657,7 @@ namespace TagConfig
public void AddNode() public void AddNode()
{ {
TreeNode node = treeView1.SelectedNode; TreeNode node = treeView1.SelectedNode;
if (node != null && node.Level != 2) if (node != null)
{ {
short did = 0;// short.MinValue; short did = 0;// short.MinValue;
if (node.Level == 0) if (node.Level == 0)
@ -658,7 +671,7 @@ namespace TagConfig
did++; did++;
devices.Add(new Driver { ID = did }); devices.Add(new Driver { ID = did });
} }
else else if (node.Level == 1)
{ {
for (int i = 0; i < groups.Count; i++) for (int i = 0; i < groups.Count; i++)
{ {
@ -668,7 +681,12 @@ namespace TagConfig
} }
did++; did++;
groups.Add(new Group { ID = did, DriverID = short.Parse(node.Name) }); 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); TreeNode nwNode = node.Nodes.Add(did.ToString(), "", node.Level + 1, node.Level + 1);
treeView1.SelectedNode = nwNode; treeView1.SelectedNode = nwNode;
treeView1.LabelEdit = true; 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) private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{ {
switch (e.ClickedItem.Text) switch (e.ClickedItem.Text)
@ -809,12 +837,7 @@ namespace TagConfig
case "增加": case "增加":
if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2) 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); AddTag();
bindingSource1.Add(tag);
int index = list.BinarySearch(tag);
if (index < 0) index = ~index;
list.Insert(index, tag);
dataGridView1.FirstDisplayedScrollingRowIndex = bindingSource1.Count - 1;
} }
break; break;
case "删除": case "删除":
@ -825,11 +848,15 @@ namespace TagConfig
} }
break; break;
case "清除": case "清除":
bindingSource1.Clear(); if (MessageBox.Show("将清除所有的标签,是否确定?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
list.Clear(); {
bindingSource1.Clear();
list.Clear();
}
break; break;
case "保存": case "保存":
Save(); if(Save())
MessageBox.Show("保存成功!");
break; break;
case "注册": case "注册":
@ -914,7 +941,7 @@ namespace TagConfig
} }
break; break;
case "导入变量": 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"; openFileDialog1.DefaultExt = "xml";
if (openFileDialog1.ShowDialog() == DialogResult.OK) if (openFileDialog1.ShowDialog() == DialogResult.OK)
{ {
@ -925,12 +952,9 @@ namespace TagConfig
LoadFromXml(file); LoadFromXml(file);
break; break;
case 2: case 2:
LoadFromCsv(file);
break;
case 3:
LoadFromExcel(file); LoadFromExcel(file);
break; break;
case 4: case 3:
LoadFromKepserverCSV(file); LoadFromKepserverCSV(file);
break; break;
} }
@ -1170,6 +1194,9 @@ namespace TagConfig
isCut = true; isCut = true;
} }
break; break;
case "粘贴CSV":
LoadFromCsv();
break;
case "粘帖": case "粘帖":
{ {
if (treeView1.SelectedNode == null || treeView1.SelectedNode.Level != 2) if (treeView1.SelectedNode == null || treeView1.SelectedNode.Level != 2)

2
SCADA/Program/TagConfig/TagConfig/Form1.resx

@ -128,7 +128,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAC6 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAC6
CAAAAk1TRnQBSQFMAgEBAwEAARABAgEQAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo CAAAAk1TRnQBSQFMAgEBAwEAARgBAgEYAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

BIN
SCADA/dll/DataService.dll

Binary file not shown.

BIN
SCADA/dll/SiemensPLCDriver.dll

Binary file not shown.
Loading…
Cancel
Save