2026-06-05 13:44:39 +09:00

72 lines
2.7 KiB
C#

using Aurora;
using static AuroraPLC.PLCBase;
namespace AuroraPLC.Views
{
public class PLCStatic
{
#region PLC 뷰 관련
// 뷰모델 For Bit & Word
private static UCPLCBitViewModel ViewModelBitMonitor { get; set; }
private static UCPLCBitViewModel ViewModelMBitMonitor { get; set; }
private static UCPLCWordViewModel ViewModelWordMonitor { get; set; }
private static UCPLCWordViewModel ViewModelDWordMonitor { get; set; }
// 동기화를 위한 뮤텍스
private static readonly object _lockBitVM = new object();
private static readonly object _lockWordVM = new object();
// 싱글톤 패턴으로 구현
public static UCPLCBitViewModel GetInstanceBitVM(IAuroraEnvironment auroraEnv, string deviceID, ePLCNetType netType, ePLCDevice device = ePLCDevice.B)
{
if (device == ePLCDevice.M) {
if (ViewModelMBitMonitor is null) {
lock (_lockBitVM) {
if (ViewModelMBitMonitor is null) {
ViewModelMBitMonitor = new UCPLCBitViewModel(auroraEnv, deviceID, netType, device);
}
}
}
return ViewModelMBitMonitor;
} else {
if (ViewModelBitMonitor is null) {
lock (_lockBitVM) {
if (ViewModelBitMonitor is null) {
ViewModelBitMonitor = new UCPLCBitViewModel(auroraEnv, deviceID, netType, device);
}
}
}
return ViewModelBitMonitor;
}
}
public static UCPLCWordViewModel GetInstanceWordVM(IAuroraEnvironment auroraEnv, string deviceID, ePLCNetType netType, ePLCDevice device = ePLCDevice.W)
{
if (device == ePLCDevice.D) {
if (ViewModelDWordMonitor is null) {
lock (_lockWordVM) {
if (ViewModelDWordMonitor is null) {
ViewModelDWordMonitor = new UCPLCWordViewModel(auroraEnv, deviceID, netType, device);
}
}
}
return ViewModelDWordMonitor;
} else {
if (ViewModelWordMonitor is null) {
lock (_lockWordVM) {
if (ViewModelWordMonitor is null) {
ViewModelWordMonitor = new UCPLCWordViewModel(auroraEnv, deviceID, netType, device);
}
}
}
return ViewModelWordMonitor;
}
}
public static bool IsViewEnabled { get; set; } = true;
#endregion
}
}