Dreamine.PLC.Omron.Fins
1.0.1
Dreamine.PLC.Omron.Fins 산업 자동화 및 I/O 기능을 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
OmronFinsResponseParser.cs
이 파일의 문서화 페이지로 가기
1
using
Dreamine.PLC.Abstractions.Results;
2
3
namespace
Dreamine.PLC.Omron.Fins.Protocol
;
4
13
public
sealed
class
OmronFinsResponseParser
14
{
47
public
PlcResult<byte[]>
ExtractPayload
(IReadOnlyList<byte> frame)
48
{
49
ArgumentNullException.ThrowIfNull(frame);
50
51
if
(frame.Count < 14)
52
{
53
return
PlcResult<byte[]>.Failure($
"The FINS response frame is too short. Length={frame.Count}."
);
54
}
55
56
var buffer = frame as
byte
[] ?? frame.ToArray();
57
var endCode =
OmronFinsEndian
.
ReadUInt16
(buffer, 12);
58
if
(endCode != 0)
59
{
60
return
PlcResult<byte[]>.Failure($
"FINS end code indicates failure: 0x{endCode:X4}."
, endCode);
61
}
62
63
return
PlcResult<byte[]>.Success(buffer[14..]);
64
}
65
106
public
PlcResult<bool[]>
ParseBits
(IReadOnlyList<byte> payload,
int
count)
107
{
108
ArgumentNullException.ThrowIfNull(payload);
109
110
if
(payload.Count < count)
111
{
112
return
PlcResult<bool[]>.Failure($
"The FINS bit payload is too short. Expected={count}, Actual={payload.Count}."
);
113
}
114
115
var values =
new
bool
[count];
116
for
(var index = 0; index < count; index++)
117
{
118
values[index] = payload[index] != 0;
119
}
120
121
return
PlcResult<bool[]>.Success(values);
122
}
123
172
public
PlcResult<short[]>
ParseWords
(IReadOnlyList<byte> payload,
int
count)
173
{
174
ArgumentNullException.ThrowIfNull(payload);
175
176
var expectedLength = checked(count * 2);
177
if
(payload.Count < expectedLength)
178
{
179
return
PlcResult<short[]>.Failure($
"The FINS word payload is too short. Expected={expectedLength}, Actual={payload.Count}."
);
180
}
181
182
var buffer = payload as
byte
[] ?? payload.ToArray();
183
var values =
new
short
[count];
184
for
(var index = 0; index < count; index++)
185
{
186
values[index] =
OmronFinsEndian
.
ReadInt16
(buffer, index * 2);
187
}
188
189
return
PlcResult<short[]>.Success(values);
190
}
191
}
Dreamine.PLC.Omron.Fins.Protocol
Definition
OmronFinsCommand.cs:1
Dreamine.PLC.Omron.Fins.Protocol.OmronFinsEndian
Definition
OmronFinsEndian.cs:12
Dreamine.PLC.Omron.Fins.Protocol.OmronFinsEndian.ReadInt16
static short ReadInt16(ReadOnlySpan< byte > buffer, int offset)
Definition
OmronFinsEndian.cs:98
Dreamine.PLC.Omron.Fins.Protocol.OmronFinsEndian.ReadUInt16
static ushort ReadUInt16(ReadOnlySpan< byte > buffer, int offset)
Definition
OmronFinsEndian.cs:53
Dreamine.PLC.Omron.Fins.Protocol.OmronFinsResponseParser
Definition
OmronFinsResponseParser.cs:14
Dreamine.PLC.Omron.Fins.Protocol.OmronFinsResponseParser.ExtractPayload
PlcResult< byte[]> ExtractPayload(IReadOnlyList< byte > frame)
Definition
OmronFinsResponseParser.cs:47
Dreamine.PLC.Omron.Fins.Protocol.OmronFinsResponseParser.ParseBits
PlcResult< bool[]> ParseBits(IReadOnlyList< byte > payload, int count)
Definition
OmronFinsResponseParser.cs:106
Dreamine.PLC.Omron.Fins.Protocol.OmronFinsResponseParser.ParseWords
PlcResult< short[]> ParseWords(IReadOnlyList< byte > payload, int count)
Definition
OmronFinsResponseParser.cs:172
Protocol
OmronFinsResponseParser.cs
다음에 의해 생성됨 :
1.17.0