Commit 7bd8fb8f LN

去掉io处理的lock.

1 个父辈 1f1bcfad
...@@ -488,12 +488,13 @@ namespace OnlineStore.AssemblyLine ...@@ -488,12 +488,13 @@ namespace OnlineStore.AssemblyLine
private DateTime lastLogTime = DateTime.Now; private DateTime lastLogTime = DateTime.Now;
PerformanceCounter curtime = null; PerformanceCounter curtime = null;
private int logMinute = 5;
private void LogM() private void LogM()
{ {
try try
{ {
TimeSpan sp = DateTime.Now - lastLogTime; TimeSpan sp = DateTime.Now - lastLogTime;
if (sp.TotalMinutes >= 5) if (sp.TotalMinutes >= logMinute)
{ {
lastLogTime = DateTime.Now; lastLogTime = DateTime.Now;
...@@ -507,7 +508,16 @@ namespace OnlineStore.AssemblyLine ...@@ -507,7 +508,16 @@ namespace OnlineStore.AssemblyLine
StringBuilder sbResult = new StringBuilder(); StringBuilder sbResult = new StringBuilder();
PerformanceCounter pf1 = new PerformanceCounter("Process", "Working Set - Private", process.ProcessName); PerformanceCounter pf1 = new PerformanceCounter("Process", "Working Set - Private", process.ProcessName);
sbResult.AppendFormat(DateTime.Now.ToLongTimeString() + ", 名称:{0} 内存:{1}M ", process.ProcessName, Math.Round(pf1.NextValue() / 1024 / 1024F, 2)); sbResult.AppendFormat(DateTime.Now.ToLongTimeString() + ", 名称:{0} 内存:{1}M ", process.ProcessName, Math.Round(pf1.NextValue() / 1024 / 1024F, 2));
sbResult.AppendFormat(", CPU : {0} %", curtime.NextValue() / Environment.ProcessorCount); float cpu = curtime.NextValue() / Environment.ProcessorCount;
sbResult.AppendFormat(", CPU : {0} %",cpu);
if (cpu >= 10)
{
logMinute = 1;
}
else
{
logMinute = 5;
}
LogUtil.info(sbResult.ToString()); LogUtil.info(sbResult.ToString());
} }
} }
......

104.2 KB | 宽: | 高:

104.3 KB | 宽: | 高:

source/AssemblyLineClient/image/line.png
source/AssemblyLineClient/image/line.png
source/AssemblyLineClient/image/line.png
source/AssemblyLineClient/image/line.png
  • 两方对比
  • 交换覆盖
  • 透明覆盖
...@@ -94,8 +94,6 @@ ...@@ -94,8 +94,6 @@
<Compile Include="assemblyLine\LineBean_Partial.cs" /> <Compile Include="assemblyLine\LineBean_Partial.cs" />
<Compile Include="assemblyLine\MoveEquip.cs" /> <Compile Include="assemblyLine\MoveEquip.cs" />
<Compile Include="assemblyLine\MoveEquip_Partial.cs" /> <Compile Include="assemblyLine\MoveEquip_Partial.cs" />
<Compile Include="deviceLibrary\IO\KangNaiDe\KNDManager.cs" />
<Compile Include="deviceLibrary\IO\KangNaiDe\MasterTcpClient.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACCMDManager.cs" /> <Compile Include="deviceLibrary\PanasonicServo\ACCMDManager.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" /> <Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" /> <Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" />
......
...@@ -10,6 +10,7 @@ using OnlineStore.LoadCSVLibrary; ...@@ -10,6 +10,7 @@ using OnlineStore.LoadCSVLibrary;
using System.Threading.Tasks; using System.Threading.Tasks;
using Asa.IOModule; using Asa.IOModule;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Concurrent;
namespace OnlineStore.DeviceLibrary namespace OnlineStore.DeviceLibrary
{ {
...@@ -21,13 +22,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -21,13 +22,13 @@ namespace OnlineStore.DeviceLibrary
//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 = "";
private object DILock = ""; //private object DILock = "";
private object DOLock = ""; //private object DOLock = "";
public override void ConnectionIOList(List<string> DIONameList) public override void ConnectionIOList(List<string> DIONameList)
...@@ -63,11 +64,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -63,11 +64,11 @@ namespace OnlineStore.DeviceLibrary
} }
if (DIValueMap.ContainsKey(ioIp)) if (DIValueMap.ContainsKey(ioIp))
{ {
DIValueMap.Remove(ioIp); DIValueMap.TryRemove(ioIp,out List<Box_Sta> sValueList);
} }
if (DOValueMap.ContainsKey(ioIp)) if (DOValueMap.ContainsKey(ioIp))
{ {
DOValueMap.Remove(ioIp); DOValueMap.TryRemove(ioIp, out List<Box_Sta> sValueList);
} }
int DIMS = ConfigAppSettings.GetIntValue("DIMS"); int DIMS = ConfigAppSettings.GetIntValue("DIMS");
if (DIMS < 20) if (DIMS < 20)
...@@ -84,15 +85,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -84,15 +85,6 @@ namespace OnlineStore.DeviceLibrary
string logName = "IO模块[" + ioIp + "] DI[" + DILength + "] DO[" + DOLength + "],[" + DIMS + "] [" + DOMS + "]"; string logName = "IO模块[" + ioIp + "] DI[" + DILength + "] DO[" + DOLength + "],[" + DIMS + "] [" + DOMS + "]";
try try
{ {
//aioBox = new AIOBOX();
//aioBox.LogPath(Application.StartupPath + @"\logs\aio\", LogType.OnlyError);
//aioBox.IP = ioIp;
//aioBox.SetInput(Asa.IOModule.Box_Type.DI, DILength);
//aioBox.SetOutput(Asa.IOModule.Box_Type.DO, DOLength);
////DI主动上传
//aioBox.AutoReadInput(true);
//aioBox.AutoReadOutput(false, DOMS);
aioBox = new AIOBOX(Asa.IOModule.Box_Type.DI, DILength, Asa.IOModule.Box_Type.DO, DOLength); aioBox = new AIOBOX(Asa.IOModule.Box_Type.DI, DILength, Asa.IOModule.Box_Type.DO, DOLength);
// aioBox.SetType(Asa.IOModule.Box_Type.DI, DILength, Asa.IOModule.Box_Type.DO, DOLength); // aioBox.SetType(Asa.IOModule.Box_Type.DI, DILength, Asa.IOModule.Box_Type.DO, DOLength);
...@@ -152,36 +144,36 @@ namespace OnlineStore.DeviceLibrary ...@@ -152,36 +144,36 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error("AioBox_DO_Changed_Event出错:", ex); LogUtil.error("AioBox_DO_Changed_Event出错:", ex);
} }
} }
private bool IsAxisCheckDI(string ip, int index) //private bool IsAxisCheckDI(string ip, int index)
{ //{
// DI,0,SL1伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_12,0,SL1伺服定位料盘检测,X123,X123 , // // DI,0,SL1伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_12,0,SL1伺服定位料盘检测,X123,X123 ,
// DI,0,SL2伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_14,0,SL2伺服定位料盘检测,X163,X163 , // // DI,0,SL2伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_14,0,SL2伺服定位料盘检测,X163,X163 ,
// DI,0,SL3伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_16,0,SL3伺服定位料盘检测,X203,X203 , // // DI,0,SL3伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_16,0,SL3伺服定位料盘检测,X203,X203 ,
// DI,0,SL4伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_18,0,SL4伺服定位料盘检测,X243,X243 , // // DI,0,SL4伺服定位料盘检测,SL_AxisLocationCheck,2,PRO_AOI_IP_18,0,SL4伺服定位料盘检测,X243,X243 ,
//PRO,0,上料流水线SL1 - 模块2,PRO_AOI_IP_12,192.168.101.25,,,,, // //PRO,0,上料流水线SL1 - 模块2,PRO_AOI_IP_12,192.168.101.25,,,,,
//PRO,0,上料流水线SL2 - 模块2,PRO_AOI_IP_14,192.168.101.27,,,,, // //PRO,0,上料流水线SL2 - 模块2,PRO_AOI_IP_14,192.168.101.27,,,,,
//PRO,0,上料流水线SL3 - 模块2,PRO_AOI_IP_16,192.168.101.29,,,,, // //PRO,0,上料流水线SL3 - 模块2,PRO_AOI_IP_16,192.168.101.29,,,,,
//PRO,0,下料流水线SL4 - 模块2,PRO_AOI_IP_18,192.168.101.31,,,,, // //PRO,0,下料流水线SL4 - 模块2,PRO_AOI_IP_18,192.168.101.31,,,,,
if (index.Equals(2) && ip.Equals("192.168.101.25")) // if (index.Equals(2) && ip.Equals("192.168.101.25"))
{ // {
return true; // return true;
} // }
else if (index.Equals(2) && ip.Equals("192.168.101.27")) // else if (index.Equals(2) && ip.Equals("192.168.101.27"))
{ // {
return true; // return true;
} // }
else if (index.Equals(2) && ip.Equals("192.168.101.29")) // else if (index.Equals(2) && ip.Equals("192.168.101.29"))
{ // {
return true; // return true;
} // }
else if (index.Equals(2) && ip.Equals("192.168.101.31")) // else if (index.Equals(2) && ip.Equals("192.168.101.31"))
{ // {
return true; // return true;
} // }
return false; // return false;
} //}
private void UpdateAllDI(string ip, Box_Sta[] sta) private void UpdateAllDI(string ip, Box_Sta[] sta)
{ {
if (sta != null && sta.Length >= LineManager.Config.GetDILength(ip)) if (sta != null && sta.Length >= LineManager.Config.GetDILength(ip))
...@@ -209,14 +201,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -209,14 +201,14 @@ namespace OnlineStore.DeviceLibrary
} }
if (needUpdate) if (needUpdate)
{ {
lock (DILock) //lock (DILock)
{ //{
if (DIValueMap.ContainsKey(ip)) //if (DIValueMap.ContainsKey(ip))
{ //{
DIValueMap.Remove(ip); // DIValueMap.TryRemove(ip,out List<Box_Sta> vList);
} //}
DIValueMap.Add(ip, newList); DIValueMap.AddOrUpdate(ip, newList, (k, v) => newList);
} //}
try try
{ {
if (oldList != null && newList != null) if (oldList != null && newList != null)
...@@ -270,14 +262,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -270,14 +262,14 @@ namespace OnlineStore.DeviceLibrary
} }
if (needUpdate) if (needUpdate)
{ {
lock (DOLock) //lock (DOLock)
{ //{
if (DOValueMap.ContainsKey(ip)) //if (DOValueMap.ContainsKey(ip))
{ //{
DOValueMap.Remove(ip); // DOValueMap.TryRemove(ip,out List<Box_Sta> vs);
} //}
DOValueMap.Add(ip, newList); DOValueMap.AddOrUpdate(ip, newList, (k, v) => newList);
} //}
} }
} }
} }
......
...@@ -174,14 +174,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -174,14 +174,14 @@ namespace OnlineStore.DeviceLibrary
public static void Init() public static void Init()
{ {
bool isAIOBox = ConfigAppSettings.GetIntValue(Setting_Init.UseAIOBOX).Equals(1); bool isAIOBox = ConfigAppSettings.GetIntValue(Setting_Init.UseAIOBOX).Equals(1);
if (isAIOBox) //if (isAIOBox)
{ //{
instance = new AIOBOXManager(); instance = new AIOBOXManager();
} //}
else //else
{ //{
instance = new KNDManager(); //instance = new KNDManager();
} //}
} }
public abstract void ReadAllDI(string deviceName, byte slaveId); public abstract void ReadAllDI(string deviceName, byte slaveId);
......
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Ports; using System.IO.Ports;
using System.Linq; using System.Linq;
...@@ -17,8 +18,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -17,8 +18,8 @@ namespace OnlineStore.DeviceLibrary
public static bool IsShowMsg = false ; public static bool IsShowMsg = false ;
private static int SleepMSendons = 20; private static int SleepMSendons = 20;
private static int ReviceOutTimeMS = 100; private static int ReviceOutTimeMS = 100;
private static Dictionary<string, Dictionary<string, int>> ComAddrValue = new Dictionary<string, Dictionary<string, int>>(); private static ConcurrentDictionary<string, ConcurrentDictionary<string, int>> ComAddrValue = new ConcurrentDictionary<string, ConcurrentDictionary<string, int>>();
private static string mapObj = ""; //private static string mapObj = "";
private static int GetAddrValue(string portName, int slvAddr, string addr) private static int GetAddrValue(string portName, int slvAddr, string addr)
{ {
...@@ -26,7 +27,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -26,7 +27,7 @@ namespace OnlineStore.DeviceLibrary
try try
{ {
string name = portName + "_" + slvAddr; string name = portName + "_" + slvAddr;
Dictionary<string, int> map = null; ConcurrentDictionary<string, int> map = null;
ComAddrValue.TryGetValue(name, out map); ComAddrValue.TryGetValue(name, out map);
if (map == null) if (map == null)
{ {
...@@ -47,30 +48,30 @@ namespace OnlineStore.DeviceLibrary ...@@ -47,30 +48,30 @@ namespace OnlineStore.DeviceLibrary
{ {
try try
{ {
lock (mapObj) //lock (mapObj)
{ //{
string name = portName + "_" + slvAddr; string name = portName + "_" + slvAddr;
Dictionary<string, int> map = null; ConcurrentDictionary<string, int> map = null;
ComAddrValue.TryGetValue(name, out map); ComAddrValue.TryGetValue(name, out map);
if (map == null) if (map == null)
{ {
map = new Dictionary<string, int>(); map = new ConcurrentDictionary<string, int>();
ComAddrValue.Add(name, map); ComAddrValue.TryAdd(name, map);
} }
if (map.ContainsKey(addr)) //if (map.ContainsKey(addr))
{ //{
ComAddrValue[name][addr] = value; // ComAddrValue[name][addr] = value;
} //}
else //else
{ //{
ComAddrValue[name].Add(addr, value); ComAddrValue[name].AddOrUpdate(addr, value, (k, v) => value);
} //}
} //}
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("UpdateAddrValue出错:",ex); LogUtil.error("UpdateAddrValue出错:", ex);
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
...@@ -73,21 +74,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -73,21 +74,21 @@ namespace OnlineStore.DeviceLibrary
/// <summary> /// <summary>
/// 记录上一次的部分IO状态,主要是急停,气压检测信号,复位信号,用来判断是否io发生改变 /// 记录上一次的部分IO状态,主要是急停,气压检测信号,复位信号,用来判断是否io发生改变
/// </summary> /// </summary>
public Dictionary<string, IO_VALUE> DILastValueMap = new Dictionary<string, IO_VALUE>(); public ConcurrentDictionary<string, IO_VALUE> DILastValueMap = new ConcurrentDictionary<string, IO_VALUE>();
public object lastDiListLock = ""; public object lastDiListLock = "";
public void addLastDI(string type, IO_VALUE value) public void addLastDI(string type, IO_VALUE value)
{ {
try try
{ {
lock (lastDiListLock) //lock (lastDiListLock)
{ //{
if (DILastValueMap.ContainsKey(type)) //if (DILastValueMap.ContainsKey(type))
{ //{
DILastValueMap.Remove(type); // DILastValueMap.TryRemove(type, out IO_VALUE v);
} //}
DILastValueMap.Add(type, value); DILastValueMap.AddOrUpdate(type, value, (k, v) => value);
} //}
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -13,6 +13,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -13,6 +13,7 @@ namespace OnlineStore.DeviceLibrary
{ {
//private static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); //private static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static object MapLock = "";
private static TcpServer tcpserver = null; private static TcpServer tcpserver = null;
public static bool IsStart = false; public static bool IsStart = false;
public static int ClientKeepSecond = 10; public static int ClientKeepSecond = 10;
...@@ -148,11 +149,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -148,11 +149,15 @@ namespace OnlineStore.DeviceLibrary
if (span.TotalSeconds < ClientKeepSecond && box.HasTray.Equals(0) && box.SAlarmType.Equals(LineAlarmType.None)) if (span.TotalSeconds < ClientKeepSecond && box.HasTray.Equals(0) && box.SAlarmType.Equals(LineAlarmType.None))
{ {
LineRunStatus runs = (LineRunStatus)box.SRunStatus; LineRunStatus runs = (LineRunStatus)box.SRunStatus;
LineStatus movestatus = (LineStatus)box.SStatus;
if (runs.Equals(LineRunStatus.Runing)) if (runs.Equals(LineRunStatus.Runing))
{ {
return true; return true;
} }
//else if (runs.Equals(LineRunStatus.Busy) && movestatus.Equals(LineStatus.InStoreEnd))
//{
// return true;
//}
else else
{ {
NotOkMsg = " [料仓" + id + "可以入库:忙碌中] "; NotOkMsg = " [料仓" + id + "可以入库:忙碌中] ";
...@@ -388,7 +393,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -388,7 +393,6 @@ namespace OnlineStore.DeviceLibrary
result = JsonHelper.SerializeObject(paramList); result = JsonHelper.SerializeObject(paramList);
return result + "\r"; return result + "\r";
} }
private static object MapLock = "";
private static void SaveBoxClient(int id, BoxInfo box, TcpClientBean client) private static void SaveBoxClient(int id, BoxInfo box, TcpClientBean client)
{ {
lock (MapLock) lock (MapLock)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!