SampleSmart 1.0.0.0
SampleSmart 사용 방법을 보여 주는 예제 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
PagePlcMonitor.xaml.Event.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.PLC.Wpf.ViewModels;
2using Dreamine.PLC.Mitsubishi.MxComponent.Options;
4
6
15public sealed class PagePlcMonitorEvent
16{
25 private readonly PlcSampleRuntime _runtime;
26
52 {
53 _runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
54 }
55
64 public PlcMonitorViewModel Monitor => _runtime.Monitor;
65
74 public string Host { get; set; } = "127.0.0.1";
75
84 public string PortText { get; set; } = "55000";
85
86
95 public string ClientModeText { get; set; } = "SimulatorTcp";
96
105 public string MxProgId { get; set; } = MitsubishiMxComponentOptions.DefaultProgId;
106
115 public string MxLogicalStationNumberText { get; set; } = "0";
116
125 public string CxProgId { get; set; } = "OMRON.Compolet.CJ2Compolet";
126
135 public string CxPeerAddress { get; set; } = "127.0.0.1";
136
137
146 public string McHost { get; set; } = "127.0.0.1";
147
156 public string McPortText { get; set; } = "5000";
157
166 public string McTransportText { get; set; } = "Tcp";
167
176 public string McRetryCountText { get; set; } = "1";
177
186 public string HandshakeStartValueText { get; set; } = "1000";
187
196 public string HandshakeIterationsText { get; set; } = "100";
197
206 public string HandshakeDelayMsText { get; set; } = "10";
207
216 public void UseInMemory()
217 {
218 _runtime.UseInMemoryClient();
219 }
220
229 public void StartServer()
230 {
231 var mode = string.IsNullOrWhiteSpace(ClientModeText) ? "SimulatorTcp" : ClientModeText.Trim();
232 if (mode.Equals("MxComponent", StringComparison.OrdinalIgnoreCase)
233 || mode.Equals("CxComponent", StringComparison.OrdinalIgnoreCase))
234 {
235 _runtime.Monitor.StatusMessage = "MxComponent/CxComponent modes use vendor runtime directly. Press Use Client, then Connect.";
236 return;
237 }
238
239 if (!TryGetPort(out var port))
240 {
241 return;
242 }
243
244 _ = _runtime.StartProtocolServerAsync(ClientModeText, Host, port);
245 }
246
255 public void StopServer()
256 {
257 _ = _runtime.StopProtocolServerAsync();
258 }
259
268 public void UseSelectedClient()
269 {
270 if (!TryGetPort(out var port))
271 {
272 return;
273 }
274
275 var mode = string.IsNullOrWhiteSpace(ClientModeText) ? "SimulatorTcp" : ClientModeText.Trim();
276 switch (mode.ToUpperInvariant())
277 {
278 case "SIMULATORTCP":
279 _runtime.UseSimulatorTcpClient(Host, port);
280 return;
281 case "MCTCP":
282 UseMitsubishiMcClient(Host, port, "Tcp");
283 return;
284 case "MCUDP":
285 UseMitsubishiMcClient(Host, port, "Udp");
286 return;
287 case "FINSTCP":
288 UseOmronFinsClient(Host, port, "Tcp");
289 return;
290 case "FINSUDP":
291 UseOmronFinsClient(Host, port, "Udp");
292 return;
293 case "MXCOMPONENT":
295 return;
296 case "CXCOMPONENT":
298 return;
299 default:
300 _runtime.Monitor.StatusMessage = "Client mode must be SimulatorTcp, McTcp, McUdp, FinsTcp, FinsUdp, MxComponent, or CxComponent.";
301 return;
302 }
303 }
304
314 {
315 if (!int.TryParse(MxLogicalStationNumberText, out var logicalStationNumber) || logicalStationNumber < 0)
316 {
317 _runtime.Monitor.StatusMessage = "MX logical station number must be zero or greater.";
318 return;
319 }
320
321 var progId = string.IsNullOrWhiteSpace(MxProgId)
322 ? MitsubishiMxComponentOptions.DefaultProgId
323 : MxProgId;
324
325 _runtime.UseMitsubishiMxComponentClient(progId, logicalStationNumber);
326 }
327
337 {
338 _runtime.UseOmronCxComponentClient(CxProgId, CxPeerAddress);
339 }
340
341
374 private void UseOmronFinsClient(string host, int port, string transportText)
375 {
376 if (!int.TryParse(McRetryCountText, out var retryCount) || retryCount <= 0)
377 {
378 _runtime.Monitor.StatusMessage = "FINS retry count must be greater than zero.";
379 return;
380 }
381
382 _runtime.UseOmronFinsClient(host, port, transportText, retryCount);
383 }
384
393 public void UseTcpClient()
394 {
395 if (!TryGetPort(out var port))
396 {
397 return;
398 }
399
400 _runtime.UseSimulatorTcpClient(Host, port);
401 }
402
403
436 private void UseMitsubishiMcClient(string host, int port, string transportText)
437 {
438 if (!int.TryParse(McRetryCountText, out var retryCount) || retryCount <= 0)
439 {
440 _runtime.Monitor.StatusMessage = "MC retry count must be greater than zero.";
441 return;
442 }
443
444 _runtime.UseMitsubishiMcClient(host, port, transportText, retryCount);
445 }
446
447
456 public void UseMcClient()
457 {
458 if (!int.TryParse(McPortText, out var port) || port is <= 0 or > 65535)
459 {
460 _runtime.Monitor.StatusMessage = "MC port must be between 1 and 65535.";
461 return;
462 }
463
464 if (!int.TryParse(McRetryCountText, out var retryCount) || retryCount <= 0)
465 {
466 _runtime.Monitor.StatusMessage = "MC retry count must be greater than zero.";
467 return;
468 }
469
470 _runtime.UseMitsubishiMcClient(McHost, port, McTransportText, retryCount);
471 }
472
481 public void RunHandshakeTest()
482 {
483 if (!short.TryParse(HandshakeStartValueText, out var startValue))
484 {
485 _runtime.Monitor.StatusMessage = "Handshake start value must be a 16-bit integer.";
486 return;
487 }
488
489 if (!int.TryParse(HandshakeIterationsText, out var iterations) || iterations <= 0)
490 {
491 _runtime.Monitor.StatusMessage = "Handshake iterations must be greater than zero.";
492 return;
493 }
494
495 if (!int.TryParse(HandshakeDelayMsText, out var delayMs) || delayMs < 0)
496 {
497 _runtime.Monitor.StatusMessage = "Handshake delay must be zero or greater.";
498 return;
499 }
500
501 _ = _runtime.RunHandshakeTestAsync(startValue, iterations, delayMs);
502 }
503
528 private bool TryGetPort(out int port)
529 {
530 if (!int.TryParse(PortText, out port) || port is <= 0 or > 65535)
531 {
532 _runtime.Monitor.StatusMessage = "Port must be between 1 and 65535.";
533 return false;
534 }
535
536 return true;
537 }
538}
void UseOmronFinsClient(string host, int port, string transportText)
void UseMitsubishiMcClient(string host, int port, string transportText)