1.初版差异提交

This commit is contained in:
龚记林
2026-08-19 17:02:08 +08:00
parent 6f8dae2d02
commit 92c0d2e8d5
24 changed files with 507 additions and 27 deletions
@@ -185,6 +185,7 @@ namespace AGVSystem
temp.Read_dt = DateTime.Now;
UPDateDBList.upDbList.Add(new Location_Log(DateTime.Now, temp.Agv_ID, temp.Location_Display, location_value, 0, 0, 0));
}
WriteTxt.SaveLog1("=========》(11):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
#region
if (temp.Cross_Location_Go != location_temp && location_value > 0 && location_value < 2000)
{
@@ -361,10 +362,12 @@ namespace AGVSystem
#region
else if (Frm_A17168.businessCtrl.apiModel.waitRfidList.Split(',').Contains(location_temp.ToString()))
{
WriteTxt.SaveLog1("=========》(12):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
if (Frm_A17168.businessCtrl == null) Frm_A17168.businessCtrl = new BusinessManage();
if (Frm_A17168.leavedDic == null) Frm_A17168.leavedDic = new Dictionary<int, int>();
if (!Frm_A17168.leavedDic.ContainsKey(temp.Agv_ID)) Frm_A17168.leavedDic.Add(temp.Agv_ID, 0);
bool flg = false;
WriteTxt.SaveLog1(location_temp.ToString() + "开始请求放行", "放行日志" + (temp.Agv_ID), "插件日志");
//2秒请求一次
if (Frm_A17168.leavedDic[temp.Agv_ID] % Frm_A17168.businessCtrl.apiModel.requestSecond == 0)
{
@@ -375,16 +378,15 @@ namespace AGVSystem
//放行
if (flg)
{
// if (Link_To_PLC.WriteGo(temp.Agv_ID) == 0)
// {
// Frm_A17168.leavedDic[temp.Agv_ID] = 0;
// WriteTxt.SaveLog1(location_temp.ToString() + "路口已放行", "放行日志" + (temp.Agv_ID), "插件日志");
// t_temp = 0;
// temp.Cross_Location_Go = location_temp;
// }
WriteTxt.SaveLog1("=========》(13):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
//登记第三方交管路口占用
TrafficModel trafficModel = Frm_A17168.autoLeavedDic.Find(_ => _.areaCode.Equals(location_temp.ToString()));
if (trafficModel != null)
{
trafficModel.agvId = temp.Agv_ID;
trafficModel.InArea = DateTime.Now;
}
WriteTxt.SaveLog1(location_temp.ToString() + "路口添加" + trafficModel?.areaCode + "(" + trafficModel.agvId + ")", "放行日志" + (temp.Agv_ID), "插件日志");
if (Link_To_PC.WriteInfo(1, 0, 0) == 0)
{
Frm_A17168.leavedDic[temp.Agv_ID] = 0;
@@ -402,23 +404,31 @@ namespace AGVSystem
//{
else if (Frm_A17168.businessCtrl.apiModel.leavedRfidList.Split(',').Contains(location_temp.ToString()))
{
WriteTxt.SaveLog1("=========》(14):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
if (Frm_A17168.businessCtrl == null) Frm_A17168.businessCtrl = new BusinessManage();
if (Frm_A17168.leavedDic == null) Frm_A17168.leavedDic = new Dictionary<int, int>();
if (!Frm_A17168.leavedDic.ContainsKey(temp.Agv_ID)) Frm_A17168.leavedDic.Add(temp.Agv_ID, 0);
bool flg = false;
WriteTxt.SaveLog1(location_temp.ToString() + "开始请求释放", "放行日志" + (temp.Agv_ID), "插件日志");
if (Frm_A17168.leavedDic[temp.Agv_ID] % Frm_A17168.businessCtrl.apiModel.requestSecond == 0)
{
flg = Frm_A17168.businessCtrl.ByLeaved(temp.Agv_ID.ToString(), location_temp.ToString(), lockCode.ToString());
flg = Frm_A17168.businessCtrl.ByLeaved(temp.Agv_ID.ToString(), location_temp.ToString(), (location_temp - 1).ToString());
WriteTxt.SaveLog1(location_temp.ToString() + "离开释放返回的值" + flg, "放行日志" + (temp.Agv_ID), "插件日志");
}
//归还
if (flg)
{
WriteTxt.SaveLog1("=========》(15):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
Frm_A17168.leavedDic[temp.Agv_ID] = 0;
temp.Cross_Location_Go = location_temp;
lockCode = location_temp;
//清除第三方交管路口占用
TrafficModel trafficModel2 = Frm_A17168.autoLeavedDic.Find(_ => _.areaCode.Equals(location_temp.ToString()));
if (trafficModel2 != null)
{
trafficModel2.agvId = 0;
}
WriteTxt.SaveLog1(location_temp.ToString() + "路口已归还", "放行日志" + (temp.Agv_ID), "插件日志");
}
Frm_A17168.leavedDic[temp.Agv_ID]++;
@@ -467,8 +477,11 @@ namespace AGVSystem
Convert.ToString(param_info[6], 2).PadLeft(8, '0') +
Convert.ToString(param_info[5], 2).PadLeft(8, '0') +
Convert.ToString(param_info[4], 2).PadLeft(8, '0');
Thread.Sleep(100);
Warn_Deal(temp, sWarn);
ThreadPool.QueueUserWorkItem(delegate
{
Thread.Sleep(100);
Warn_Deal(temp, sWarn);
});
#endregion
}
}
@@ -608,8 +621,6 @@ namespace AGVSystem
WriteTxt.SaveLog1("AGV经过地标:" + location_temp, temp.Agv_ID + "#Agv", "地标日志");
//地标信息
temp.Location_Display = location_temp;
//记录充电
Func.Change_Rec(temp.Agv_ID, location_temp, temp.Location_Display, temp.Read_dt);
temp.Read_dt = DateTime.Now;
//Func.db_conn.Command("INSERT INTO [Location_Log] ([Dt] ,[Agv_ID] ,[Loc_ID] ,[Value] ,[Loc_ID2] ,[Value2],[Value3]) VALUES ('" +
@@ -617,13 +628,13 @@ namespace AGVSystem
string strsql = "INSERT INTO [Location_Log] ([Dt] ,[Agv_ID] ,[Loc_ID] ,[Value] ,[Loc_ID2] ,[Value2],[Value3]) VALUES ('" +
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + temp.Agv_ID + "," + location_temp + "," + location_value + "," + 0 + "," + 0 + "," + 0 + ")";
bBllBase.ExecuteNonQuery(strsql);
UPDateDBList.sqlList.Add(strsql);
}
if (Math.Abs(errorcount) > 0) errorcount = 0;
WriteTxt.SaveLog1("=========》(21):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
#region
if (temp.Cross_Location_Go != location_temp && location_value > 0 && location_value < 2000)
@@ -799,10 +810,12 @@ namespace AGVSystem
#region
else if (Frm_A17168.businessCtrl.apiModel.waitRfidList.Split(',').Contains(location_temp.ToString()))
{
WriteTxt.SaveLog1("=========》(22):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
if (Frm_A17168.businessCtrl == null) Frm_A17168.businessCtrl = new BusinessManage();
if (Frm_A17168.leavedDic == null) Frm_A17168.leavedDic = new Dictionary<int, int>();
if (!Frm_A17168.leavedDic.ContainsKey(temp.Agv_ID)) Frm_A17168.leavedDic.Add(temp.Agv_ID, 0);
bool flg = false;
WriteTxt.SaveLog1(location_temp.ToString() + "开始请求放行", "放行日志" + (temp.Agv_ID), "插件日志");
//2秒请求一次
if (Frm_A17168.leavedDic[temp.Agv_ID] % Frm_A17168.businessCtrl.apiModel.requestSecond == 0)
{
@@ -821,8 +834,15 @@ namespace AGVSystem
// temp.Cross_Location_Go = location_temp;
// }
WriteTxt.SaveLog1("=========》(23):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
//登记第三方交管路口占用
TrafficModel trafficModel = Frm_A17168.autoLeavedDic.Find(_ => _.areaCode.Equals(location_temp.ToString()));
if (trafficModel != null)
{
trafficModel.agvId = temp.Agv_ID;
trafficModel.InArea = DateTime.Now;
}
WriteTxt.SaveLog1(location_temp.ToString() + "路口添加" + trafficModel?.areaCode + "(" + trafficModel.agvId + ")", "放行日志" + (temp.Agv_ID), "插件日志");
if (Link_To_PLC.WriteVW(2, 116, temp.Location_Display) == 0)
{
Frm_A17168.leavedDic[temp.Agv_ID] = 0;
@@ -840,23 +860,31 @@ namespace AGVSystem
//{
else if (Frm_A17168.businessCtrl.apiModel.leavedRfidList.Split(',').Contains(location_temp.ToString()))
{
WriteTxt.SaveLog1("=========》(24):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
if (Frm_A17168.businessCtrl == null) Frm_A17168.businessCtrl = new BusinessManage();
if (Frm_A17168.leavedDic == null) Frm_A17168.leavedDic = new Dictionary<int, int>();
if (!Frm_A17168.leavedDic.ContainsKey(temp.Agv_ID)) Frm_A17168.leavedDic.Add(temp.Agv_ID, 0);
bool flg = false;
WriteTxt.SaveLog1(location_temp.ToString() + "开始请求释放", "放行日志" + (temp.Agv_ID), "插件日志");
if (Frm_A17168.leavedDic[temp.Agv_ID] % Frm_A17168.businessCtrl.apiModel.requestSecond == 0)
{
flg = Frm_A17168.businessCtrl.ByLeaved(temp.Agv_ID.ToString(), location_temp.ToString(), lockCode.ToString());
flg = Frm_A17168.businessCtrl.ByLeaved(temp.Agv_ID.ToString(), location_temp.ToString(), (location_temp - 1).ToString());
WriteTxt.SaveLog1(location_temp.ToString() + "离开释放返回的值" + flg, "放行日志" + (temp.Agv_ID), "插件日志");
}
//归还
if (flg)
{
WriteTxt.SaveLog1("=========》(25):" + location_temp, temp.Agv_ID + "#Agv", "调试日志");
Frm_A17168.leavedDic[temp.Agv_ID] = 0;
temp.Cross_Location_Go = location_temp;
lockCode = location_temp;
//清除第三方交管路口占用
TrafficModel trafficModel2 = Frm_A17168.autoLeavedDic.Find(_ => _.areaCode.Equals(location_temp.ToString()));
if (trafficModel2 != null)
{
trafficModel2.agvId = 0;
}
WriteTxt.SaveLog1(location_temp.ToString() + "路口已归还", "放行日志" + (temp.Agv_ID), "插件日志");
}
Frm_A17168.leavedDic[temp.Agv_ID]++;
@@ -902,8 +930,11 @@ namespace AGVSystem
string sWarn = (Convert.ToString(WarnRead[0], 2).PadLeft(8, '0') + Convert.ToString(WarnRead[1], 2).PadLeft(8, '0')).PadLeft(64, '0');
Thread.Sleep(100);
Warn_Deal_Plc(temp, sWarn);
ThreadPool.QueueUserWorkItem(delegate
{
Thread.Sleep(100);
Warn_Deal_Plc(temp, sWarn);
});
#endregion
}
}
@@ -31,6 +31,14 @@ namespace AGVSystem
public static ClsDBConn_sql db_station = new ClsDBConn_sql();
public static ClsDBConn_sql db_Agv_Info = new ClsDBConn_sql();
public static BusinessManage businessCtrl;
/// <summary>
/// 第三方交管自动归还秒数
/// </summary>
public static int TraffAutoTimet = 0;
/// <summary>
/// 第三方交管路口占用列表
/// </summary>
public static List<TrafficModel> autoLeavedDic = new List<TrafficModel>();
public static Dictionary<int, int> leavedDic = new Dictionary<int, int>();
/// <summary>
/// Array_Station_Info [17,12]
@@ -111,6 +119,22 @@ namespace AGVSystem
mainfrm.Map2 = panel2;
mainfrm.Map3 = panel1;
businessCtrl = new BusinessManage();
//初始化第三方交管路口占用列表
if (businessCtrl != null && businessCtrl.apiModel != null)
{
TraffAutoTimet = businessCtrl.apiModel.AutoTime;
if (!string.IsNullOrEmpty(businessCtrl.apiModel.waitRfidList))
{
autoLeavedDic = new List<TrafficModel>();
foreach (string areaCode in businessCtrl.apiModel.waitRfidList.Split(','))
{
autoLeavedDic.Add(new TrafficModel
{
areaCode = areaCode
});
}
}
}
this.ControlBox = false;
this.Width = mainfrm.newmainfrm.ClientSize.Width - 5;
this.Height = mainfrm.newmainfrm.ClientSize.Height - 29 - 74 - 22 - 5;
@@ -304,6 +328,10 @@ namespace AGVSystem
Thread dbThread = new Thread(UPDateDBList.UpDateDb);
dbThread.IsBackground = true;
dbThread.Start();
//第三方交管自动归还监听线程
Thread trafficThread = new Thread(TrafficCtrl.Listen);
trafficThread.IsBackground = true;
trafficThread.Start();
//初始化小车控制线程
Cls.Param.th_GetData = new Thread[Cls.Param.AGV_Qty];
@@ -0,0 +1,65 @@
using System;
using System.Threading;
namespace AGVSystem.A17168
{
/// <summary>
/// 第三方交管自动归还路权监听
/// </summary>
public class TrafficCtrl
{
/// <summary>
/// 获取AGV当前地标
/// </summary>
private static int Agv_Land(int agvid)
{
for (byte b = 0; b < Func.AgvInfo.Length; b++)
{
if (Func.AgvInfo[b].Agv_ID == agvid)
{
return Func.AgvInfo[b].Location_Display;
}
}
return 0;
}
/// <summary>
/// 监听线程:占用超过AutoTime秒的路口自动归还路权
/// </summary>
public static void Listen()
{
while (true)
{
try
{
if (Frm_A17168.businessCtrl?.apiModel == null)
continue;
int autoTime = Frm_A17168.businessCtrl.apiModel.AutoTime;
if (autoTime == 0 || string.IsNullOrEmpty(Frm_A17168.businessCtrl.apiModel.waitRfidList) || Frm_A17168.autoLeavedDic == null || Frm_A17168.autoLeavedDic.Count <= 0)
continue;
foreach (TrafficModel item in Frm_A17168.autoLeavedDic)
{
if (item.agvId == 0)
continue;
if ((DateTime.Now - item.InArea).TotalSeconds > autoTime)
{
bool flag = Frm_A17168.businessCtrl.ByLeaved(item.agvId.ToString(), Agv_Land(item.agvId).ToString(), item.areaCode.ToString());
WriteTxt.SaveLog1(item.areaCode.ToString() + "自动释放,返回的值" + flag, "放行日志" + item.agvId, "插件日志");
if (flag)
{
Frm_A17168.leavedDic[item.agvId] = 0;
item.agvId = 0;
WriteTxt.SaveLog1(item.areaCode.ToString() + "路口已自动归还", "放行日志" + item.agvId, "插件日志");
}
}
}
}
catch (Exception ex)
{
WriteTxt.SaveLog1("第三方交管监听线程异常!" + ex.ToString(), "异常日志", "插件日志");
}
Thread.Sleep(1000);
}
}
}
}
@@ -0,0 +1,23 @@
using System;
namespace AGVSystem.A17168
{
/// <summary>
/// 第三方交管路口占用模型
/// </summary>
public class TrafficModel
{
/// <summary>
/// 路口(交汇区)地标编号
/// </summary>
public string areaCode { get; set; }
/// <summary>
/// 当前占用该路口的AGV编号,0=空闲
/// </summary>
public int agvId { get; set; }
/// <summary>
/// 进入路口时间
/// </summary>
public DateTime InArea { get; set; }
}
}