75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace 电子展板.Base
|
|
{
|
|
public class ViewModelBase : ModelBase
|
|
{
|
|
public MyConfig Config => GlobalVariable.Config;
|
|
public static object _lock = new object();
|
|
//获取PLC变量值
|
|
//public object GetPlcValue(string plcVariableName, bool isLog = true)
|
|
//{
|
|
// lock (_lock)
|
|
// {
|
|
// try
|
|
// {
|
|
// return adsServer.GetValue(plcVariableName);
|
|
// }
|
|
// catch
|
|
// {
|
|
// if (string.IsNullOrEmpty(plcVariableName))
|
|
// LogErr($"Error in GetPLCVar() Plc variable is null or empty.");
|
|
// else
|
|
// LogErr($"Error in GetPLCVar(), PLC variable '{plcVariableName}'");
|
|
// }
|
|
// return "0";
|
|
// }
|
|
//}
|
|
|
|
//public T GetPlcValue<T>(string plcVariableName)
|
|
//{
|
|
// lock (_lock)
|
|
// {
|
|
// try
|
|
// {
|
|
// object value = adsServer.GetValue(plcVariableName);
|
|
// return (T)Convert.ChangeType(value, typeof(T));
|
|
// }
|
|
// catch
|
|
// {
|
|
// if (string.IsNullOrEmpty(plcVariableName))
|
|
// LogErr($"Error in GetPLCVar() Plc variable is null or empty.");
|
|
// else
|
|
// LogErr($"Error in GetPLCVar(), PLC variable '{plcVariableName}'");
|
|
// return default(T);
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
//设置PLC变量值
|
|
//public bool SetPlcValue(string plcVariableName, object plcValue, bool isLog = true)
|
|
//{
|
|
// lock (_lock)
|
|
// {
|
|
// bool res = false;
|
|
// try
|
|
// {
|
|
// res = adsServer.SetValue(plcVariableName, plcValue);
|
|
// }
|
|
// catch
|
|
// {
|
|
// if (string.IsNullOrEmpty(plcVariableName))
|
|
// LogErr($"Error in SetPLCVar() Plc variable is null or empty.");
|
|
// else
|
|
// LogErr($"Error in SetPLCVar(), PLC variable '{plcVariableName}'");
|
|
// }
|
|
// return res;
|
|
// }
|
|
//}
|
|
}
|
|
}
|