Commit f571fc94 顾剑亮

debug

1 个父辈 5badfd23
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
<Reference Include="System.ServiceModel" /> <Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Activation" /> <Reference Include="System.ServiceModel.Activation" />
<Reference Include="System.ServiceModel.Web" /> <Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
......
...@@ -77,76 +77,15 @@ namespace BLL ...@@ -77,76 +77,15 @@ namespace BLL
info.StateText = stateText; info.StateText = stateText;
info.Battery = battery; info.Battery = battery;
info.MissionText = missionText; info.MissionText = missionText;
//info.Position = position; info.Position = position;
CheckStandTimeOut(info,position);
UpdateDisplayBoard(info);
string ip = info.IP; string ip = info.IP;
int idx = Common.agvInfos.FindIndex(s => s.IP == ip); int idx = Common.agvInfos.FindIndex(s => s.IP == ip);
if (idx > -1) AgvChanged?.Invoke(idx); if (idx > -1) AgvChanged?.Invoke(idx);
} }
} }
/// <summary>
/// 检查小车是否在原地停留超时
/// </summary>
/// <returns></returns>
private void CheckStandTimeOut(AgvInfo agv,System.Drawing.PointF position)
{
if (agv.IsCall && agv.CurrentJob != null && !(agv.CurrentJob is ChargeJob) && !(agv.CurrentJob is StandbyJob))//!CurTaskName.Contains(SettingString.AutoCharge) ||
{
if (Math.Abs(position.X - agv.Position.X) < 1 && Math.Abs(position.Y - agv.Position.Y) < 1)
{
//满足条件,计算持续时间
if (agv.StandStartTime == DateTime.MaxValue)
{
agv.StandStartTime = DateTime.Now;
}
TimeSpan lastTimeSpan = DateTime.Now - agv.StandStartTime;
agv.StandTimeOut = (lastTimeSpan.TotalMinutes >= agv.StandLastTimeMinute);
}
else
{
//重新计时
agv.StandStartTime = DateTime.Now;
agv.StandTimeOut = false;
}
}
else if (agv.CurrentJob != null && ((agv.CurrentJob is ChargeJob)|| (agv.CurrentJob is StandbyJob)))
{
agv.StandTimeOut = false;
agv.StandStartTime = DateTime.Now;
}
else
{
agv.StandTimeOut = false;
agv.StandStartTime = DateTime.Now;
}
agv.Position = position;
}
private void UpdateDisplayBoard(AgvInfo agv)
{
try
{
if (agv.StandTimeOut)
{
// isAlarm = true;
agv.DisplayBoard.Add(agv.Name, "lineAgv." + agv.Name + ".StandTimeOut", "在" + agv.Place + "停留超时" + (DateTime.Now - agv.StandStartTime).TotalMinutes.ToString("f2") + "分钟");
}
if ((int)StateID.Error == agv.StateID || (int)StateID.EmergencyStop == agv.StateID || (int)StateID.Pause == agv.StateID)
{
//isAlarm = true;
agv.DisplayBoard.Add(agv.Name, "lineAgv." + agv.Name + ".Error.EmergencyStop", "agv状态:" + agv.StateText);
}
agv.DisplayBoard.UpdateAlarmMsg();
}
catch (Exception ex)
{
Common.log.Error(agv.Name + "上报小车信息失败",ex);
}
}
private void CheckAgvOnline(ref AgvInfo info) private void CheckAgvOnline(ref AgvInfo info)
{ {
bool rtn = Common.mir.CheckIP(info.IP); bool rtn = Common.mir.CheckIP(info.IP);
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AGVControl;
using Model;
namespace AGVControl
{
public class AGVManager
{
private static string Addr_updateDeviceAlarmMsg = "/rest/api/qisda/device/updateDeviceAlarmMsg";
/// <summary>
/// 异常看板
/// </summary>
/// <param name="msgList"></param>
/// <returns></returns>
public static string updateDeviceAlarmMsg(List<AlarmMsg> msgList)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
string msgListStr = JsonHelper.SerializeObject(msgList);
paramMap.Add("deviceAlarmList", msgListStr);
string server = GetAddr(Addr_updateDeviceAlarmMsg, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
Common.log.Debug("updateDeviceAlarmMsg " + " 【" + server + "】【" + resultStr + "】");
RfidData data = JsonHelper.DeserializeJsonToObject<RfidData>(resultStr);
if (data == null)
{
return msg = " updateDeviceAlarmMsg 没有收到服务器反馈";
}
else if (data.code.Equals(0).Equals(false))
{
return msg = " updateDeviceAlarmMsg 【" + server + "】【" + resultStr + "】" + data.msg;
}
return "";
}
catch (Exception ex)
{
Common.log.Error("updateDeviceAlarmMsg",ex);
}
return msg;
}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
string server = "http://10.85.199.25/myproject/";
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;
}
}
public class AlarmMsg
{
//>>>name : 异常位置名称
public string name = "";
//>>>msgKey : 异常信息唯一标识
public string msgKey = "";
//>>>msgValue : 异常信息
public string msgValue = "";
public int type;
/// <summary>
/// 异常信息
/// </summary>
/// <param name="name">异常位置名称</param>
/// <param name="key">异常信息唯一标识</param>
/// <param name="value">异常信息</param>
public AlarmMsg(string name, string key, string value,int type=0)
{
this.name = name;
this.msgKey = key;
this.msgValue = value;
this.type = type;
}
}
public class RfidData
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
public Dictionary<string, string> data { get; set; }
}
}
using AGVControl; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -82,10 +81,7 @@ namespace Model ...@@ -82,10 +81,7 @@ namespace Model
public int NewSteel { set; get; } = 0; public int NewSteel { set; get; } = 0;
/// <summary>
/// 看板信息
/// </summary>
public DisplayBoard DisplayBoard;
...@@ -146,13 +142,5 @@ namespace Model ...@@ -146,13 +142,5 @@ namespace Model
else else
return false; return false;
} }
public int StandLastTimeMinute = 5;
public DateTime StandStartTime = DateTime.MaxValue;
/// <summary>
/// 停在同一处超时
/// </summary>
public bool StandTimeOut = false;
} }
} }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AGVControl
{
public class DisplayBoard
{
/// <summary>
/// 异常列表
/// </summary>
public List<AlarmMsg> MsgList { get; private set; }
/// <summary>
/// 看板类
/// </summary>
public DisplayBoard()
{
MsgList = new List<AlarmMsg>();
}
/// <summary>
/// 添加上报信息
/// </summary>
/// <param name="name"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="type">默认类型是异常,1表示正常信息</param>
public void Add(string name, string key, string value, int type = 0)
{
MsgList.Add(new AlarmMsg(name, key, value, type));
}
private void ClearAlram()
{
if (MsgList != null && MsgList.Count > 0)
MsgList.Clear();
}
public void UpdateAlarmMsg()
{
if (MsgList != null && MsgList.Count > 0)
{
AGVManager.updateDeviceAlarmMsg(MsgList);
ClearAlram();
}
}
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections;
using System.Net;
using System.Net.Security;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Reflection;
using System.Net.NetworkInformation;
using MiR;
using AGVControl;
namespace AGVControl
{
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);
}
//public static bool PingURLIP(string url, int ms=100)
//{
// string[] urlArray = url.Split('/');
// if (urlArray.Length > 3)
// {
// string ip = urlArray[2];
// Ping pingSender = new Ping();
// PingReply reply = pingSender.Send(ip, ms);//第一个参数为ip地址,第二个参数为ping的时间
// if (reply.Status == IPStatus.Success)
// {
// //通
// return true;
// }
// else
// {
// //不通
// return false;
// }
// }
// return true;
//}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <param name="operation"></param>
/// <param name="simulate">是否模拟服务器返回结果</param>
/// <returns></returns>
//public static Operation Post(string url, Operation operation, bool simulate)
//{
// try
// {
// ////如果Op=0或者Op=5,先拼Ip,不通不发送
// //if (operation.op < 0 || operation.op.Equals(5))
// //{
// // if (PingURLIP(url, 100).Equals(false))
// // {
// // return null;
// // }
// //}
// if (simulate)
// {//模拟服务器返回
// operation.status = 200;
// operation.data.Clear();
// operation.data.Add("posId", "A001");
// string pos = "D100-111#D102-222#D104-333";
// operation.data.Add("pos", pos);
// if (operation.op == 1 || operation.op == 2)
// {//入库或出库
// string json = JsonHelper.SerializeObject(operation);
// LogUtil.error("模拟HTTP服务器返回出库入库信息:" + json);
// return operation;
// }
// }
// else
// {
// string json = "";
// try
// {
// json = JsonHelper.SerializeObject(operation);
// }
// catch (Exception ex)
// {
// LogUtil.error("JsonHelper.SerializeObject(operation) 出错【operation.op=" + operation.op + "】" + ex);
// }
// string result = Post(url, json);
// if (!string.IsNullOrEmpty(result))
// {
// try
// {
// return JsonHelper.DeserializeJsonToObject<Operation>(result);
// }
// catch (Exception ex)
// {
// LogUtil.error("JsonHelper.DeserializeJsonToObject 出错【result=" + result + "】" + ex);
// }
// }
// }
// }
// catch (Exception ex)
// {
// LogUtil.error("Post 出错【operation.op=" + operation.op + "】:" + ex);
// }
// return null;
//}
public static string LastServerMsg = "";
public static string Post(string url, string paramData, Encoding encoding)
{
//if (PingURLIP(url, 100).Equals(false))
//{
// return null;
//}
if (paramData != "null" && paramData != null)
{
// LogUtil.debug(LOGGER, "HTTP POST to " + url + " \n\t >> " + paramData);
}
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
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);
//Common.LogInfo(result);
}
catch (Exception e)
{
Common.log.Error("POST ERROR:" + e.ToString());
}
if (!result.Contains("null") && result.Length != 0)
{
//LogUtil.debug(LOGGER,"receive << " + result);
}
LastServerMsg = DateTime.Now.ToLongTimeString() + " URL:" + url + "\r\n"
+ "发送:" + paramData + "\r\n"
+ "接收:" + result + "\r\n"
;
return result;
}
public static string Get(string url)
{
return Get(url, Encoding.UTF8);
}
public static string Get(string url, Encoding encoding)
{
try
{
Common.log.Debug("HTTP GET FROM: " + url);
var wc = new WebClient { Encoding = encoding };
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
{
var result = sr.ReadToEnd();
Common.log.Debug("receive << " + result);
return result;
}
}
catch (Exception e)
{
Common.log.Error("HTTP GET ERROR:" + e.Message);
}
return "";
}
}
}
\ No newline at end of file \ No newline at end of file
using AGVControl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace AGVControl
{
/// <summary>
/// Json帮助类
/// </summary>
public class JsonHelper
{
/// <summary>
/// 将对象序列化为JSON格式
/// </summary>
/// <param name="o">对象</param>
/// <returns>json字符串</returns>
public static string SerializeObject(object o)
{
string json = JsonConvert.SerializeObject(o);
return json;
}
/// <summary>
/// 解析JSON字符串生成对象实体
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
/// <returns>对象实体</returns>
public static T DeserializeJsonToObject<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
T t = o as T;
return t;
}
/// <summary>
/// 解析JSON数组生成对象实体集合
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json数组字符串(eg.[{"ID":"112","Name":"石子儿"}])</param>
/// <returns>对象实体集合</returns>
public static List<T> DeserializeJsonToList<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
List<T> list = o as List<T>;
return list;
}
/// <summary>
/// 反序列化JSON到给定的匿名对象.
/// </summary>
/// <typeparam name="T">匿名对象类型</typeparam>
/// <param name="json">json字符串</param>
/// <param name="anonymousTypeObject">匿名对象</param>
/// <returns>匿名对象</returns>
public static T DeserializeAnonymousType<T>(string json, T anonymousTypeObject)
{
T t = JsonConvert.DeserializeAnonymousType(json, anonymousTypeObject);
return t;
}
/// <summary>
///写入JSON文件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ts"></param>
/// <param name="fileName"></param>
public static void WriteJson<T>(List<T> ts, string fileName) where T : class
{
try
{
string path = Common.CONFIG_PATH + fileName + ".json";
string output = JsonConvert.SerializeObject(ts,Formatting.Indented);
File.WriteAllText(path, output);
}
catch (Exception e)
{
Common.log.Error(e.Message + "/r/n" + e.StackTrace);
}
}
/// <summary>
/// 读取JSON文件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ts"></param>
/// <param name="fileName"></param>
public static List<T> ReadJson<T>(string fileName) where T : class
{
try
{
string path = Common.CONFIG_PATH + fileName + ".json";
StreamReader streamReader = new StreamReader(path);
string jsonStr = streamReader.ReadToEnd();
List<T> jsonObj = DeserializeJsonToList<T>(jsonStr);
streamReader.Close();
return jsonObj;
}
catch (Exception e)
{
Common.log.Error(e.Message + "/r/n" + e.StackTrace);
return null;
}
}
}
///// <summary>
///// 与服务器通信用对象
///// </summary>
//public class Operation
//{
// private string _cid = "";
// public string cid
// {
// get { return _cid; }
// set { _cid = value; }
// }
// public int seq { get; set; }
// public int op { get; set; }
// public int status { get; set; }
// private string _error = "";
// public string error
// {
// get { return _error; }
// set { _error = value; }
// }
// private Dictionary<string, string> _data = new Dictionary<string,string>();
// public Dictionary<string, string> data {
// get { return _data; }
// set { _data = value; }
// }
//}
}
...@@ -56,17 +56,11 @@ ...@@ -56,17 +56,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AgvInfo.cs" /> <Compile Include="AgvInfo.cs" />
<Compile Include="AGVManager.cs" />
<Compile Include="Common.cs" /> <Compile Include="Common.cs" />
<Compile Include="DisplayBoard.cs" />
<Compile Include="HttpHelper.cs" />
<Compile Include="IJob.cs" /> <Compile Include="IJob.cs" />
<Compile Include="JsonHelper.cs" />
<Compile Include="Log.cs" /> <Compile Include="Log.cs" />
<Compile Include="MiR_API.cs" /> <Compile Include="MiR_API.cs" />
<Compile Include="MyWebClient.cs"> <Compile Include="MiR_API_Test.cs" />
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SteelWork.cs" /> <Compile Include="SteelWork.cs" />
<Compile Include="WorkshopLine.cs" /> <Compile Include="WorkshopLine.cs" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace MiR
{
public class MyWebClient:WebClient
{
private int _timeout;
/// <summary>
/// 超时时间(毫秒)
/// </summary>
public int Timeout
{
get
{
return _timeout;
}
set
{
_timeout = value;
}
}
public MyWebClient()
{
this._timeout = 60000;
}
public MyWebClient(int timeout)
{
this._timeout = timeout;
}
protected override WebRequest GetWebRequest(Uri address)
{
var result = base.GetWebRequest(address);
result.Timeout = this._timeout;
return result;
}
}
}
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!