Dreamine.PLC.Mitsubishi.MC
1.0.1
Dreamine.PLC.Mitsubishi.MC 산업 자동화 및 I/O 기능을 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
MitsubishiMcPlcClient.cs
이 파일의 문서화 페이지로 가기
1
using
Dreamine.PLC.Abstractions.Devices;
2
using
Dreamine.PLC.Abstractions.Results;
3
using
Dreamine.PLC.Core.Clients;
4
using
Dreamine.PLC.Mitsubishi.MC.Options
;
5
using
Dreamine.PLC.Mitsubishi.MC.Protocol
;
6
using
Dreamine.PLC.Mitsubishi.MC.Transport
;
7
8
namespace
Dreamine.PLC.Mitsubishi.MC.Clients
;
9
18
public
sealed
class
MitsubishiMcPlcClient
: PlcClientBase
19
{
28
private
readonly
MitsubishiMcConnectionOptions
_options
;
37
private
readonly
IMitsubishiMcTransport
_transport
;
46
private
readonly
MitsubishiMcBinary3EFrameBuilder
_frameBuilder
;
55
private
readonly
MitsubishiMcBinary3EResponseParser
_responseParser
;
56
87
public
MitsubishiMcPlcClient
(
MitsubishiMcConnectionOptions
options)
88
: this(
89
options,
90
CreateTransport
(options),
91
new
MitsubishiMcBinary3EFrameBuilder
(),
92
new
MitsubishiMcBinary3EResponseParser
())
93
{
94
}
95
140
public
MitsubishiMcPlcClient
(
141
MitsubishiMcConnectionOptions
options,
142
IMitsubishiMcTransport
transport,
143
MitsubishiMcBinary3EFrameBuilder
frameBuilder,
144
MitsubishiMcBinary3EResponseParser
responseParser)
145
{
146
_options
= options ??
throw
new
ArgumentNullException(nameof(options));
147
_transport
= transport ??
throw
new
ArgumentNullException(nameof(transport));
148
_frameBuilder
= frameBuilder ??
throw
new
ArgumentNullException(nameof(frameBuilder));
149
_responseParser
= responseParser ??
throw
new
ArgumentNullException(nameof(responseParser));
150
}
151
160
public
MitsubishiMcConnectionOptions
Options
=>
_options
;
161
198
private
static
IMitsubishiMcTransport
CreateTransport
(
MitsubishiMcConnectionOptions
options)
199
{
200
ArgumentNullException.ThrowIfNull(options);
201
202
return
options.TransportType
switch
203
{
204
MitsubishiMcTransportType.Tcp
=>
new
TcpMitsubishiMcTransport
(),
205
MitsubishiMcTransportType.Udp
=>
new
UdpMitsubishiMcTransport
(),
206
_ =>
throw
new
ArgumentOutOfRangeException(nameof(options), options.
TransportType
,
"Unsupported Mitsubishi MC transport type."
)
207
};
208
}
209
232
protected
override
Task<PlcResult>
ConnectCoreAsync
(CancellationToken cancellationToken)
233
{
234
return
_transport
.ConnectAsync(
235
_options
.Host,
236
_options
.Port,
237
_options
.ConnectTimeoutMs,
238
cancellationToken);
239
}
240
263
protected
override
Task<PlcResult>
DisconnectCoreAsync
(CancellationToken cancellationToken)
264
{
265
return
_transport
.DisconnectAsync(cancellationToken);
266
}
267
304
protected
override
async Task<PlcResult<bool[]>>
ReadBitsCoreAsync
(
305
PlcAddress address,
306
int
count,
307
CancellationToken cancellationToken)
308
{
309
var frameResult =
_frameBuilder
.BuildBatchReadFrame(
310
_options
,
311
address,
312
count,
313
isBitAccess:
true
);
314
315
if
(!frameResult.IsSuccess || frameResult.Value is
null
)
316
{
317
return
PlcResult<bool[]>.Failure(
318
frameResult.Message ??
"Failed to build Mitsubishi MC bit read frame."
,
319
frameResult.ErrorCode);
320
}
321
322
var responseResult = await
_transport
.SendAndReceiveAsync(
323
frameResult.Value,
324
_options
.ReceiveTimeoutMs,
325
_options
.RetryCount,
326
cancellationToken).ConfigureAwait(
false
);
327
328
if
(!responseResult.IsSuccess || responseResult.Value is
null
)
329
{
330
return
PlcResult<bool[]>.Failure(
331
responseResult.Message ??
"Failed to receive Mitsubishi MC bit read response."
,
332
responseResult.ErrorCode);
333
}
334
335
return
_responseParser
.ParseReadBits(responseResult.Value, count);
336
}
337
374
protected
override
async Task<PlcResult<short[]>>
ReadWordsCoreAsync
(
375
PlcAddress address,
376
int
count,
377
CancellationToken cancellationToken)
378
{
379
var frameResult =
_frameBuilder
.BuildBatchReadFrame(
380
_options
,
381
address,
382
count,
383
isBitAccess:
false
);
384
385
if
(!frameResult.IsSuccess || frameResult.Value is
null
)
386
{
387
return
PlcResult<short[]>.Failure(
388
frameResult.Message ??
"Failed to build Mitsubishi MC word read frame."
,
389
frameResult.ErrorCode);
390
}
391
392
var responseResult = await
_transport
.SendAndReceiveAsync(
393
frameResult.Value,
394
_options
.ReceiveTimeoutMs,
395
_options
.RetryCount,
396
cancellationToken).ConfigureAwait(
false
);
397
398
if
(!responseResult.IsSuccess || responseResult.Value is
null
)
399
{
400
return
PlcResult<short[]>.Failure(
401
responseResult.Message ??
"Failed to receive Mitsubishi MC word read response."
,
402
responseResult.ErrorCode);
403
}
404
405
return
_responseParser
.ParseReadWords(responseResult.Value, count);
406
}
407
444
protected
override
async Task<PlcResult>
WriteBitsCoreAsync
(
445
PlcAddress address,
446
IReadOnlyList<bool> values,
447
CancellationToken cancellationToken)
448
{
449
var frameResult =
_frameBuilder
.BuildBatchWriteBitsFrame(
450
_options
,
451
address,
452
values);
453
454
if
(!frameResult.IsSuccess || frameResult.Value is
null
)
455
{
456
return
PlcResult.Failure(
457
frameResult.Message ??
"Failed to build Mitsubishi MC bit write frame."
,
458
frameResult.ErrorCode);
459
}
460
461
var responseResult = await
_transport
.SendAndReceiveAsync(
462
frameResult.Value,
463
_options
.ReceiveTimeoutMs,
464
_options
.RetryCount,
465
cancellationToken).ConfigureAwait(
false
);
466
467
if
(!responseResult.IsSuccess || responseResult.Value is
null
)
468
{
469
return
PlcResult.Failure(
470
responseResult.Message ??
"Failed to receive Mitsubishi MC bit write response."
,
471
responseResult.ErrorCode);
472
}
473
474
var parseResult =
_responseParser
.Parse(responseResult.Value);
475
if
(!parseResult.IsSuccess)
476
{
477
return
PlcResult.Failure(
478
parseResult.Message ??
"Failed to parse Mitsubishi MC bit write response."
,
479
parseResult.ErrorCode);
480
}
481
482
return
PlcResult.Success();
483
}
484
521
protected
override
async Task<PlcResult>
WriteWordsCoreAsync
(
522
PlcAddress address,
523
IReadOnlyList<short> values,
524
CancellationToken cancellationToken)
525
{
526
var frameResult =
_frameBuilder
.BuildBatchWriteWordsFrame(
527
_options
,
528
address,
529
values);
530
531
if
(!frameResult.IsSuccess || frameResult.Value is
null
)
532
{
533
return
PlcResult.Failure(
534
frameResult.Message ??
"Failed to build Mitsubishi MC word write frame."
,
535
frameResult.ErrorCode);
536
}
537
538
var responseResult = await
_transport
.SendAndReceiveAsync(
539
frameResult.Value,
540
_options
.ReceiveTimeoutMs,
541
_options
.RetryCount,
542
cancellationToken).ConfigureAwait(
false
);
543
544
if
(!responseResult.IsSuccess || responseResult.Value is
null
)
545
{
546
return
PlcResult.Failure(
547
responseResult.Message ??
"Failed to receive Mitsubishi MC word write response."
,
548
responseResult.ErrorCode);
549
}
550
551
var parseResult =
_responseParser
.Parse(responseResult.Value);
552
if
(!parseResult.IsSuccess)
553
{
554
return
PlcResult.Failure(
555
parseResult.Message ??
"Failed to parse Mitsubishi MC word write response."
,
556
parseResult.ErrorCode);
557
}
558
559
return
PlcResult.Success();
560
}
561
577
public
override
async ValueTask
DisposeAsync
()
578
{
579
await base.DisposeAsync().ConfigureAwait(
false
);
580
await
_transport
.DisposeAsync().ConfigureAwait(
false
);
581
}
582
}
Dreamine.PLC.Mitsubishi.MC.Clients
Definition
MitsubishiMcPlcClient.cs:8
Dreamine.PLC.Mitsubishi.MC.Options
Definition
MitsubishiMcConnectionOptions.cs:3
Dreamine.PLC.Mitsubishi.MC.Options.MitsubishiMcTransportType.Tcp
@ Tcp
Definition
MitsubishiMcTransportType.cs:21
Dreamine.PLC.Mitsubishi.MC.Options.MitsubishiMcTransportType.Udp
@ Udp
Definition
MitsubishiMcTransportType.cs:31
Dreamine.PLC.Mitsubishi.MC.Protocol
Definition
MitsubishiMcBinary3EFrameBuilder.cs:6
Dreamine.PLC.Mitsubishi.MC.Transport
Definition
FakeMitsubishiMcTransport.cs:3
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.DisconnectCoreAsync
override Task< PlcResult > DisconnectCoreAsync(CancellationToken cancellationToken)
Definition
MitsubishiMcPlcClient.cs:263
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient._responseParser
readonly MitsubishiMcBinary3EResponseParser _responseParser
Definition
MitsubishiMcPlcClient.cs:55
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.MitsubishiMcPlcClient
MitsubishiMcPlcClient(MitsubishiMcConnectionOptions options)
Definition
MitsubishiMcPlcClient.cs:87
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.MitsubishiMcPlcClient
MitsubishiMcPlcClient(MitsubishiMcConnectionOptions options, IMitsubishiMcTransport transport, MitsubishiMcBinary3EFrameBuilder frameBuilder, MitsubishiMcBinary3EResponseParser responseParser)
Definition
MitsubishiMcPlcClient.cs:140
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.CreateTransport
static IMitsubishiMcTransport CreateTransport(MitsubishiMcConnectionOptions options)
Definition
MitsubishiMcPlcClient.cs:198
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient._transport
readonly IMitsubishiMcTransport _transport
Definition
MitsubishiMcPlcClient.cs:37
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient._options
readonly MitsubishiMcConnectionOptions _options
Definition
MitsubishiMcPlcClient.cs:28
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.ReadBitsCoreAsync
override async Task< PlcResult< bool[]> > ReadBitsCoreAsync(PlcAddress address, int count, CancellationToken cancellationToken)
Definition
MitsubishiMcPlcClient.cs:304
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient._frameBuilder
readonly MitsubishiMcBinary3EFrameBuilder _frameBuilder
Definition
MitsubishiMcPlcClient.cs:46
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.ConnectCoreAsync
override Task< PlcResult > ConnectCoreAsync(CancellationToken cancellationToken)
Definition
MitsubishiMcPlcClient.cs:232
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.ReadWordsCoreAsync
override async Task< PlcResult< short[]> > ReadWordsCoreAsync(PlcAddress address, int count, CancellationToken cancellationToken)
Definition
MitsubishiMcPlcClient.cs:374
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.WriteBitsCoreAsync
override async Task< PlcResult > WriteBitsCoreAsync(PlcAddress address, IReadOnlyList< bool > values, CancellationToken cancellationToken)
Definition
MitsubishiMcPlcClient.cs:444
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.DisposeAsync
override async ValueTask DisposeAsync()
Definition
MitsubishiMcPlcClient.cs:577
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.WriteWordsCoreAsync
override async Task< PlcResult > WriteWordsCoreAsync(PlcAddress address, IReadOnlyList< short > values, CancellationToken cancellationToken)
Definition
MitsubishiMcPlcClient.cs:521
Dreamine.PLC.Mitsubishi.MC.Clients.MitsubishiMcPlcClient.Options
MitsubishiMcConnectionOptions Options
Definition
MitsubishiMcPlcClient.cs:160
Dreamine.PLC.Mitsubishi.MC.Options.MitsubishiMcConnectionOptions
Definition
MitsubishiMcConnectionOptions.cs:14
Dreamine.PLC.Mitsubishi.MC.Options.MitsubishiMcConnectionOptions.TransportType
MitsubishiMcTransportType TransportType
Definition
MitsubishiMcConnectionOptions.cs:133
Dreamine.PLC.Mitsubishi.MC.Protocol.MitsubishiMcBinary3EFrameBuilder
Definition
MitsubishiMcBinary3EFrameBuilder.cs:17
Dreamine.PLC.Mitsubishi.MC.Protocol.MitsubishiMcBinary3EResponseParser
Definition
MitsubishiMcBinary3EResponseParser.cs:14
Dreamine.PLC.Mitsubishi.MC.Transport.IMitsubishiMcTransport
Definition
IMitsubishiMcTransport.cs:14
Dreamine.PLC.Mitsubishi.MC.Transport.TcpMitsubishiMcTransport
Definition
TcpMitsubishiMcTransport.cs:15
Dreamine.PLC.Mitsubishi.MC.Transport.UdpMitsubishiMcTransport
Definition
UdpMitsubishiMcTransport.cs:16
Clients
MitsubishiMcPlcClient.cs
다음에 의해 생성됨 :
1.17.0