Skip to content

Commit

Permalink
add SiemensServer
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaopeiym committed Oct 18, 2019
1 parent 938aa41 commit a1bf132
Show file tree
Hide file tree
Showing 11 changed files with 596 additions and 293 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -270,3 +270,5 @@ __pycache__/
/IoTClient.Tests/appsettings.json
/IoTClient/自增版本号打包.ps1
/IoTClient/version.props
/IoTServer/version.props
/IoTServer/自增版本号打包.ps1
1 change: 1 addition & 0 deletions IoTClient.Demo/SiemensForm.Designer.cs

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

28 changes: 20 additions & 8 deletions IoTClient.Demo/SiemensForm.cs
@@ -1,30 +1,26 @@
using IoTClient.Clients.PLC;
using IoTClient.Common.Enums;
using IoTServer.Servers.PLC;
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;

namespace IoTClient.Demo
{
public partial class SiemensForm : Form
{
SiemensClient client;
SiemensServer server;
public SiemensForm()
{
InitializeComponent();
but_read.Enabled = false;
but_write.Enabled = false;
rd_bit.Enabled = false;
}

private void SiemensForm_Load(object sender, EventArgs e)
{
but_server.Enabled = false;
//but_server.Enabled = false;
}

private void but_open_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -113,6 +109,7 @@ private void button3_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
//client?.Close();
MessageBox.Show(ex.Message);
}
}
Expand Down Expand Up @@ -203,5 +200,20 @@ private void button4_Click(object sender, EventArgs e)
MessageBox.Show(ex.Message);
}
}

private void but_server_Click(object sender, EventArgs e)
{
if (but_server.Text == "本地模拟服务")
{
but_server.Text = "已开启服务";
server = new SiemensServer(txt_ip.Text?.Trim(), int.Parse(txt_port.Text.Trim()));
server.Start();
}
else
{
but_server.Text = "本地模拟服务";
server?.Close();
}
}
}
}
22 changes: 22 additions & 0 deletions IoTClient.Tests/TempTest/temp.cs
@@ -0,0 +1,22 @@
using IoTClient.Common.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;

namespace IoTClient.Tests.TempTest
{
public class temp
{
[Fact]
public void test()
{
var str = "03 00 00 1D 02 F0 80 32 03 00 00 00 01 00 02 00 1F 00 00 04 01 FF 04 00 04 00 00 00 00";
//var b = str.Split(" ").Select(t => Convert.ToByte(t, 16)).ToArray();

var aa = DataConvert.StringToByteArray(str);
var bb = DataConvert.ByteArrayToString(aa);
}
}
}
31 changes: 31 additions & 0 deletions IoTClient/Common/Helpers/DataConvert.cs
@@ -0,0 +1,31 @@
using System;
using System.Linq;

namespace IoTClient.Common.Helpers
{
/// <summary>
/// 数据转换
/// </summary>
public static class DataConvert
{
/// <summary>
/// 字节数组转16进制字符
/// </summary>
/// <param name="byteArray"></param>
/// <returns></returns>
public static string ByteArrayToString(byte[] byteArray)
{
return string.Join(" ", byteArray.Select(t => t.ToString("X2")));
}

/// <summary>
/// 16进制字符串转字节数组
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static byte[] StringToByteArray(string str)
{
return str.Split(' ').Where(t => t?.Length == 2).Select(t => Convert.ToByte(t, 16)).ToArray();
}
}
}

0 comments on commit a1bf132

Please sign in to comment.