Skip to content

Commit

Permalink
win 64
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhengzhou committed Apr 1, 2020
1 parent bdd34ae commit 19a90c3
Show file tree
Hide file tree
Showing 16 changed files with 3,016 additions and 2 deletions.
30 changes: 28 additions & 2 deletions SiemensDBSimulator.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.572
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SiemensDBSimulator", "SiemensDBSimulator\SiemensDBSimulator.csproj", "{98E773F5-8149-486F-AE88-2B1777BED20F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SiemensSimulator", "SiemensSimulator\SiemensSimulator.csproj", "{4590643F-525C-4387-8344-10C6B5E827BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{98E773F5-8149-486F-AE88-2B1777BED20F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Debug|x64.ActiveCfg = Debug|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Debug|x64.Build.0 = Debug|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Debug|x86.ActiveCfg = Debug|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Debug|x86.Build.0 = Debug|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Release|Any CPU.Build.0 = Release|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Release|x64.ActiveCfg = Release|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Release|x64.Build.0 = Release|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Release|x86.ActiveCfg = Release|Any CPU
{98E773F5-8149-486F-AE88-2B1777BED20F}.Release|x86.Build.0 = Release|Any CPU
{4590643F-525C-4387-8344-10C6B5E827BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4590643F-525C-4387-8344-10C6B5E827BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4590643F-525C-4387-8344-10C6B5E827BE}.Debug|x64.ActiveCfg = Debug|x64
{4590643F-525C-4387-8344-10C6B5E827BE}.Debug|x64.Build.0 = Debug|x64
{4590643F-525C-4387-8344-10C6B5E827BE}.Debug|x86.ActiveCfg = Debug|x86
{4590643F-525C-4387-8344-10C6B5E827BE}.Debug|x86.Build.0 = Debug|x86
{4590643F-525C-4387-8344-10C6B5E827BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4590643F-525C-4387-8344-10C6B5E827BE}.Release|Any CPU.Build.0 = Release|Any CPU
{4590643F-525C-4387-8344-10C6B5E827BE}.Release|x64.ActiveCfg = Release|x64
{4590643F-525C-4387-8344-10C6B5E827BE}.Release|x64.Build.0 = Release|x64
{4590643F-525C-4387-8344-10C6B5E827BE}.Release|x86.ActiveCfg = Release|x86
{4590643F-525C-4387-8344-10C6B5E827BE}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file modified SiemensDBSimulator/snap7.dll
Binary file not shown.
115 changes: 115 additions & 0 deletions SiemensSimulator/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

165 changes: 165 additions & 0 deletions SiemensSimulator/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using Snap7;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace SiemensSimulator
{
public partial class Form1 : Form
{
static S7Server Server;

static S7Server.TSrvCallback TheEventCallBack; // <== Static var containig the callback

delegate void AsynUpdateUI(string status);


const int size = 1024;


static byte[] buf1 = new byte[size];
static byte[] buf2 = new byte[size];
static byte[] buf3 = new byte[size];
static byte[] buf4 = new byte[size];
static byte[] buf5 = new byte[size];
static byte[] buf6 = new byte[size];
static byte[] buf7 = new byte[size];
static byte[] buf8 = new byte[size];
static byte[] buf9 = new byte[size];
static byte[] buf10 = new byte[size];

static Dictionary<byte[], int> data = new Dictionary<byte[], int>();

public Form1()
{
InitializeComponent();

data.Add(buf1, 0);
data.Add(buf2, 0);
data.Add(buf3, 0);
data.Add(buf4, 0);
data.Add(buf5, 0);
data.Add(buf6, 0);
data.Add(buf7, 0);
data.Add(buf8, 0);
data.Add(buf9, 0);
data.Add(buf10, 0);

}

private void Form1_Load(object sender, EventArgs e)
{

Server = new S7Server();

TheEventCallBack = new S7Server.TSrvCallback(EventCallback);
Server.SetEventsCallBack(TheEventCallBack, IntPtr.Zero);

int Error = Server.Start();

showMsg("Start:" + Error);

var dbs = ConfigurationManager.AppSettings["dbs"];
if (!string.IsNullOrEmpty(dbs))
{
foreach (var cmd in dbs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
Reg(cmd);
}
}

}

private void btn_add_Click(object sender, EventArgs e)
{

Reg(this.cb_num.Text);

}

private void Reg(string str)
{
var num = 0;

if (int.TryParse(str, out num))
{
if (!data.ContainsValue(num))
{
var item = data.FirstOrDefault(x => x.Value == 0);

if (item.Key == null)
{
showMsg("注册失败:超过限制数量" + data.Count);
return;
}

data[item.Key] = num;

int Error = Server.RegisterArea(S7Server.srvAreaDB, num, item.Key, item.Key.Length);

showMsg("注册" + Error + ":DB" + num + "大小" + item.Key.Length + "字节");

this.cb_num.Items.Add(num);

}
}
}

void EventCallback(IntPtr usrPtr, ref S7Server.USrvEvent Event, int Size)
{
var msg = Server.EventText(ref Event);
Log.Logger.TraceLog(msg);
}

private void bt_del_Click(object sender, EventArgs e)
{
var num = 0;

if (int.TryParse(this.cb_num.Text, out num))
{
if (data.ContainsValue(num))
{
var item = data.FirstOrDefault(x => x.Value == 0);

if (item.Key == null)
{
showMsg("DB" + num + "未注册");
return;
}

data[item.Key] = 0;

int Error = Server.UnregisterArea(S7Server.srvAreaDB, num);

showMsg("移除" + Error + ":DB" + num);

this.cb_num.Items.Remove(num);

}
}
}

void showMsg(string msg)
{
if (InvokeRequired)
{
this.Invoke(new AsynUpdateUI(delegate (string s)
{
this.tb_msg.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss") + "->" + msg + "\r\n";
}), msg);
}
else
{
this.tb_msg.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss") + "->" + msg + "\r\n";
}
}

}
}
Loading

0 comments on commit 19a90c3

Please sign in to comment.