SampleSmart
1.0.0.0
SampleSmart 사용 방법을 보여 주는 예제 프로젝트입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
PagePlcMonitor.xaml.Event.cs
이 파일의 문서화 페이지로 가기
1
using
Dreamine.PLC.Wpf.ViewModels;
2
using
Dreamine.PLC.Mitsubishi.MxComponent.Options;
3
using
SampleSmart.Pages.PageSub.PlcTabs
;
4
5
namespace
SampleSmart.Pages.PageSub
;
6
15
public
sealed
class
PagePlcMonitorEvent
16
{
25
private
readonly
PlcSampleRuntime
_runtime
;
26
51
public
PagePlcMonitorEvent
(
PlcSampleRuntime
runtime)
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"
:
294
UseMitsubishiMxComponentClient
();
295
return
;
296
case
"CXCOMPONENT"
:
297
UseOmronCxComponentClient
();
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
313
private
void
UseMitsubishiMxComponentClient
()
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
336
private
void
UseOmronCxComponentClient
()
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
}
SampleSmart.Pages.PageSub
Definition
CommunicationSampleRuntime.cs:21
SampleSmart.Pages.PageSub.PlcTabs
Definition
InMemoryPlcTab.xaml.cs:3
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseOmronFinsClient
void UseOmronFinsClient(string host, int port, string transportText)
Definition
PagePlcMonitor.xaml.Event.cs:374
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.McTransportText
string McTransportText
Definition
PagePlcMonitor.xaml.Event.cs:166
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseOmronCxComponentClient
void UseOmronCxComponentClient()
Definition
PagePlcMonitor.xaml.Event.cs:336
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.TryGetPort
bool TryGetPort(out int port)
Definition
PagePlcMonitor.xaml.Event.cs:528
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.McPortText
string McPortText
Definition
PagePlcMonitor.xaml.Event.cs:156
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.RunHandshakeTest
void RunHandshakeTest()
Definition
PagePlcMonitor.xaml.Event.cs:481
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.HandshakeStartValueText
string HandshakeStartValueText
Definition
PagePlcMonitor.xaml.Event.cs:186
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseTcpClient
void UseTcpClient()
Definition
PagePlcMonitor.xaml.Event.cs:393
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.MxProgId
string MxProgId
Definition
PagePlcMonitor.xaml.Event.cs:105
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.Monitor
PlcMonitorViewModel Monitor
Definition
PagePlcMonitor.xaml.Event.cs:64
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.ClientModeText
string ClientModeText
Definition
PagePlcMonitor.xaml.Event.cs:95
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.PortText
string PortText
Definition
PagePlcMonitor.xaml.Event.cs:84
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.Host
string Host
Definition
PagePlcMonitor.xaml.Event.cs:74
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.McHost
string McHost
Definition
PagePlcMonitor.xaml.Event.cs:146
SampleSmart.Pages.PageSub.PagePlcMonitorEvent._runtime
readonly PlcSampleRuntime _runtime
Definition
PagePlcMonitor.xaml.Event.cs:25
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.CxPeerAddress
string CxPeerAddress
Definition
PagePlcMonitor.xaml.Event.cs:135
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.McRetryCountText
string McRetryCountText
Definition
PagePlcMonitor.xaml.Event.cs:176
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseInMemory
void UseInMemory()
Definition
PagePlcMonitor.xaml.Event.cs:216
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.MxLogicalStationNumberText
string MxLogicalStationNumberText
Definition
PagePlcMonitor.xaml.Event.cs:115
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.CxProgId
string CxProgId
Definition
PagePlcMonitor.xaml.Event.cs:125
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseMitsubishiMxComponentClient
void UseMitsubishiMxComponentClient()
Definition
PagePlcMonitor.xaml.Event.cs:313
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.HandshakeDelayMsText
string HandshakeDelayMsText
Definition
PagePlcMonitor.xaml.Event.cs:206
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseSelectedClient
void UseSelectedClient()
Definition
PagePlcMonitor.xaml.Event.cs:268
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseMitsubishiMcClient
void UseMitsubishiMcClient(string host, int port, string transportText)
Definition
PagePlcMonitor.xaml.Event.cs:436
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.StartServer
void StartServer()
Definition
PagePlcMonitor.xaml.Event.cs:229
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.PagePlcMonitorEvent
PagePlcMonitorEvent(PlcSampleRuntime runtime)
Definition
PagePlcMonitor.xaml.Event.cs:51
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.HandshakeIterationsText
string HandshakeIterationsText
Definition
PagePlcMonitor.xaml.Event.cs:196
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.UseMcClient
void UseMcClient()
Definition
PagePlcMonitor.xaml.Event.cs:456
SampleSmart.Pages.PageSub.PagePlcMonitorEvent.StopServer
void StopServer()
Definition
PagePlcMonitor.xaml.Event.cs:255
SampleSmart.Pages.PageSub.PlcTabs.PlcSampleRuntime
Definition
PlcSampleRuntime.cs:29
Pages
PageSub
PagePlcMonitor.xaml.Event.cs
다음에 의해 생성됨 :
1.17.0