Commit 2470f161 LN

1

1 个父辈 ac6deef9
...@@ -9,19 +9,17 @@ using OnlineStore.Common; ...@@ -9,19 +9,17 @@ using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System.Threading.Tasks; using System.Threading.Tasks;
using Asa.IOModule; using Asa.IOModule;
using System.Collections.Concurrent;
namespace OnlineStore.DeviceLibrary namespace OnlineStore.DeviceLibrary
{ {
public class AIOBOXManager : IOManager public class AIOBOXManager : IOManager
{ {
//public static uint DefaultDICount = 16;
//public static uint DefaultDOCount = 16;
public readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public Dictionary<string, AIOBOX> AIOMap = new Dictionary<string, AIOBOX>(); public Dictionary<string, AIOBOX> AIOMap = new Dictionary<string, AIOBOX>();
public Dictionary<string, List<Box_Sta>> DIValueMap = new Dictionary<string, List<Box_Sta>>(); public ConcurrentDictionary<string, List<Box_Sta>> DIValueMap = new ConcurrentDictionary<string, List<Box_Sta>>();
public Dictionary<string, List<Box_Sta>> DOValueMap = new Dictionary<string, List<Box_Sta>>(); public ConcurrentDictionary<string, List<Box_Sta>> DOValueMap = new ConcurrentDictionary<string, List<Box_Sta>>();
private object DIMapLock = ""; private object DIMapLock = "";
private object DOMapLock = ""; private object DOMapLock = "";
...@@ -87,13 +85,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -87,13 +85,14 @@ namespace OnlineStore.DeviceLibrary
} }
AIOMap.Remove(ioIp); AIOMap.Remove(ioIp);
} }
List<Box_Sta> list = new List<Box_Sta>();
if (DIValueMap.ContainsKey(ioIp)) if (DIValueMap.ContainsKey(ioIp))
{ {
DIValueMap.Remove(ioIp); DIValueMap.TryRemove(ioIp,out list);
} }
if (DOValueMap.ContainsKey(ioIp)) if (DOValueMap.ContainsKey(ioIp))
{ {
DOValueMap.Remove(ioIp); DOValueMap.TryRemove(ioIp, out list);
} }
int DIMS = ConfigAppSettings.GetIntValue("DIMS"); int DIMS = ConfigAppSettings.GetIntValue("DIMS");
if (DIMS < 20) if (DIMS < 20)
...@@ -220,15 +219,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -220,15 +219,7 @@ namespace OnlineStore.DeviceLibrary
needUpdate = true; needUpdate = true;
} }
else else
{ {
//foreach(Box_Sta s in sta)
//{
// updateDi += s.ToString() + ",";
//}
//if (ip.Equals("192.168.201.61"))
//{
// LogUtil.info(updateDi);
//}
for (int i = 0; i < newList.Count; i++) for (int i = 0; i < newList.Count; i++)
{ {
if (!(oldList[i].Equals(newList[i]))) if (!(oldList[i].Equals(newList[i])))
...@@ -240,13 +231,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -240,13 +231,15 @@ namespace OnlineStore.DeviceLibrary
} }
if (needUpdate) if (needUpdate)
{ {
lock (DILock) // lock (DILock)
{ {
if (DIValueMap.ContainsKey(ip)) if (DIValueMap.ContainsKey(ip))
{ {
DIValueMap.Remove(ip); List<Box_Sta> s = new List<Box_Sta>();
DIValueMap.TryRemove(ip,out s);
} }
DIValueMap.Add(ip, newList); DIValueMap.TryAdd(ip, newList);
} }
} }
} }
...@@ -261,12 +254,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -261,12 +254,7 @@ namespace OnlineStore.DeviceLibrary
newList.AddRange(sta); newList.AddRange(sta);
List<Box_Sta> oldList = null; List<Box_Sta> oldList = null;
DOValueMap.TryGetValue(ip, out oldList); DOValueMap.TryGetValue(ip, out oldList);
//string result = "UpdateAllDO ip[" + ip + "], sta :";
//for (int i = 0; i < newList.Count; i++)
//{
// result += newList[i] + ",";
//}
//LogUtil.info(result);
if (oldList == null || oldList.Count.Equals(newList.Count).Equals(false)) if (oldList == null || oldList.Count.Equals(newList.Count).Equals(false))
{ {
needUpdate = true; needUpdate = true;
...@@ -284,27 +272,17 @@ namespace OnlineStore.DeviceLibrary ...@@ -284,27 +272,17 @@ namespace OnlineStore.DeviceLibrary
} }
if (needUpdate) if (needUpdate)
{ {
lock (DOLock) // lock (DOLock)
{ {
if (DOValueMap.ContainsKey(ip)) if (DOValueMap.ContainsKey(ip))
{ {
DOValueMap.Remove(ip); List<Box_Sta> list = new List<Box_Sta>();
DOValueMap.TryRemove(ip,out list);
} }
DOValueMap.Add(ip, newList); DOValueMap.TryAdd(ip, newList);
} }
} }
} }
//else
//{
// if (sta == null)
// {
// LogUtil.error("UpdateAllDO ip[" + ip + "], sta=null");
// }
// else
// {
// LogUtil.error(" UpdateAllDO ip[" + ip + "], sta.Length=" + sta.Length);
// }
//}
} }
...@@ -422,7 +400,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -422,7 +400,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("ReadAllDI出错:" + ioIp); LogUtil.error("ReadAllDI [" + ioIp + "] 出错:" + ex.ToString());
} }
} }
public override void ReadAllDO(string ioIp, byte slaveId) public override void ReadAllDO(string ioIp, byte slaveId)
...@@ -439,7 +417,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -439,7 +417,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("ReadAllDO出错:" + ioIp); LogUtil.error("ReadAllDO ["+ioIp+"] 出错:" + ex.ToString());
} }
} }
public override IO_VALUE GetDOValue(string ioIP, byte slaveId, ushort StartAddress) public override IO_VALUE GetDOValue(string ioIP, byte slaveId, ushort StartAddress)
...@@ -468,7 +446,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -468,7 +446,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("GetDOValue 出错:" + ex.ToString()); LogUtil.error("GetDOValue [" + ioIP + "] [" + StartAddress + "] 出错:" + ex.ToString());
} }
return value; return value;
} }
...@@ -476,31 +454,34 @@ namespace OnlineStore.DeviceLibrary ...@@ -476,31 +454,34 @@ namespace OnlineStore.DeviceLibrary
public override IO_VALUE GetDIValue(string ioIP, byte slaveId, ushort StartAddress) public override IO_VALUE GetDIValue(string ioIP, byte slaveId, ushort StartAddress)
{ {
IO_VALUE value = IO_VALUE.LOW; IO_VALUE value = IO_VALUE.LOW;
try for (int i = 1; i <= 3; i++)
{ {
AIOBOX aioBox = getAIO(ioIP); try
if (aioBox != null)
{ {
Box_Sta sta = Box_Sta.Off; AIOBOX aioBox = getAIO(ioIP);
// Box_Addr addr = GetAddr(StartAddress); if (aioBox != null)
int index = StartAddress;
if (DIValueMap.ContainsKey(ioIP) && DIValueMap[ioIP].Count > index)
{ {
sta = DIValueMap[ioIP][index]; Box_Sta sta = Box_Sta.Off;
} // Box_Addr addr = GetAddr(StartAddress);
else int index = StartAddress;
{ if (DIValueMap.ContainsKey(ioIP) && DIValueMap[ioIP].Count > index)
sta = aioBox.ReadDI(StartAddress); {
} sta = DIValueMap[ioIP][index];
if (sta.Equals(Box_Sta.On)) }
{ else
value = IO_VALUE.HIGH; {
sta = aioBox.ReadDI(StartAddress);
}
if (sta.Equals(Box_Sta.On))
{
value = IO_VALUE.HIGH;
}
} }
} }
} catch (Exception ex)
catch (Exception ex) {
{ LogUtil.error("GetDIValue [" + ioIP + "] ["+StartAddress+"] [" + i+"] 出错:" + ex.ToString());
LogUtil.error("GetDIValue 出错:" + ex.ToString()); }
} }
return value; return value;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!