Commit 7bd8fb8f LN

去掉io处理的lock.

1 个父辈 1f1bcfad
......@@ -488,12 +488,13 @@ namespace OnlineStore.AssemblyLine
private DateTime lastLogTime = DateTime.Now;
PerformanceCounter curtime = null;
private int logMinute = 5;
private void LogM()
{
try
{
TimeSpan sp = DateTime.Now - lastLogTime;
if (sp.TotalMinutes >= 5)
if (sp.TotalMinutes >= logMinute)
{
lastLogTime = DateTime.Now;
......@@ -505,9 +506,18 @@ namespace OnlineStore.AssemblyLine
if (process != null)
{
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(", 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());
}
}
......

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