Dreamine.PLC.Mitsubishi.MC 1.0.1
Dreamine.PLC.Mitsubishi.MC 산업 자동화 및 I/O 기능을 제공합니다.
로딩중...
검색중...
일치하는것 없음
Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer 클래스 참조sealed

더 자세히 ...

Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer에 대한 상속 다이어그램 :
Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer에 대한 협력 다이어그램:

Public 멤버 함수

 MitsubishiMcTcpSimulatorServer (MitsubishiMcSimulatorServerOptions options)
 MitsubishiMcTcpSimulatorServer (MitsubishiMcSimulatorServerOptions options, InMemoryPlcMemory memory)
Task StartAsync (CancellationToken cancellationToken=default)
async Task StopAsync ()
async ValueTask DisposeAsync ()

속성

bool IsRunning [get]

이벤트

EventHandler< string >? StatusChanged

Private 멤버 함수

async Task AcceptLoopAsync (CancellationToken cancellationToken)
async Task HandleClientAsync (TcpClient client, CancellationToken cancellationToken)
void OnProtocolStatusChanged (object? sender, string e)

정적 Private 멤버 함수

static async Task< byte[]> ReceiveBinary3EFrameAsync (NetworkStream stream, CancellationToken cancellationToken)
static async Task ReadExactlyAsync (NetworkStream stream, byte[] buffer, CancellationToken cancellationToken)
static IPAddress ParseAddress (string host)

Private 속성

readonly MitsubishiMcSimulatorServerOptions _options
readonly MitsubishiMcBinary3ESimulatorProtocol _protocol
readonly List< Task > _clientTasks = []
readonly object _syncRoot = new()
CancellationTokenSource? _cts
TcpListener? _listener
Task? _acceptTask

상세한 설명

로컬 및 PC 간 테스트용 최소 Mitsubishi MC Binary 3E TCP 서버를 제공합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 15 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ MitsubishiMcTcpSimulatorServer() [1/2]

Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.MitsubishiMcTcpSimulatorServer ( MitsubishiMcSimulatorServerOptions options)
inline

새 메모리와 지정한 옵션으로 TCP 서버를 초기화합니다.

매개변수
options시뮬레이터 옵션입니다.
예외
ArgumentNullException옵션이 null인 경우 발생합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 104 번째 라인에서 정의되었습니다.

105 : this(options, new InMemoryPlcMemory())
106 {
107 }

◆ MitsubishiMcTcpSimulatorServer() [2/2]

Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.MitsubishiMcTcpSimulatorServer ( MitsubishiMcSimulatorServerOptions options,
InMemoryPlcMemory memory )
inline

공유 메모리와 옵션으로 TCP 서버를 초기화합니다.

매개변수
options옵션입니다.
memory공유 메모리입니다.
예외
ArgumentNullException옵션 또는 메모리가 null인 경우 발생합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 139 번째 라인에서 정의되었습니다.

140 {
141 _options = options ?? throw new ArgumentNullException(nameof(options));
142 _protocol = new MitsubishiMcBinary3ESimulatorProtocol(memory ?? throw new ArgumentNullException(nameof(memory)), options);
143 _protocol.StatusChanged += OnProtocolStatusChanged;
144 }

다음을 참조함 : _options, _protocol, OnProtocolStatusChanged().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 함수 문서화

◆ AcceptLoopAsync()

async Task Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.AcceptLoopAsync ( CancellationToken cancellationToken)
inlineprivate

TCP 클라이언트를 수락하고 처리 작업을 추적합니다.

매개변수
cancellationToken취소 토큰입니다.
반환값
수락 루프입니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 309 번째 라인에서 정의되었습니다.

310 {
311 while (!cancellationToken.IsCancellationRequested && _listener is not null)
312 {
313 TcpClient client;
314
315 try
316 {
317 client = await _listener.AcceptTcpClientAsync(cancellationToken).ConfigureAwait(false);
318 }
319 catch (OperationCanceledException)
320 {
321 break;
322 }
323 catch (ObjectDisposedException)
324 {
325 break;
326 }
327
328 var task = Task.Run(() => HandleClientAsync(client, cancellationToken), CancellationToken.None);
329 lock (_syncRoot)
330 {
331 _clientTasks.RemoveAll(static item => item.IsCompleted);
332 _clientTasks.Add(task);
333 }
334 }
335 }

다음을 참조함 : _clientTasks, _listener, _syncRoot, HandleClientAsync().

다음에 의해서 참조됨 : StartAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ DisposeAsync()

async ValueTask Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.DisposeAsync ( )
inline

프로토콜 이벤트 구독을 해제하고 서버를 중지합니다.

반환값
비동기 해제 작업입니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 281 번째 라인에서 정의되었습니다.

282 {
283 _protocol.StatusChanged -= OnProtocolStatusChanged;
284 await StopAsync().ConfigureAwait(false);
285 }

다음을 참조함 : OnProtocolStatusChanged(), StopAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ HandleClientAsync()

async Task Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.HandleClientAsync ( TcpClient client,
CancellationToken cancellationToken )
inlineprivate

한 클라이언트의 Binary 3E 프레임을 반복 처리합니다.

매개변수
client클라이언트입니다.
cancellationToken취소 토큰입니다.
반환값
처리 작업입니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 366 번째 라인에서 정의되었습니다.

367 {
368 using (client)
369 using (var stream = client.GetStream())
370 {
371 StatusChanged?.Invoke(this, "MC TCP simulator client connected.");
372
373 while (!cancellationToken.IsCancellationRequested)
374 {
375 byte[] request;
376 try
377 {
378 request = await ReceiveBinary3EFrameAsync(stream, cancellationToken).ConfigureAwait(false);
379 }
380 catch (OperationCanceledException)
381 {
382 break;
383 }
384 catch (IOException)
385 {
386 break;
387 }
388 catch (ObjectDisposedException)
389 {
390 break;
391 }
392
393 var response = _protocol.Execute(request);
394 await stream.WriteAsync(response, cancellationToken).ConfigureAwait(false);
395 await stream.FlushAsync(cancellationToken).ConfigureAwait(false);
396 }
397 }
398
399 StatusChanged?.Invoke(this, "MC TCP simulator client disconnected.");
400 }

다음을 참조함 : _protocol, ReceiveBinary3EFrameAsync(), StatusChanged.

다음에 의해서 참조됨 : AcceptLoopAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ OnProtocolStatusChanged()

void Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.OnProtocolStatusChanged ( object? sender,
string e )
inlineprivate

프로토콜 상태 메시지를 서버 이벤트로 전달합니다.

매개변수
sender이벤트 원본입니다.
e상태 메시지입니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 577 번째 라인에서 정의되었습니다.

578 {
579 StatusChanged?.Invoke(this, e);
580 }

다음을 참조함 : StatusChanged.

다음에 의해서 참조됨 : DisposeAsync(), MitsubishiMcTcpSimulatorServer().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ParseAddress()

IPAddress Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.ParseAddress ( string host)
inlinestaticprivate

바인딩 호스트를 IP 주소로 변환하며 잘못되면 Any를 사용합니다.

매개변수
host호스트입니다.
반환값
IP 주소입니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 545 번째 라인에서 정의되었습니다.

546 {
547 if (string.IsNullOrWhiteSpace(host) || host == "*" || host == "+")
548 {
549 return IPAddress.Any;
550 }
551
552 return IPAddress.TryParse(host, out var address) ? address : IPAddress.Any;
553 }

다음에 의해서 참조됨 : StartAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ReadExactlyAsync()

async Task Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.ReadExactlyAsync ( NetworkStream stream,
byte[] buffer,
CancellationToken cancellationToken )
inlinestaticprivate

대상 버퍼가 찰 때까지 스트림을 읽습니다.

매개변수
stream스트림입니다.
buffer버퍼입니다.
cancellationToken취소 토큰입니다.
반환값
읽기 작업입니다.
예외
IOException버퍼가 차기 전에 연결이 닫힌 경우 발생합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 508 번째 라인에서 정의되었습니다.

509 {
510 var offset = 0;
511 while (offset < buffer.Length)
512 {
513 var read = await stream.ReadAsync(buffer.AsMemory(offset, buffer.Length - offset), cancellationToken).ConfigureAwait(false);
514 if (read == 0)
515 {
516 throw new IOException("The MC TCP simulator client closed the connection.");
517 }
518
519 offset += read;
520 }
521 }

다음에 의해서 참조됨 : ReceiveBinary3EFrameAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ReceiveBinary3EFrameAsync()

async Task< byte[]> Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.ReceiveBinary3EFrameAsync ( NetworkStream stream,
CancellationToken cancellationToken )
inlinestaticprivate

헤더의 데이터 길이에 맞춰 완전한 Binary 3E 요청을 읽습니다.

매개변수
stream스트림입니다.
cancellationToken취소 토큰입니다.
반환값
요청 프레임입니다.
예외
InvalidOperationException데이터 길이가 잘못된 경우 발생합니다.
IOException프레임 수신 중 연결이 닫힌 경우 발생합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 445 번째 라인에서 정의되었습니다.

446 {
447 var header = new byte[9];
448 await ReadExactlyAsync(stream, header, cancellationToken).ConfigureAwait(false);
449
450 var requestDataLength = header[7] | (header[8] << 8);
451 if (requestDataLength < 2)
452 {
453 throw new InvalidOperationException($"Invalid MC request data length: {requestDataLength}");
454 }
455
456 var body = new byte[requestDataLength];
457 await ReadExactlyAsync(stream, body, cancellationToken).ConfigureAwait(false);
458
459 var frame = new byte[header.Length + body.Length];
460 Buffer.BlockCopy(header, 0, frame, 0, header.Length);
461 Buffer.BlockCopy(body, 0, frame, header.Length, body.Length);
462 return frame;
463 }

다음을 참조함 : ReadExactlyAsync().

다음에 의해서 참조됨 : HandleClientAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ StartAsync()

Task Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.StartAsync ( CancellationToken cancellationToken = default)
inline

TCP 수신기와 수락 루프를 시작합니다.

매개변수
cancellationToken서버 수명 토큰입니다.
반환값
시작 작업입니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 189 번째 라인에서 정의되었습니다.

190 {
191 if (_listener is not null)
192 {
193 return Task.CompletedTask;
194 }
195
196 var address = ParseAddress(_options.Host);
197 _listener = new TcpListener(address, _options.Port);
198 _listener.Start();
199 _cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
200 _acceptTask = Task.Run(() => AcceptLoopAsync(_cts.Token), CancellationToken.None);
201 StatusChanged?.Invoke(this, $"MC TCP simulator server started. {_options.Host}:{_options.Port}");
202 return Task.CompletedTask;
203 }

다음을 참조함 : _acceptTask, _cts, _listener, _options, AcceptLoopAsync(), ParseAddress(), StatusChanged.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ StopAsync()

async Task Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.StopAsync ( )
inline

TCP 수신기를 중지하고 클라이언트 작업 종료를 기다립니다.

반환값
중지 작업입니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 221 번째 라인에서 정의되었습니다.

222 {
223 if (_listener is null)
224 {
225 return;
226 }
227
228 _cts?.Cancel();
229 _listener.Stop();
230 _listener = null;
231
232 if (_acceptTask is not null)
233 {
234 try
235 {
236 await _acceptTask.ConfigureAwait(false);
237 }
238 catch (OperationCanceledException)
239 {
240 }
241 catch (ObjectDisposedException)
242 {
243 }
244 }
245
246 Task[] clientTasks;
247 lock (_syncRoot)
248 {
249 clientTasks = _clientTasks.ToArray();
250 _clientTasks.Clear();
251 }
252
253 try
254 {
255 await Task.WhenAll(clientTasks).ConfigureAwait(false);
256 }
257 catch
258 {
259 }
260
261 _cts?.Dispose();
262 _cts = null;
263 StatusChanged?.Invoke(this, "MC TCP simulator server stopped.");
264 }

다음을 참조함 : _acceptTask, _clientTasks, _cts, _listener, _syncRoot, StatusChanged.

다음에 의해서 참조됨 : DisposeAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ _acceptTask

Task? Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer._acceptTask
private

accept Task 값을 보관합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 79 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : StartAsync(), StopAsync().

◆ _clientTasks

readonly List<Task> Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer._clientTasks = []
private

client Tasks 값을 보관합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 43 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AcceptLoopAsync(), StopAsync().

◆ _cts

CancellationTokenSource? Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer._cts
private

cts 값을 보관합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 61 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : StartAsync(), StopAsync().

◆ _listener

TcpListener? Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer._listener
private

listener 값을 보관합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 70 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AcceptLoopAsync(), StartAsync(), StopAsync().

◆ _options

readonly MitsubishiMcSimulatorServerOptions Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer._options
private

options 값을 보관합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 25 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : MitsubishiMcTcpSimulatorServer(), StartAsync().

◆ _protocol

readonly MitsubishiMcBinary3ESimulatorProtocol Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer._protocol
private

protocol 값을 보관합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 34 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : HandleClientAsync(), MitsubishiMcTcpSimulatorServer().

◆ _syncRoot

readonly object Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer._syncRoot = new()
private

sync Root 값을 보관합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 52 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AcceptLoopAsync(), StopAsync().

속성 문서화

◆ IsRunning

bool Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.IsRunning
get

서버 실행 여부를 가져옵니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 164 번째 라인에서 정의되었습니다.

이벤트 문서화

◆ StatusChanged

EventHandler<string>? Dreamine.PLC.Mitsubishi.MC.Simulation.MitsubishiMcTcpSimulatorServer.StatusChanged

서버 상태 메시지가 변경될 때 발생합니다.

MitsubishiMcTcpSimulatorServer.cs 파일의 154 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : HandleClientAsync(), OnProtocolStatusChanged(), StartAsync(), StopAsync().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: