Skip to content

Commit 86c4191

Browse files
committed
Update EthernetConnector
Resolve a bug in WriteBitAsync method
1 parent 113ca86 commit 86c4191

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/CimonPlc/PlcConnectors/EthernetConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public override async Task<ResponseCode> WriteWordAsync(MemoryType memoryType, s
324324
public override async Task<ResponseCode> WriteBitAsync(MemoryType memoryType, string address, params byte[] data)
325325
{
326326
Guard.Against.NullOrEmpty(data, nameof(data));
327-
Guard.Against.OutOfRange<byte>(data, nameof(data), 0, 0xFF);
327+
Guard.Against.OutOfRange<byte>(data, nameof(data), 0, 1);
328328
Guard.Against.OutOfRange(data.Length, nameof(data), 1, 256);
329329
Guard.Against.Null(memoryType, nameof(memoryType));
330330
Guard.Against.BadFormat(address, nameof(address), "[0-9a-fA-F]{1,6}");

tests/CimonPlc.UnitTests/CimonPlc/EthernetConnectorTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,21 @@ public async void WriteWordAsync_Should_Return_Error_On_Incorrect_Data(MemoryTyp
110110

111111

112112
[Theory]
113-
[InlineData(MemoryType.X, "000F0", (byte)10, (byte)100, (byte)250)]
114-
[InlineData(MemoryType.Y, "0", (byte)20, (byte)3, (byte)52, (byte)255)]
115-
[InlineData(MemoryType.D, "000F1", (byte)16, (byte)50)]
116-
[InlineData(MemoryType.M, "0F011", (byte)100, (byte)100, (byte)101, (byte)120, (byte)140)]
117-
[InlineData(MemoryType.L, "000F0", (byte)101, (byte)65, (byte)220, (byte)230)]
113+
[InlineData(MemoryType.X, "000F0", (byte)1, (byte)1, (byte)1)]
114+
[InlineData(MemoryType.Y, "0", (byte)1, (byte)1, (byte)1, (byte)1)]
115+
[InlineData(MemoryType.D, "000F1", (byte)1, (byte)1)]
116+
[InlineData(MemoryType.M, "0F011", (byte)1, (byte)1, (byte)0, (byte)1, (byte)1)]
117+
[InlineData(MemoryType.L, "000F0", (byte)1, (byte)1, (byte)1, (byte)0)]
118118
public async void WriteBitAsync_Should_Return_Value_On_Correct_Data(MemoryType memoryType, string address, params byte[] data)
119119
{
120120
var result = await _connector.WriteBitAsync(memoryType, address, data);
121121
Assert.Equal(ResponseCode.Success, result);
122122
}
123123

124124
[Theory]
125-
[InlineData(MemoryType.X, "00FF001", (byte)10, (byte)110, (byte)0, (byte)12)]
126-
[InlineData(MemoryType.D, "000x5", (byte)6)]
125+
[InlineData(MemoryType.X, "00FF001", (byte)1, (byte)1, (byte)0, (byte)1)]
126+
[InlineData(MemoryType.D, "000x5", (byte)1)]
127+
[InlineData(MemoryType.D, "000F5", (byte)2)]
127128
[InlineData(MemoryType.Y, "0")]
128129
public async void WriteBitAsync_Should_Return_Error_On_Incorrect_Data(MemoryType memoryType, string address, params byte[] data)
129130
{

0 commit comments

Comments
 (0)