Dreamine.FullKit.Tests 1.0.0.0
Dreamine.FullKit.Tests 기능을 검증하는 자동화 테스트 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
MitsubishiMcProtocolTests.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.PLC.Abstractions.Devices;
2using Dreamine.PLC.Mitsubishi.MC.Devices;
3using Dreamine.PLC.Mitsubishi.MC.Options;
4using Dreamine.PLC.Mitsubishi.MC.Protocol;
5
7
16public sealed class MitsubishiMcProtocolTests
17{
26 [Fact]
28 {
29 var mapper = new MitsubishiMcDeviceCodeMapper();
30
31 Assert.Equal(MitsubishiMcDeviceCode.D, mapper.Map(PlcDeviceType.D).Value);
32 Assert.Equal(MitsubishiMcDeviceCode.M, mapper.Map(PlcDeviceType.M).Value);
33 Assert.False(mapper.Map(PlcDeviceType.Unknown).IsSuccess);
34 }
35
44 [Fact]
46 {
47 var options = new MitsubishiMcConnectionOptions();
48 var result = new MitsubishiMcBinary3EFrameBuilder()
49 .BuildBatchReadFrame(options, new PlcAddress(PlcDeviceType.D, 100), 2, isBitAccess: false);
50
51 Assert.True(result.IsSuccess);
52 Assert.Equal(0x00, result.Value![0]);
53 Assert.Equal(0x50, result.Value[1]);
54 Assert.Contains((byte)MitsubishiMcDeviceCode.D, result.Value);
55 }
56
65 [Fact]
67 {
68 var parser = new MitsubishiMcBinary3EResponseParser();
69 var wordFrame = BuildResponse(0x00, 0x00, 0x34, 0x12, 0xFE, 0xFF);
70 var bitFrame = BuildResponse(0x00, 0x00, 0x11);
71
72 Assert.Equal(new short[] { 0x1234, -2 }, parser.ParseReadWords(wordFrame, 2).Value);
73 Assert.Equal(new[] { true, true }, parser.ParseReadBits(bitFrame, 2).Value);
74 }
75
84 [Fact]
86 {
87 var bytes = new List<byte>();
88
89 MitsubishiMcEndian.WriteUInt16LittleEndian(bytes, 0x1234);
90
91 Assert.Equal(new byte[] { 0x34, 0x12 }, bytes);
92 Assert.Throws<ArgumentOutOfRangeException>(() => MitsubishiMcEndian.WriteUInt24LittleEndian(bytes, -1));
93 }
94
119 private static byte[] BuildResponse(params byte[] data)
120 {
121 var length = data.Length;
122 return new byte[]
123 {
124 0x00, 0xD0, 0, 0, 0, 0, 0,
125 (byte)length, (byte)(length >> 8)
126 }.Concat(data).ToArray();
127 }
128}