27 lines
939 B
C#
27 lines
939 B
C#
using System.IO;
|
|
using PLCSharp.VVMs.Connects.ModbusRtu;
|
|
|
|
namespace PLCSharp.Tests;
|
|
|
|
public class ModbusRtuFramingTests
|
|
{
|
|
[Theory]
|
|
[InlineData(6, "1106000100039A9B", "110600010003")]
|
|
[InlineData(16, "1110000100021298", "111000010002")]
|
|
[InlineData(6, "118602C264", "118602")]
|
|
[InlineData(3, "110304000A01024BA1", "110304000A0102")]
|
|
public void ValidResponseKeepsWireLayout(byte function, string wire, string expected)
|
|
{
|
|
using var stream = new MemoryStream(Convert.FromHexString(wire));
|
|
Assert.Equal(Convert.FromHexString(expected), ModbusRtuClient.ReadResponse(stream, function));
|
|
Assert.Equal(stream.Length, stream.Position);
|
|
}
|
|
|
|
[Fact]
|
|
public void BadWriteResponseCrcIsRejected()
|
|
{
|
|
using var stream = new MemoryStream(Convert.FromHexString("1106000100030000"));
|
|
Assert.Throws<InvalidDataException>(() => ModbusRtuClient.ReadResponse(stream, 6));
|
|
}
|
|
}
|