-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
300 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using NewLife.Serialization; | ||
|
||
namespace NewLife.Siemens.Messages; | ||
|
||
/// <summary>写入变量请求</summary> | ||
/// <remarks></remarks> | ||
public class WriteRequest : S7Parameter | ||
{ | ||
#region 属性 | ||
/// <summary>请求项</summary> | ||
public IList<RequestItem> Items { get; set; } = []; | ||
|
||
/// <summary>数据项</summary> | ||
public IList<DataItem> DataItems { get; set; } = []; | ||
#endregion | ||
|
||
#region 构造 | ||
/// <summary>实例化</summary> | ||
public WriteRequest() => Code = S7Functions.WriteVar; | ||
#endregion | ||
|
||
#region 方法 | ||
/// <summary>读取</summary> | ||
/// <param name="reader"></param> | ||
protected override void OnRead(Binary reader) | ||
{ | ||
var count = reader.ReadByte(); | ||
|
||
var list = new List<RequestItem>(); | ||
for (var i = 0; i < count; i++) | ||
{ | ||
var di = new RequestItem(); | ||
di.Read(reader); | ||
|
||
list.Add(di); | ||
} | ||
Items = list.ToArray(); | ||
|
||
if (!reader.EndOfStream()) | ||
{ | ||
var list2 = new List<DataItem>(); | ||
for (var i = 0; i < count; i++) | ||
{ | ||
var di = new DataItem(); | ||
di.Read(reader); | ||
|
||
list2.Add(di); | ||
} | ||
DataItems = list2.ToArray(); | ||
} | ||
} | ||
|
||
/// <summary>写入</summary> | ||
/// <param name="writer"></param> | ||
protected override void OnWrite(Binary writer) | ||
{ | ||
var count = Items?.Count ?? 0; | ||
writer.WriteByte((Byte)count); | ||
|
||
for (var i = 0; i < count; i++) | ||
{ | ||
Items[i].Writer(writer); | ||
} | ||
|
||
for (var i = 0; i < count; i++) | ||
{ | ||
DataItems[i].Writer(writer); | ||
} | ||
} | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using NewLife.Serialization; | ||
|
||
namespace NewLife.Siemens.Messages; | ||
|
||
/// <summary>写入变量响应</summary> | ||
/// <remarks></remarks> | ||
public class WriteResponse : S7Parameter | ||
{ | ||
#region 属性 | ||
///// <summary>项个数</summary> | ||
//public Byte ItemCount { get; set; } | ||
|
||
/// <summary>数据项</summary> | ||
public IList<DataItem> Items { get; set; } = []; | ||
#endregion | ||
|
||
#region 构造 | ||
/// <summary>实例化</summary> | ||
public WriteResponse() => Code = S7Functions.WriteVar; | ||
#endregion | ||
|
||
#region 方法 | ||
/// <summary>读取</summary> | ||
/// <param name="reader"></param> | ||
protected override void OnRead(Binary reader) | ||
{ | ||
var count = reader.ReadByte(); | ||
|
||
var list = new List<DataItem>(); | ||
for (var i = 0; i < count; i++) | ||
{ | ||
var di = new DataItem(); | ||
di.Read(reader); | ||
|
||
list.Add(di); | ||
} | ||
|
||
Items = list; | ||
} | ||
|
||
/// <summary>写入</summary> | ||
/// <param name="writer"></param> | ||
protected override void OnWrite(Binary writer) | ||
{ | ||
var count = Items?.Count ?? 0; | ||
writer.WriteByte((Byte)count); | ||
|
||
for (var i = 0; i < count; i++) | ||
{ | ||
Items[i].Writer(writer); | ||
} | ||
} | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,52 @@ | ||
namespace NewLife.Siemens.Models | ||
namespace NewLife.Siemens.Models; | ||
|
||
/// <summary> | ||
/// Types of error code that can be set after a function is called | ||
/// </summary> | ||
public enum ErrorCode | ||
{ | ||
/// <summary> | ||
/// Types of error code that can be set after a function is called | ||
/// </summary> | ||
public enum ErrorCode | ||
{ | ||
/// <summary> | ||
/// The function has been executed correctly | ||
/// </summary> | ||
NoError = 0, | ||
|
||
/// <summary> | ||
/// Wrong type of CPU error | ||
/// </summary> | ||
WrongCPU_Type = 1, | ||
|
||
/// <summary> | ||
/// Connection error | ||
/// </summary> | ||
ConnectionError = 2, | ||
|
||
/// <summary> | ||
/// Ip address not available | ||
/// </summary> | ||
IPAddressNotAvailable, | ||
|
||
/// <summary> | ||
/// Wrong format of the variable | ||
/// </summary> | ||
WrongVarFormat = 10, | ||
|
||
/// <summary> | ||
/// Wrong number of received bytes | ||
/// </summary> | ||
WrongNumberReceivedBytes = 11, | ||
|
||
/// <summary> | ||
/// Error on send data | ||
/// </summary> | ||
SendData = 20, | ||
|
||
/// <summary> | ||
/// Error on read data | ||
/// </summary> | ||
ReadData = 30, | ||
|
||
/// <summary> | ||
/// Error on write data | ||
/// </summary> | ||
WriteData = 50 | ||
} | ||
/// The function has been executed correctly | ||
/// </summary> | ||
NoError = 0, | ||
|
||
/// <summary> | ||
/// Wrong type of CPU error | ||
/// </summary> | ||
WrongCPU_Type = 1, | ||
|
||
/// <summary> | ||
/// Connection error | ||
/// </summary> | ||
ConnectionError = 2, | ||
|
||
/// <summary> | ||
/// Ip address not available | ||
/// </summary> | ||
IPAddressNotAvailable, | ||
|
||
/// <summary> | ||
/// Wrong format of the variable | ||
/// </summary> | ||
WrongVarFormat = 10, | ||
|
||
/// <summary> | ||
/// Wrong number of received bytes | ||
/// </summary> | ||
WrongNumberReceivedBytes = 11, | ||
|
||
/// <summary> | ||
/// Error on send data | ||
/// </summary> | ||
SendData = 20, | ||
|
||
/// <summary> | ||
/// Error on read data | ||
/// </summary> | ||
ReadData = 30, | ||
|
||
/// <summary> | ||
/// Error on write data | ||
/// </summary> | ||
WriteData = 50 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.