Dreamine.PLC.Core
1.0.1
Dreamine.PLC.Core 산업 자동화 및 I/O 기능을 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
InMemoryPlcClient.cs
이 파일의 문서화 페이지로 가기
1
using
Dreamine.PLC.Abstractions.Devices;
2
using
Dreamine.PLC.Abstractions.Results;
3
using
Dreamine.PLC.Core.Memory
;
4
5
namespace
Dreamine.PLC.Core.Clients
;
6
15
public
sealed
class
InMemoryPlcClient
:
PlcClientBase
16
{
25
private
readonly
InMemoryPlcMemory
_memory
;
34
private
bool
_isConnected
;
35
44
public
InMemoryPlcClient
()
45
: this(new
InMemoryPlcMemory
())
46
{
47
}
48
73
public
InMemoryPlcClient
(
InMemoryPlcMemory
memory)
74
{
75
_memory
= memory ??
throw
new
ArgumentNullException(nameof(memory));
76
}
77
86
public
InMemoryPlcMemory
Memory
=>
_memory
;
87
120
protected
override
Task<PlcResult>
ConnectCoreAsync
(CancellationToken cancellationToken)
121
{
122
cancellationToken.ThrowIfCancellationRequested();
123
124
_isConnected
=
true
;
125
126
return
Task.FromResult(PlcResult.Success());
127
}
128
161
protected
override
Task<PlcResult>
DisconnectCoreAsync
(CancellationToken cancellationToken)
162
{
163
cancellationToken.ThrowIfCancellationRequested();
164
165
_isConnected
=
false
;
166
167
return
Task.FromResult(PlcResult.Success());
168
}
169
216
protected
override
Task<PlcResult<bool[]>>
ReadBitsCoreAsync
(
217
PlcAddress address,
218
int
count,
219
CancellationToken cancellationToken)
220
{
221
cancellationToken.ThrowIfCancellationRequested();
222
223
if
(!
_isConnected
)
224
{
225
return
Task.FromResult(PlcResult<
bool
[]>.Failure(
"The in-memory PLC client is not connected."
));
226
}
227
228
return
Task.FromResult(
_memory
.ReadBits(address, count));
229
}
230
277
protected
override
Task<PlcResult<short[]>>
ReadWordsCoreAsync
(
278
PlcAddress address,
279
int
count,
280
CancellationToken cancellationToken)
281
{
282
cancellationToken.ThrowIfCancellationRequested();
283
284
if
(!
_isConnected
)
285
{
286
return
Task.FromResult(PlcResult<
short
[]>.Failure(
"The in-memory PLC client is not connected."
));
287
}
288
289
return
Task.FromResult(
_memory
.ReadWords(address, count));
290
}
291
338
protected
override
Task<PlcResult>
WriteBitsCoreAsync
(
339
PlcAddress address,
340
IReadOnlyList<bool> values,
341
CancellationToken cancellationToken)
342
{
343
cancellationToken.ThrowIfCancellationRequested();
344
345
if
(!
_isConnected
)
346
{
347
return
Task.FromResult(PlcResult.Failure(
"The in-memory PLC client is not connected."
));
348
}
349
350
return
Task.FromResult(
_memory
.WriteBits(address, values));
351
}
352
399
protected
override
Task<PlcResult>
WriteWordsCoreAsync
(
400
PlcAddress address,
401
IReadOnlyList<short> values,
402
CancellationToken cancellationToken)
403
{
404
cancellationToken.ThrowIfCancellationRequested();
405
406
if
(!
_isConnected
)
407
{
408
return
Task.FromResult(PlcResult.Failure(
"The in-memory PLC client is not connected."
));
409
}
410
411
return
Task.FromResult(
_memory
.WriteWords(address, values));
412
}
413
}
Dreamine.PLC.Core.Clients
Definition
InMemoryPlcClient.cs:5
Dreamine.PLC.Core.Memory
Definition
InMemoryPlcMemory.cs:4
Dreamine.PLC.Core.Clients.InMemoryPlcClient.ReadWordsCoreAsync
override Task< PlcResult< short[]> > ReadWordsCoreAsync(PlcAddress address, int count, CancellationToken cancellationToken)
Definition
InMemoryPlcClient.cs:277
Dreamine.PLC.Core.Clients.InMemoryPlcClient.InMemoryPlcClient
InMemoryPlcClient(InMemoryPlcMemory memory)
Definition
InMemoryPlcClient.cs:73
Dreamine.PLC.Core.Clients.InMemoryPlcClient._memory
readonly InMemoryPlcMemory _memory
Definition
InMemoryPlcClient.cs:25
Dreamine.PLC.Core.Clients.InMemoryPlcClient.WriteBitsCoreAsync
override Task< PlcResult > WriteBitsCoreAsync(PlcAddress address, IReadOnlyList< bool > values, CancellationToken cancellationToken)
Definition
InMemoryPlcClient.cs:338
Dreamine.PLC.Core.Clients.InMemoryPlcClient.InMemoryPlcClient
InMemoryPlcClient()
Definition
InMemoryPlcClient.cs:44
Dreamine.PLC.Core.Clients.InMemoryPlcClient.WriteWordsCoreAsync
override Task< PlcResult > WriteWordsCoreAsync(PlcAddress address, IReadOnlyList< short > values, CancellationToken cancellationToken)
Definition
InMemoryPlcClient.cs:399
Dreamine.PLC.Core.Clients.InMemoryPlcClient.ConnectCoreAsync
override Task< PlcResult > ConnectCoreAsync(CancellationToken cancellationToken)
Definition
InMemoryPlcClient.cs:120
Dreamine.PLC.Core.Clients.InMemoryPlcClient._isConnected
bool _isConnected
Definition
InMemoryPlcClient.cs:34
Dreamine.PLC.Core.Clients.InMemoryPlcClient.DisconnectCoreAsync
override Task< PlcResult > DisconnectCoreAsync(CancellationToken cancellationToken)
Definition
InMemoryPlcClient.cs:161
Dreamine.PLC.Core.Clients.InMemoryPlcClient.ReadBitsCoreAsync
override Task< PlcResult< bool[]> > ReadBitsCoreAsync(PlcAddress address, int count, CancellationToken cancellationToken)
Definition
InMemoryPlcClient.cs:216
Dreamine.PLC.Core.Clients.InMemoryPlcClient.Memory
InMemoryPlcMemory Memory
Definition
InMemoryPlcClient.cs:86
Dreamine.PLC.Core.Clients.PlcClientBase
Definition
PlcClientBase.cs:19
Dreamine.PLC.Core.Memory.InMemoryPlcMemory
Definition
InMemoryPlcMemory.cs:15
Clients
InMemoryPlcClient.cs
다음에 의해 생성됨 :
1.17.0