Commit e9591eda LN

极创接口对接

1 个父辈 9f488557
......@@ -233,5 +233,7 @@ namespace OnlineStore.Common
public static string door2 = "door2";
public static string openDoor= "openDoor";
public static string closeDoor= "closeDoor";
public static string boxCanPutIn = "boxCanPutIn";
}
}
......@@ -12,17 +12,15 @@ using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Reflection;
using log4net;
using System.Collections.Specialized;
using System.Net.NetworkInformation;
namespace OnlineStore.Common
{
{
public class HttpHelper
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static string Post(string url, string paramData)
{
return Post(url, paramData, Encoding.UTF8);
}
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open);
/// <summary>
///
/// </summary>
......@@ -65,17 +63,24 @@ namespace OnlineStore.Common
{
try
{
return JsonHelper.DeserializeJsonToObject<Operation>(result);
Operation operation1 = JsonHelper.DeserializeJsonToObject<Operation>(result);
if (isLog == 1)
{
LOGGER.Info("Post【" + url + "】【" + json + "】收到【" + result + "】");
}
else if (operation1 != null && operation1.op > 0)
{
LOGGER.Info("Post【" + url + "】【" + json + "】收到【" + result + "】");
}
return operation1;
}
catch (Exception ex)
{
LOGGER.Error("JsonHelper.DeserializeJsonToObject 出错【result=" + result + "】" + ex);
}
}
if (isLog == 1)
{
LOGGER.Info("Post【" + url + "】【" + json + "】收到【" + result + "】");
}
}
}
catch (Exception ex)
......@@ -84,17 +89,32 @@ namespace OnlineStore.Common
}
return null;
}
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open);
public static string Post(string url, string paramData, Encoding encoding)
public static bool PingURLIP(string url, int ms = 100)
{
//if (isLog == 1)
//{
// LOGGER.Info("给服务器发送数据【" + paramData + "】 ");
//}
if (paramData != "null" && paramData != null)
string[] urlArray = url.Split('/');
if (urlArray.Length > 3)
{
// LogUtil.debug(LOGGER, "HTTP POST to " + url + " \n\t >> " + paramData);
string ip = urlArray[2];
Ping pingSender = new Ping();
PingReply reply = pingSender.Send(ip, ms);//第一个参数为ip地址,第二个参数为ping的时间
if (reply.Status == IPStatus.Success)
{
//通
return true;
}
else
{
LogUtil.error(LOGGER,"Ping IP " + ip + " : false");
//不通
return false;
}
}
return true;
}
public static string Post(string url, NameValueCollection paramData, int timeOut = 10000)
{
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
......@@ -105,53 +125,140 @@ namespace OnlineStore.Common
try
{
var wc = new MyWebClient(5000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
using (var wc = new MyWebClient(timeOut))
{
byte[] buf = wc.UploadValues(url, "POST", paramData);
result = Encoding.UTF8.GetString(buf);
}
//LogUtil.info(result);
}
catch (Exception e)
{
LogUtil.error(LOGGER, "POST ERROR:" + e.StackTrace, 1);
LogUtil.error(LOGGER,"POST ERROR:" + e.ToString() + "\r\n" + url, 101);
}
return result;
}
public static string Post(string url, string paramData, int timeOut = 10000)
{
return Post(url, paramData, Encoding.UTF8, timeOut);
}
public static string Post(string url, string paramData, Encoding encoding, int timeOut = 10000)
{
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
if (!result.Contains("null") && result.Length != 0)
try
{
//LogUtil.debug(LOGGER,"receive << " + result);
using (var wc = new MyWebClient(timeOut))
{
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
{
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
}
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
}
//LogUtil.info(result);
}
if (isLog == 1)
catch (Exception e)
{
LOGGER.Info("Post【"+ url + "】【"+ paramData + "】收到【" + result + "】");
LogUtil.error(LOGGER,"POST ERROR:" + e.ToString() + "\r\n" + url, 101);
}
return result;
}
static object lockpost = new object();
public static Operation Post(string url, Operation operation, int timeout = 5000, bool printlog = false)
{
try
{
string json = JsonHelper.SerializeObject(operation);
string result = Post(url, json, timeout);
Operation op = JsonHelper.DeserializeJsonToObject<Operation>(result);
if (printlog)
{
LogUtil.info("Send [" + json + "] Revice [" + result + "]");
}
return op;
}
catch (Exception ex)
{
LogUtil.error(LOGGER,"Post 出错【operation.op=" + operation.op + "】:" + ex);
}
return null;
}
public static string Get(string url)
{
return Get(url, Encoding.UTF8);
}
public static string Get(string url, Encoding encoding)
public static string Get(string url, Encoding encoding, int timeOut = 10000)
{
try
{
LogUtil.info(LOGGER, "HTTP GET FROM: " + url);
var wc = new WebClient { Encoding = encoding };
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
LogUtil.debug("HTTP GET FROM: " + url);
using (var wc = new MyWebClient { Encoding = encoding })
{
var result = sr.ReadToEnd();
LogUtil.info(LOGGER, "receive << " + result);
return result;
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
{
var result = sr.ReadToEnd();
LogUtil.debug("receive << " + result);
return result;
}
}
}
catch (Exception e)
{
LogUtil.error(LOGGER, "HTTP GET ERROR:" + e.Message, 2);
LogUtil.error(LOGGER,"HTTP GET ERROR:" + e.Message, 102);
}
return "";
}
public static string PostJson(string url, Dictionary<string, string> paramDataMap, Encoding encoding, int timeOut = 10000)
{
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
try
{
string paramData = JsonHelper.SerializeObject(paramDataMap);
using (var wc = new MyWebClient(timeOut))
{
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
{
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
}
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
}
//LogUtil.info(result);
}
catch (Exception e)
{
LogUtil.error(LOGGER,"POST ERROR:" + e.ToString() + "\r\n" + url, 101);
}
return result;
}
}
}
\ No newline at end of file
......@@ -51,6 +51,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
......@@ -69,6 +70,7 @@
<Compile Include="IO\IOManager.cs" />
<Compile Include="IO\KangNaiDe\KNDManager.cs" />
<Compile Include="IO\KangNaiDe\MasterTcpClient.cs" />
<Compile Include="manager\HttpServer.cs" />
<Compile Include="PanasonicServo\ACCMDManager.cs" />
<Compile Include="PanasonicServo\ACServerManager.cs" />
<Compile Include="PanasonicServo\ACServerManager_Partial.cs" />
......
......@@ -1616,13 +1616,40 @@ namespace OnlineStore.DeviceLibrary
}
lineOperation.boxStatus.Add(1, boxStatus);
//1 定时通信data里面添加boxCanPutIn字段表示箱子是否可放上入库线体, 值为字符串"TRUE"时表示可放, 其他为不可放
if (!alarmType.Equals(StoreAlarmType.None))
{
lineOperation.alarmList.Add(alarmInfo);
}
//1 定时通信data里面添加 boxCanPutIn 字段表示箱子是否可放上入库线体, 值为字符串"TRUE"时表示可放, 其他为不可放
string canput = BoxCanPutIn() ? "TRUE" : "FALSE";
lineOperation.data.Add("boxCanPutIn", canput);
return lineOperation;
}
private bool BoxCanPutIn()
{
if (storeRunStatus< StoreRunStatus.Runing)
{
return false;
}
if (StoreMove.MoveType.Equals(StoreMoveType.OutStore))
{
return false;
}
else if (IOManager.IOValue(IO_Type.LeftShelf_Check).Equals(IO_VALUE.HIGH))
{
return false;
}
else if (IOManager.IOValue(IO_Type.RightShelf_Check).Equals(IO_VALUE.HIGH))
{
return false;
}
return true;
}
public void SendLineStatus()
{
DateTime time = DateTime.Now;
......
using OnlineStore.Common;
using DeviceLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
......@@ -434,6 +435,9 @@ namespace OnlineStore.DeviceLibrary
StoreMove.NextMoveStep(StoreMoveStep.SI_09_MiddleToP3);
InStoreLog("入库: 移动到安全点,前后轴至安全点, [" + moveP.MiddleAxis_Safe_Position + "]");
ACAxisMove(Config.Middle_Axis, moveP.MiddleAxis_Safe_Position, Config.MiddleAxis_P1_Speed);
InStoreLog("堆垛机取货完成, 通知极创");
HttpServer.ddjPickUpGoodsNotice(StoreMove.MoveParam.PosInfo.PosId);
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_09_MiddleToP3)
......@@ -495,6 +499,10 @@ namespace OnlineStore.DeviceLibrary
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
ACAxisMove(Config.Middle_Axis, moveP.MiddleAxis_Safe_Position, Config.MiddleAxis_P1_Speed);
ShelfForward(StoreMove.MoveParam.PosInfo.ShelfType);
InStoreLog("料箱放入库位完成, 通知极创");
HttpServer.inStorageFeedback(StoreMove.MoveParam.PosInfo.PosId);
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_15_UpdownBack)
......@@ -753,10 +761,43 @@ namespace OnlineStore.DeviceLibrary
}
if (StoreMove.MoveParam.PosInfo.ShelfType > 0)
{
//StoreMove.NextMoveStep(StoreMoveStep.SO_12_InoutToP2);
//OutStoreLog("出库: 叉子进出料口,进出轴至P2(进料口取料点) [" + moveP.InOut_P2 + "] ");
//ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
string msg = HttpServer.outIsReady(CID, StoreMove.MoveParam.PosInfo.PosId);
if (msg == "")
{
StoreMove.NextMoveStep(StoreMoveStep.SO_12_InoutToP2);
OutStoreLog("出库: 叉子进出料口,进出轴至P2(进料口取料点) [" + moveP.InOut_P2 + "] ");
ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
}
else
{
WarnMsg = "查询接驳线体放料结果:"+msg;
StoreMove.NextMoveStep(StoreMoveStep.SO_12_WaitCanPut);
OutStoreLog($"出库: 出库时查询接驳线体是否可以放料箱 失败{msg}:等待2秒重新查询 ");
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
}
}else if(StoreMove.MoveStep== StoreMoveStep.SO_12_WaitCanPut)
{
string msg = HttpServer.outIsReady(CID, StoreMove.MoveParam.PosInfo.PosId);
if (msg == "")
{
if (WarnMsg.Contains("查询接驳线体放料结果"))
{
WarnMsg = "";
}
StoreMove.NextMoveStep(StoreMoveStep.SO_12_InoutToP2);
OutStoreLog("出库: 叉子进出料口,进出轴至P2(进料口取料点) [" + moveP.InOut_P2 + "] ");
ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
}
else
{
StoreMove.NextMoveStep(StoreMoveStep.SO_12_WaitCanPut);
OutStoreLog($"出库: 出库时查询接驳线体是否可以放料箱 失败{msg}:等待2秒重新查询 ");
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
}
else if (StoreMove.MoveStep == StoreMoveStep.SO_12_InoutToP2)
{
......@@ -794,6 +835,10 @@ namespace OnlineStore.DeviceLibrary
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
OpenDoor(StoreMove.MoveParam.PosInfo.ShelfType);
ShelfForward(StoreMove.MoveParam.PosInfo.ShelfType, StoreMove);
InStoreLog("堆垛机放货完成反馈, 通知极创");
HttpServer.ddjReleaseTheGoodsNotice(StoreMove.MoveParam.PosInfo.PosId);
}
else if (StoreMove.MoveStep == StoreMoveStep.SO_16_GoBack)
{
......

using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace DeviceLibrary
{
public class HttpServer
{
public HttpServer()
{
}
private static string Addr_ddjPickUpGoodsNotice = "/rest/api/v2/803/service/store/xl/ddjPickUpGoodsNotice";//堆垛机取货完成, 通知极创
private static string Addr_inStorageFeedback = "/rest/api/v2/803/service/store/xl/inStorageFeedback";//料箱放入库位完成, 通知极创
private static string Addr_outIsReady = "/rest/api/v2/803/service/store/xl/outIsReady";//出库时查询接驳线体是否可以放料箱
private static string Addr_ddjReleaseTheGoodsNotice = "/rest/api/v2/803/service/store/xl/ddjReleaseTheGoodsNotice";//堆垛机放货完成反馈
// ## 入库:
//1 定时通信data里面添加boxCanPutIn字段表示箱子是否可放上入库线体, 值为字符串"TRUE"时表示可放, 其他为不可放
//2 堆垛机取货完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/ddjPickUpGoodsNotice
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
//3 料箱放入库位完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/inStorageFeedback
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
//4 出库时查询接驳线体是否可以放料箱
// http://localhost/rest/api/v2/803/service/store/xl/outIsReady
//请求参数:
//{
//"cid": "001",
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
//5 堆垛机放货完成反馈
//http://localhost/rest/api/v2/803/service/store/xl/ddjReleaseTheGoodsNotice
//请求参数:
//{
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap = null)
{
if (paramsMap == null)
{
paramsMap = new Dictionary<string, string>();
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
//server = "http://192.168.1.37:8800/";
if (server.EndsWith("/"))
{
server = server.Substring(0, server.Length - 1);
}
string path = server + addr.Trim() + "?";
foreach (string paramName in paramsMap.Keys)
{
string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
path += paramName + "=" + par + "&";
}
path = path.Substring(0, path.Length - 1);
return path;
}
private static string getData(Dictionary<string, Object> data, string key)
{
if (data.ContainsKey(key))
{
return data[key].ToString().Trim();
}
return "";
}
private static int getIntData(Dictionary<string, Object> data, string key, int defValue = -1)
{
try
{
return Int32.Parse(getData(data, key));
}
catch (Exception ex)
{
}
return -1;
}
private static string PostJson(Dictionary<string, string> paramMap, string addr, string logName, bool needLog = true)
{
DateTime startTime = DateTime.Now;
try
{
string url = GetAddr(addr);
string json = HttpHelper.PostJson(url, paramMap, Encoding.UTF8, 2000);
if (needLog)
{
LogUtil.info("http :URL:" + url + " :Response:" + json + " 耗时[" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "]");
}
else
{
LogUtil.debug("http :URL:" + url + " :Response:" + json + " 耗时[" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "]");
}
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(json);
if (data == null)
{
return "未收到服务器反馈";
}
else if (data.code == 0)
{
return "";
}
else
{
LogUtil.error(logName + ": 结果:code=" + data.code + ",msg=" + data.msg);
return data.msg;
}
}
catch (Exception ex)
{
LogUtil.error(logName + " error : " + ex.ToString());
return ex.ToString();
}
}
/// <summary>
/// 堆垛机取货完成, 通知极创
/// </summary>
/// <param name="posName"></param>
/// <returns></returns>
public static string ddjPickUpGoodsNotice(string posName)
{
//2 堆垛机取货完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/ddjPickUpGoodsNotice
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
return PostJson(paramMap, Addr_ddjPickUpGoodsNotice, "ddjPickUpGoodsNotice", true);
}
/// <summary>
/// 料箱放入库位完成, 通知极创
/// </summary>
/// <param name="posName"></param>
/// <returns></returns>
public static string inStorageFeedback(string posName)
{
//3 料箱放入库位完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/inStorageFeedback
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
return PostJson(paramMap, Addr_inStorageFeedback, "inStorageFeedback", true);
}
/// <summary>
/// 出库时查询接驳线体是否可以放料箱
/// </summary>
/// <param name="cid"></param>
/// <param name="boxCode"></param>
/// <returns></returns>
public static string outIsReady(string cid, string boxCode)
{
//4 出库时查询接驳线体是否可以放料箱
// http://localhost/rest/api/v2/803/service/store/xl/outIsReady
//请求参数:
//{
//"cid": "001",
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("cid", cid);
paramMap.Add("boxCode", boxCode);
return PostJson(paramMap, Addr_outIsReady, "outIsReady", true);
}
/// <summary>
/// 堆垛机放货完成反馈
/// </summary>
/// <param name="boxCode"></param>
/// <returns></returns>
public static string ddjReleaseTheGoodsNotice(string boxCode)
{
//5 堆垛机放货完成反馈
//http://localhost/rest/api/v2/803/service/store/xl/ddjReleaseTheGoodsNotice
//请求参数:
//{
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("boxCode", boxCode);
return PostJson(paramMap, Addr_ddjReleaseTheGoodsNotice, "ddjReleaseTheGoodsNotice", true);
}
}
public class ResultData
{
public int code { get; set; }
public string msg { get; set; }
public object data { get; set; }
}
}
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
namespace DeviceLibrary
{
public class ServerCommunication
{
private static string server = Setting_Init.Device_Server_Address;
public string CID;
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
object serverclock = new object();
public ServerCommunication( )
{
CID = "line";
serverConnectTimer.Interval =2000;
serverConnectTimer.AutoReset = true;
serverConnectTimer.Enabled = false;
serverConnectTimer.Elapsed += ServerConnectTimer_Elapsed;
GC.KeepAlive(serverConnectTimer);
LogUtil.info($"server:{server},cid:{CID}");
InitModuleMap();
}
private void ServerConnectTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
if (!RobotManage.isRunning)
{
return;
}
if (!string.IsNullOrEmpty(server))
{
SendLineStatus();
}
}
catch (Exception ex)
{
LogUtil.info($"ServerConnectTimer_Elapsed:{ex}");
}
}
public void StartConnectServer() {
serverConnectTimer.Enabled = true;
}
public void StopConnectServer() {
serverConnectTimer.Enabled = false;
}
private static string api_communication = "service/equipment/communication"; //流水线状态通信接口
public static string GetPostApi(string api)
{
var host = server;
if (!host.StartsWith("http://"))
{
host = "http://" + host;
}
if (!host.EndsWith("/"))
{
host = host + "/";
}
if (api.StartsWith("/"))
{
api = api.Substring(1);
}
return host + api;
}
private List<EquipMsg> otherEquipMsg = new List<EquipMsg>();
public void AddWarnMsg(string errorCode, string moudle,string msg,string type= "WARNING")
{
otherEquipMsg.Add(EquipMsg.newMsg(errorCode, moudle,msg,type));
}
private List<EquipMsg> alarmMsgList = new List<EquipMsg>();
public void AddAlarmMsg(string errorCode, string moudle, string msg,string type="ERROR")
{
alarmMsgList.Add(EquipMsg.newMsg(errorCode, moudle, msg ,type));
}
private Dictionary<string, string> msgMoudleMap =null;
public void InitModuleMap()
{
if (msgMoudleMap == null)
{
msgMoudleMap = new Dictionary<string, string>();
msgMoudleMap.Add("2000", "line");
msgMoudleMap.Add("2010", "MU1");
msgMoudleMap.Add("2011", "MU1_1");
msgMoudleMap.Add("2012", "MU1_2");
msgMoudleMap.Add("2020", "MU2");
msgMoudleMap.Add("2021", "MU2_1");
msgMoudleMap.Add("2030", "MU3_1");
msgMoudleMap.Add("2040", "MU4");
msgMoudleMap.Add("2041", "MU4_1");
msgMoudleMap.Add("2042", "MU4_2");
msgMoudleMap.Add("2050", "MU5");
msgMoudleMap.Add("2051", "MU5_1");
msgMoudleMap.Add("2052", "MU5_2");
}
}
public void AddMsgList(List<Msg> msgs)
{
try
{
foreach (Msg msg in msgs)
{
string moudle = "line";
if (msg.msgtxt == "")
{
continue;
}
string pattern = @"\d+秒";
string replacement = "";
string msgStr = Regex.Replace(msg.msgtxt, pattern, replacement);
string regex = "\\[\\d+\\.\\d+\\]秒";
msgStr = Regex.Replace(msgStr, regex, "");
regex = "\\[\\d+\\]秒";
msgStr = Regex.Replace(msgStr,regex, "");
//已存在的不重复发送
int count = (from m in alarmMsgList where m.msg.Equals(msgStr) select m).ToList().Count();
if (count >=1)
{
continue;
}
foreach (string key in msgMoudleMap.Keys)
{
if (msg.alarmCode.StartsWith(key))
{
moudle = msgMoudleMap[key];
}
}
if (msg.msgLevel.Equals(MsgLevel.warning))
{
AddAlarmMsg(msg.alarmCode, moudle, msgStr, "WARNING");
}
else if (msg.msgLevel.Equals(MsgLevel.info))
{
AddAlarmMsg(msg.alarmCode, moudle, msgStr, "INFO");
}
else
{
AddAlarmMsg(msg.alarmCode, moudle, msgStr);
}
}
}
catch (Exception ex)
{
LogUtil.error("AddAlarmMsg 出错:" + ex.ToString());
}
}
public void SendLineStatus()
{
if (Monitor.TryEnter(serverclock, 10))
{
try
{
bool printlog = false;
DateTime time = DateTime.Now;
//构建发送给服务器的对象
EquipStatusBean bean = new EquipStatusBean();
bean.cid = CID;
bean.seq = ConfigAppSettings.nextSeq();
List<EquipMsg> equipMsgs = new List<EquipMsg>();
//List<MoveInfo> moves = MoveInfo.allList();
//foreach (MoveInfo move in moves)
//{
// if (string.IsNullOrEmpty(move.lasterrmsg))
// {
// TimeSpan span = DateTime.Now - move.lastErrmsgTime;
// if (span.TotalSeconds <= 3)
// {
// string pattern = @"\d+秒";
// string replacement = "";
// string output = Regex.Replace(move.lasterrmsg, pattern, replacement);
// //三秒内的就发送
// EquipMsg msg = EquipMsg.newMsg(move.Name, output);
// equipMsgs.Add(msg);
// }
// }
//}
equipMsgs.AddRange(otherEquipMsg);
equipMsgs.AddRange(alarmMsgList);
otherEquipMsg = new List<EquipMsg>();
alarmMsgList = new List<EquipMsg>();
//如果在暂停中,需要设置报警状态
List<StatusInfo> list = GetStatuses(equipMsgs);
bean.msgList = equipMsgs;
bean.statusList = list;
EquipStatusBean result = HttpHelper.Post(GetPostApi(api_communication), bean, 1000, printlog);
//暂无处理
}
catch (Exception e)
{
LogUtil.error("SendLineStatus 出错: " + e.ToString());
}
finally
{
Monitor.Exit(serverclock);
}
}
}
private List<StatusInfo> GetStatuses(List<EquipMsg> msgList)
{
List<string> muNames = new List<string>() { "MU1_1", "MU1_2", "MU2_1", "MU3_1", "MU4_1", "MU4_2", "MU5_1", "MU5_2" };
Dictionary<string, int> sMap = new Dictionary<string, int>();
try
{
//如果是正在暂停中,状态为报警
// 0=离线,1=正常运行中, 2=急停, 3=故障(气压检测不到等,用msg发送详细故障说明)
foreach (string name in muNames)
{
List<EquipMsg> msg = (from m in msgList where m.module.Equals(name) select m).ToList();
if (msg.Count > 0)
{
UpdateS(sMap, name, 3);
}
}
foreach (UMEquipBase mu in RobotManage.UMEquipMap.Values)
{
int s = 1;
if (mu.runStatus == RunStatus.Stop)
{
s = 0;
}
else if (mu.isInSuddenDown)
{
s = 2;
}
if (mu.UMLine1 != null)
{
bool result1 = UpdateS(sMap, mu.UMLine1.Name, s);
if (!result1 && s == 2)
{
EquipMsg msg = EquipMsg.newMsg(mu.UMLine1.alarmCode + "0006", mu.UMLine1.Name, $"{mu.Name}急停中");
msgList.Add(msg);
}
}
if (mu.UMLine2 != null)
{
bool result2 = UpdateS(sMap, mu.UMLine2.Name, s);
if (!result2 && s == 2)
{
EquipMsg msg = EquipMsg.newMsg(mu.UMLine2.alarmCode + "0006", mu.UMLine2.Name, $"{mu.Name}急停中");
msgList.Add(msg);
}
}
}
int mu3s = 1;
if (RobotManage.uM1Equip.runStatus == RunStatus.Stop)
{
mu3s = 0;
}
else if (RobotManage.uM1Equip.isInSuddenDown)
{
mu3s = 2;
}
bool result = UpdateS(sMap, "MU3_1", mu3s);
if (!result && mu3s == 2)
{
EquipMsg msg = EquipMsg.newMsg("20300006", "MU3_1", $"MU3_1急停中");
msgList.Add(msg);
}
foreach (MoveInfo moveInfo in MoveInfo.allList())
{
if (moveInfo.isAlarmStop)
{
List<string> muList = getMuNameList(moveInfo.Name);
if (muList.Count > 0)
{
foreach (string n in muList)
{
if (!UpdateS(sMap, n, 3))
{
EquipMsg msg = EquipMsg.newMsg("20" + n.Replace("MU", "").Replace("_", "") + "0005", n, $"{moveInfo.Name} 暂停中");
msgList.Add(msg);
}
}
}
}
}
}
catch (Exception ex)
{
LogUtil.error("获取出料口状态出错:" + ex.ToString());
}
List<StatusInfo> list = new List<StatusInfo>();
foreach (string key in sMap.Keys)
{
int v = sMap[key];
list.Add(new StatusInfo() { module = key, status = v });
}
return list;
}
private List<string> getMuNameList(string mName)
{
List<string> result = new List<string>();
if (mName.StartsWith("MU3"))
{
result.Add("MU3");
return result;
}
List<string> muNames = new List<string>() { "MU1_1", "MU1_2", "MU2_1", "MU3_1", "MU4_1", "MU4_2", "MU5_1", "MU5_2" };
foreach (string muName in muNames)
{
if (mName.StartsWith(muName))
{
result.Add(mName);
return result;
}
}
foreach (UMEquipBase mu in RobotManage.UMEquipMap.Values)
{
if (mName.StartsWith(mu.Name))
{
if (mu.UMLine1 != null)
{
result.Add(mu.UMLine1.Name);
}
if (mu.UMLine2 != null)
{
result.Add(mu.UMLine2.Name);
}
return result;
}
}
return result;
}
private bool UpdateS(Dictionary<string,int> sMap,string name,int s )
{
if(sMap.ContainsKey(name))
{
if (sMap[name] ==2||s==2) {
sMap[name] = 2;
}else if (sMap[name] < s)
{
sMap[name] = s;
}
sMap[name] = s;
return true ;
}
else
{
sMap.Add(name, s);
return false ;
}
}
}
}
\ No newline at end of file
......@@ -223,7 +223,13 @@ namespace OnlineStore.DeviceLibrary
SO_12_WaitNoTray=112,
/// <summary>
/// 等待可以放到出料口
/// </summary>
SO_12_WaitCanPut = 113,
/// <summary>
/// 出库:叉子进出料口,,轴3( 叉子) 至P2( 进料口取料点)
/// /// </summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!