using HH.WCS.JiaTong.api;
|
using HH.WCS.JiaTong.device;
|
using HH.WCS.JiaTong.dispatch;
|
using HH.WCS.JiaTong.util;
|
using HH.WCS.JiaTong.wms;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading;
|
using static HH.WCS.JiaTong.LISTA.process.HttpModel;
|
|
namespace HH.WCS.JiaTong.process
|
{
|
/// <summary>
|
/// 设备信号处理,主要是tcp信号,我们做server被动接收信号来处理,根据项目定制的
|
/// </summary>
|
internal class DeviceProcess
|
{
|
internal static void Analysis(string data, string ip)
|
{
|
if (data.Length >= 6)
|
{
|
//去掉消息头3F 00
|
data = data.Substring(4);
|
//Console.WriteLine($"{ip}-{data}");
|
var plc = Settings.deviceInfos.Where(a => a.address == ip && a.enable == 1).FirstOrDefault();
|
if (plc != null)
|
{
|
if (plc.deviceType == 1)
|
{
|
if (data == "")
|
{
|
Traystacker(plc);
|
}
|
}
|
}
|
else
|
{
|
Console.WriteLine($"TCP信号处理:未查询到IP为{ip}的数据,请检查deviceInfo配置中心是否存在该IP的数据!");
|
}
|
}
|
|
}
|
/// <summary>
|
/// 叠盘机空托返回
|
/// </summary>
|
internal static void Traystacker(Settings.deviceInfo device)
|
{
|
try
|
{
|
string partNumber = "";
|
//上传数据
|
Result<Traystacker> result1 = new Result<Traystacker>();
|
Traystacker traystacker = new Traystacker() { LocationCode = device.TN_Location[0], PartNumber = partNumber, Qty = 6 };
|
result1.data.Add(traystacker);
|
HttpHelper httpHelper = new HttpHelper();
|
Result result = new Result();
|
string date = JsonConvert.SerializeObject(result1);
|
string url = Settings.tableUrls.Find(a => a.id == 2).url;
|
LogHelper.Info($"叠盘机空托返回:地址:{url},内容:{date}");
|
var r = httpHelper.WebPost(url, date);
|
result = JsonConvert.DeserializeObject<Result>(r);
|
if (result.code == "0")
|
{
|
|
LogHelper.Info($"叠盘机空托返回请求成功");
|
}
|
else
|
{
|
LogHelper.Info($"叠盘机空托返回请求失败=>msg:{result.msg}");
|
}
|
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"叠盘机空托返回 Error=>{ex.ToString()}");
|
}
|
}
|
|
internal static void Traffic()
|
{
|
var db = new SqlHelper<object>().GetInstance();
|
List<string> locs = new List<string>() { "LCDP-001" };
|
var location = db.Queryable<Location>().Where(a => locs.Contains(a.S_CODE)).ToList();
|
if (location.Count > 0)
|
{
|
string cntrcode = "";
|
foreach (var item in location)
|
{
|
|
if (item.N_CURRENT_NUM >= 6)
|
{
|
var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == item.S_CODE).ToList();
|
if (cntr.Count > 0)
|
{
|
var cntrcodes = cntr.Select(a => a.S_CNTR_CODE).ToArray();
|
cntrcode = string.Join(",", cntrcodes);
|
}
|
|
//创建过未完成的任务不发起请求
|
var mst = WCSHelper.GetTaskByStartloc(item.S_CODE);
|
if (mst == null)
|
{
|
AgvEmptyBack(item.S_CODE, cntrcode);
|
}
|
}
|
}
|
}
|
|
|
}
|
|
/// <summary>
|
/// 原材料库接口访问
|
/// </summary>
|
internal static void AgvEmptyBack(string loc, string cntrcode)
|
{
|
try
|
{
|
string partNumber = "";
|
//上传数据
|
Resultmobox<Traystackermobox> result1 = new Resultmobox<Traystackermobox>() { Name = "EmptyCntrReturn", Source = "HostToAgv" };
|
Traystackermobox traystacker = new Traystackermobox() { LocationCode = loc, CntrCode = cntrcode, PartNumber = partNumber, Qty = 6 };
|
result1.data = traystacker;
|
HttpHelper httpHelper = new HttpHelper();
|
//调用接口
|
Resultmobox result = new Resultmobox();
|
string date = JsonConvert.SerializeObject(result1);
|
string url = Settings.tableUrls.Find(a => a.id == 11).url;
|
LogHelper.Info($"空托返回:地址:{url},内容:{date}");
|
var r = httpHelper.WebPostycl(url, date);
|
result = JsonConvert.DeserializeObject<Resultmobox>(r);
|
if (result.err_code == "0")
|
{
|
|
LogHelper.Info($"空托返回请求成功");
|
}
|
else
|
{
|
LogHelper.Info($"空托返回请求失败=>msg:{result.err_msg}");
|
}
|
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"空托返回 Error=>{ex.ToString()}");
|
}
|
}
|
}
|
}
|