Commit 2470f161 LN

1

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