ModbusHelper去掉单例

This commit is contained in:
maqiao 2024-11-28 11:34:42 +08:00
parent 47d2d9c475
commit fd17d9e5a9
2 changed files with 3 additions and 8 deletions

View File

@ -23,7 +23,7 @@ namespace DM_Weight.Port
private Socket socket; private Socket socket;
private TcpClient client; private TcpClient client;
private static ModbusHelper instance; private static ModbusHelper instance;
private static readonly object objLock = new object(); //private static readonly object objLock = new object();
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel)); private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
private ModbusHelper() private ModbusHelper()
{ {
@ -45,13 +45,8 @@ namespace DM_Weight.Port
//} //}
if (instance == null) if (instance == null)
{ {
lock (objLock)
{
if (instance == null)
instance = new ModbusHelper(); instance = new ModbusHelper();
} }
}
return instance; return instance;
} }
private void SetModusIpMaster() private void SetModusIpMaster()

View File

@ -287,7 +287,7 @@ namespace DM_Weight.ViewModels
//} //}
if (SelectedMenu != null && SelectedMenu.PremissionName == "退出") if (SelectedMenu != null && SelectedMenu.PremissionName == "退出")
{ {
bool[] boolArrs = {false,false };//ModbusHelper.GetInstance().GetAllBoxState(); bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
bool allTrue = Array.TrueForAll(boolArrs, b => b); bool allTrue = Array.TrueForAll(boolArrs, b => b);
//false是关着,true是开着 //false是关着,true是开着
if (!allTrue) if (!allTrue)