SampleSmart 1.0.0.0
SampleSmart 사용 방법을 보여 주는 예제 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
PlcSimulatorTab.xaml.Event.cs
이 파일의 문서화 페이지로 가기
2
11public sealed class PlcSimulatorTabEvent
12{
21 private readonly PlcSampleRuntime _runtime;
22
48 {
49 _runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
50 }
51
60 public string Host { get; set; } = "127.0.0.1";
61
70 public string PortText { get; set; } = "55000";
71
80 public void StartServer()
81 {
82 if (!TryGetPort(out var port))
83 {
84 return;
85 }
86
87 var bindHost = Host == "127.0.0.1" ? "0.0.0.0" : Host;
88 _ = _runtime.StartSimulatorServerAsync(bindHost, port);
89 }
90
99 public void StopServer()
100 {
101 _ = _runtime.StopSimulatorServerAsync();
102 }
103
112 public void UseTcpClient()
113 {
114 if (!TryGetPort(out var port))
115 {
116 return;
117 }
118
119 _runtime.UseSimulatorTcpClient(Host, port);
120 }
121
146 private bool TryGetPort(out int port)
147 {
148 if (!int.TryParse(PortText, out port) || port is <= 0 or > 65535)
149 {
150 _runtime.Monitor.StatusMessage = "Port must be between 1 and 65535.";
151 return false;
152 }
153
154 return true;
155 }
156}