|
using Hanhe.iWCS.Business;
|
using Hanhe.iWCS.Common;
|
using Hanhe.iWCS.Interface;
|
using Hanhe.iWCS.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Linq;
|
using MongoDB.Bson;
|
using Hanhe.iWCS.MData;
|
using Newtonsoft.Json;
|
using MongoDB.Driver.Builders;
|
using static Hanhe.iWCS.JingmenGEMTwoProtocol.MESHelper;
|
using MongoDB.Driver;
|
using static Hanhe.iWCS.JingmenGEMTwoProtocol.ProcessHelper;
|
using static Hanhe.iWCS.JingmenGEMTwoProtocol.ApiHelper;
|
using System.Threading;
|
using Hanhe.iWCS.Model.AMS;
|
using Hanhe.iWCS.JingmenGEMTwoTCP;
|
using static Hanhe.iWCS.JingmenGEMTwoProtocol.ProtocolAnalysis;
|
using System.Threading.Tasks;
|
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
using static Hanhe.iWCS.JingmenGEMTwoProtocol.AMSHelper;
|
using System.Collections;
|
using log4net.Config;
|
using System.Text.RegularExpressions;
|
using static Hanhe.iWCS.JingmenGEMTwoProtocol.ERPService;
|
using System.Globalization;
|
using static Hanhe.iWCS.JingmenGEMTwoProtocol.PLCControl;
|
using Hanhe.iWCS.DeviceDriver;
|
using System.Data.OleDb;
|
|
namespace Hanhe.iWCS.JingmenGEMTwoProtocol
|
{
|
public class PLCControl : IPLCControl
|
{
|
private EquipmentCommandEQBLL commandBLL = new EquipmentCommandEQBLL();
|
private static HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS);
|
|
/// <summary>
|
/// PLC 数据发送
|
/// </summary>
|
/// <param name="command"></param>
|
/// <returns></returns>
|
public void SendMessage(EquipmentCommandEQ command)
|
{
|
bool sended = SessionInstance.Instance.PLCSend(command.EquipmentIP, int.Parse(command.EquipmentPort), command.CommandText);
|
if (sended)
|
{
|
//CMMLog.Info("设备指令发送成功;EquipmentCode=" + command.EquipmentCode + "-指令=" + command.CommandText);
|
commandBLL.UpdateCommandEQStatus(command._id, Constants.COMMANDEQ_STATUS_SENDED, command.SendCount);
|
}
|
else
|
{
|
//CMMLog.Info("设备指令发送失败;EquipmentCode=" + command.EquipmentCode + "-指令=" + command.CommandText);
|
commandBLL.UpdateCommandEQStatus(command._id, Constants.COMMANDEQ_STATUS_SEND_ERRORS, command.SendCount);
|
}
|
}
|
|
/// <summary>
|
/// 处理光电信息
|
/// </summary>
|
/// <param name="data"></param>
|
public static void Analysis(string data) {
|
//3f 00 01 00 00 00 24 24
|
}
|
|
#region 纯3楼设备任务
|
|
#region 3楼包装机取料至复称平台流程——无需回报WMS任务状态——3楼包装取料——已完成(待测试,时间戳处理)
|
|
#region 收到包装机下料信号1,开始判断复称平台是否满足条件,选择性下发任务
|
|
/// <summary>
|
/// 3楼包装机取料至复称平台流程——任务开始前,判断包装机有没有下线信号,并判断当前复称平台是否NG以及有没有任务在进行中
|
/// </summary>
|
/// <param name="a"></param>
|
internal static void CheckPackingMachine(Settings.PlcInfo pmInfo)
|
{
|
var count = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.And(Query.EQ("isOne", "1"), Query.EQ("occupy", "1")), "MachineInfo");
|
|
//检查包装机通道0是否有下料信号,如果有生成下料任务。线程循环读取,无需设置循环。——通道0参数为1
|
if(count == null)
|
{
|
if (PickUpStartFree(pmInfo.location) && PickUpEndFree(pmInfo.location))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:读取包装机{pmInfo.device}通道号为:{pmInfo.readAddr}的值为:{result.result[0]}");
|
if (result != null && result.errCode == 0 && result.result.Count() > 0)
|
{
|
//1:取料
|
if (result.result[0] == 1)
|
{
|
var PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == "2").FirstOrDefault().location;
|
//包装下线任务,终点为复称位置(这里判断包装机起点,复称起点终点均无任务,则推送任务)
|
if (ProcessHelper.PickUpStartFree(pmInfo.location) && ProcessHelper.CheckEndFree(PlcBit02) && ProcessHelper.PickUpStartFree(PlcBit02))
|
{
|
//判断复称位置,没有货并且不为NG(ng参数0,1,2——0,不确定(包装机刚开始工作时)1,ok 2,ng)
|
var state = GetSecondWeighState(pmInfo.location, "2");
|
CMMLog.Debug($"包装下线流程:判断复称位置空满状态为:{state.full},ng状态为:{state.ng}");
|
if (state.full == 0)
|
{
|
if (Settings.mesOpen == "0")
|
{
|
//可以生成任务,调mes接口获取生产信息 2022.7.28 变更 MES可能需要1~2年才能上线,先把MES功能注销
|
var info = MESHelper.GetPackingMachineInfo(pmInfo.location);
|
if (info != null)
|
{
|
CMMLog.Debug($"包装下线流程:获取MES之后进入info判断!");
|
//Console.WriteLine($"包装下线流程:获取MES之后进入info判断!");
|
var trayCode = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = pmInfo.readAddr + 10,
|
dataNum = 80,//数据个数要增加 addr以及dataNum的具体数据为16个 现80个参数
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (trayCode.errCode == 0 && trayCode.result.Length == 80)
|
{
|
//获取托盘码等信息 读取通道 10、11、12的数据作为托盘码 读取其它通道 重量 叠包等信息 所有数据存入MachineInfo表
|
string location = "";
|
GetMachineData(pmInfo,ref location, trayCode.result);
|
var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
|
if (tray != null && tray.addState == 0)
|
{
|
MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", tray.machineNo), RemoveFlags.Single);
|
CMMLog.Debug("包装下线任务,叠托层数为0,不生成任务");
|
}
|
else if (tray != null)
|
{
|
if (tray.trayCode != "0" && tray.trayCode != "" && tray.trayCode != null)
|
{
|
int i = 1;
|
while (i == 1)
|
{
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3楼包装取料", 0, tray.trayCode);
|
if (amsResult.success)
|
{
|
i = 2;
|
CMMLog.Debug($"包装下线流程:AMS调用API成功!");
|
//记录包装间下料信息
|
MongoDBSingleton.Instance.Insert<packageInfoModel>(new packageInfoModel { machineNo = tray.machineNo, trayCode = tray.trayCode, time = DateTime.Now.ToString("yyyy-MM-dd"), weight = tray.oneTrayWeight });
|
break;
|
}
|
else CMMLog.Debug($"包装下线流程:AMS调用API失败,开始重新调用!");
|
}
|
CMMLog.Debug($"包装下线流程:接受并读取包装机通道里面的物料信息,并将其写入MachineInfo中间表中!接收到的信息:{JsonConvert.SerializeObject(trayCode.result)}");
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"包装下线流程:tray==null!");
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"包装下线流程:3楼包装至复称获取MODBUS值错误!trayCode.errCode:{trayCode.errCode},trayCode.result.Length:{trayCode.result.Length}");
|
}
|
}
|
else CMMLog.Debug($"包装下线流程:MES接口数据返回空值!MES接口数据:{info}");
|
}
|
else if (Settings.mesOpen == "1")
|
{
|
//可以生成任务,调mes接口获取生产信息 2022.7.28 变更 MES可能需要1~2年才能上线,先把MES功能注销
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:获取MES之后进入info判断!");
|
var trayCode = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = pmInfo.readAddr + 5,
|
dataNum = 95,////ERP变更:95 原先:90
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (trayCode.errCode == 0 && trayCode.result.Length == 95)
|
{
|
//获取托盘码等信息 读取通道 11、12、13的数据作为托盘码 读取其它通道 重量 叠包等信息 所有数据存入MachineInfo表
|
string flLoc = "";
|
string location = "";
|
GetMachineData(pmInfo,ref location, trayCode.result, false, "1");
|
if (pmInfo.location.Contains("FLZT"))
|
{
|
flLoc = pmInfo.location;
|
pmInfo.location = location;
|
}
|
|
var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
|
if (tray != null)
|
{
|
bool IsContLaterCode = true;
|
if (ERPService.ERPSwitch01 == "1")
|
{
|
// 判断当前【员工编号】通道信息读出来的员工编号是否已经存在于我们的员工信息表-ERPEmployeeTable(查询字段-employee_id)
|
var erpEmployeeInfo = MongoDBSingleton.Instance.FindOne<ERPEmployeeTable>(Query.EQ("employee_id", tray.empCode), "ERPEmployeeTable");
|
|
var erpItemInfo = MongoDBSingleton.Instance.FindOne<ERPItemTable>(Query.EQ("item_code", tray.materialCode), "ERPItemTable");
|
if (string.IsNullOrEmpty(tray.empCode) || string.IsNullOrEmpty(tray.materialCode) || erpEmployeeInfo == null || erpEmployeeInfo == null)
|
{
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:人员表或者物料表未找到该数据,员工编号:{tray.empCode},物料编码:{tray.materialCode}!");
|
IsContLaterCode = false;
|
}
|
}
|
|
if (IsContLaterCode)
|
{
|
if (tray.addState == 0)
|
{
|
MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo", RemoveFlags.None);
|
//if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:叠托层数为0,不允许生成任务");
|
}
|
if (tray.bagNo == "0")
|
{
|
MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo", RemoveFlags.None);
|
//if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:袋号为0,不允许生成任务");
|
|
}
|
else if (tray.trayCode != "0" && !string.IsNullOrEmpty(tray.trayCode))
|
{
|
CMMLog.Info($"物料编码:{tray.materialCode},批次号:{tray.lotNo}");
|
string timeStamp = ProcessHelper.GetTimeStamp(31, 1, 1);
|
pmInfo.location = !string.IsNullOrEmpty(flLoc) ? flLoc : pmInfo.location;
|
HHAmsExecuteResult req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3楼包装取料", 0, tray.trayCode, timeStamp);
|
ProcessHelper.deleteInfo(pmInfo.location + "-包装下线");
|
//包装取料卸货完成,设备生产数量加一
|
//判断是否有当天的数据,如果没有,则生成数据
|
#region
|
var proInfo = MongoDBSingleton.Instance.FindOne<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", tray.machineNo)), "ProductList");
|
if (proInfo != null)
|
{
|
proInfo.total = proInfo.total + 1;
|
proInfo.percentOfPass = Math.Round(((proInfo.qualifiedQuantity / proInfo.total) * 100), 2);
|
MongoDBSingleton.Instance.Update<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", tray.machineNo)), Update.Set("total", proInfo.total).Set("percentOfPass", proInfo.percentOfPass), UpdateFlags.None);
|
}
|
else
|
{
|
ProductList machine = new ProductList
|
{
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
machine = tray.machineNo,
|
total = 1,
|
qualifiedQuantity = 0,
|
percentOfPass = 0,
|
overallPassRate = 0
|
};
|
MongoDBSingleton.Instance.Insert(machine);
|
}
|
#endregion
|
|
//记录包装间下料信息
|
if (req.success)
|
{
|
string Weight = (decimal.Parse(tray.oneTrayWeight1) / 100).ToString("F2");
|
MongoDBSingleton.Instance.Insert<packageInfoModel>(new packageInfoModel { machineNo = tray.machineNo, trayCode = tray.trayCode, batchNo = tray.lotNo, time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), weight = Weight });
|
}
|
}
|
}
|
else
|
{
|
//检索员工信息失败写入对方通道值1 读取地址+3
|
var wirteall01 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = pmInfo.readAddr + 3,
|
host = pmInfo.ip,
|
port = pmInfo.port,
|
data = 1
|
});
|
}
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:tray==null!");
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:3楼包装至复称获取MODBUS值错误!trayCode.errCode:{trayCode.errCode},trayCode.result.Length:{trayCode.result.Length}");
|
}
|
}
|
else
|
{
|
var task = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.Or(Query.EQ("CN_S_START_BIT", PlcBit02), Query.EQ("CN_S_END_BIT", PlcBit02)), "TN_I_TASK_MST");
|
if (task != null) CMMLog.Debug($"包装下线流程-{pmInfo.location}:检查复称中间表是否为空,不为空则检查其数据full以及ng是否为0和1!任务号为:{task.CN_S_TASK_NO}");
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:检查复称中间表是否为空,不为空则检查其数据full以及ng是否为0和1!");
|
ProcessHelper.recordInfo(pmInfo.location + "-包装下线", $"当前复称口已有物料,复位口:{PlcBit02}");
|
}
|
}
|
else
|
{
|
var taskNo = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_START_BIT", pmInfo.location), "TN_I_TASK_MST");
|
var taskNo1 = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.Or(Query.EQ("CN_S_START_BIT", PlcBit02), Query.EQ("CN_S_END_BIT", PlcBit02)), "TN_I_TASK_MST");
|
string task = "", startbit = "", endbit = "";
|
if (taskNo != null)
|
{
|
task = taskNo.CN_S_TASK_NO;
|
startbit = taskNo.CN_S_START_BIT;
|
endbit = taskNo.CN_S_END_BIT;
|
}
|
else if (taskNo1 != null)
|
{
|
task = taskNo1.CN_S_TASK_NO;
|
startbit = taskNo1.CN_S_START_BIT;
|
endbit = taskNo1.CN_S_END_BIT;
|
}
|
CMMLog.Debug($"包装机起点或者复称起点终点有任务在执行中!任务号:{task},起点:{startbit},终点:{endbit}");
|
ProcessHelper.recordInfo(pmInfo.location + "-包装下线", $"当前复位口被其他任务占用,复位口:{PlcBit02}");
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:包装机通道0里面的数据不为1!result为:{JsonConvert.SerializeObject(result)}");
|
}
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:未读取到包装机通道0里面的数据!!!result:{JsonConvert.SerializeObject(result)}");
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:未读取到包装机通道0里面的数据!!!result:{JsonConvert.SerializeObject(result)}");
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:" + ex.Message);
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"当前包装机起点终点有任务正在执行,请确认当前包装机的任务是否取货卸货完成!包装机货位编码:{pmInfo.location}");
|
}
|
}
|
else CMMLog.Debug($"当前machineInfo中间表已存在数据:{JsonConvert.SerializeObject(count)}");
|
}
|
|
/// <summary>
|
/// 3楼包装机取料至复称平台流程——任务开始前,判断包装机有没有下线信号,并判断当前复称平台是否NG以及有没有任务在进行中 二期
|
/// </summary>
|
/// <param name="a"></param>
|
internal static void CheckPackingMachineTwo(Settings.PlcInfo pmInfo)
|
{
|
var count = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.And(Query.EQ("isOne", "2"), Query.EQ("occupy", "1")) , "MachineInfo");
|
|
//检查包装机通道0是否有下料信号,如果有生成下料任务。线程循环读取,无需设置循环。——通道0参数为1
|
if (count == null)
|
{
|
if (PickUpStartFree(pmInfo.location) && PickUpEndFree(pmInfo.location))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
CMMLog.Debug($"二期包装下线流程-{pmInfo.location}:读取包装机{pmInfo.device}通道号为:{pmInfo.readAddr}的值为:{result.result[0]}");
|
if (result != null && result.errCode == 0 && result.result.Count() > 0)
|
{
|
//1:取料
|
if (result.result[0] == 1)
|
{
|
string PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == "23").FirstOrDefault().location;
|
if (ProcessHelper.PickUpStartFree(pmInfo.location) && ProcessHelper.CheckEndFree(PlcBit02) && ProcessHelper.PickUpStartFree(PlcBit02))
|
{
|
//判断复称位置,没有货并且不为NG(ng参数0,1,2——0,不确定(包装机刚开始工作时)1,ok 2,ng)
|
var state = GetSecondWeighState(pmInfo.location, "23");
|
CMMLog.Debug($"二期包装下线流程:判断复称位置空满状态为:{state.full},ng状态为:{state.ng}");
|
if (state.full == 0)
|
{
|
if (Settings.mesOpen == "0")
|
{
|
//可以生成任务,调mes接口获取生产信息 2022.7.28 变更 MES可能需要1~2年才能上线,先把MES功能注销
|
var info = MESHelper.GetPackingMachineInfo(pmInfo.location);
|
if (info != null)
|
{
|
CMMLog.Debug($"二期包装下线流程:获取MES之后进入info判断!");
|
//Console.WriteLine($"包装下线流程:获取MES之后进入info判断!");
|
var trayCode = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = pmInfo.readAddr + 10,
|
dataNum = 80,//数据个数要增加 addr以及dataNum的具体数据为16个 现80个参数
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (trayCode.errCode == 0 && trayCode.result.Length == 80)
|
{
|
//获取托盘码等信息 读取通道 10、11、12的数据作为托盘码 读取其它通道 重量 叠包等信息 所有数据存入MachineInfo表
|
string location = "";
|
GetMachineData(pmInfo,ref location, trayCode.result);
|
var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
|
if (tray != null && tray.addState == 0)
|
{
|
MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", tray.machineNo), RemoveFlags.Single);
|
CMMLog.Debug("包装下线任务,叠托层数为0,不生成任务");
|
}
|
else if (tray != null)
|
{
|
if (tray.trayCode != "0" && tray.trayCode != "" && tray.trayCode != null)
|
{
|
int i = 1;
|
while (i == 1)
|
{
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3楼包装取料", 0, tray.trayCode);
|
if (amsResult.success)
|
{
|
i = 2;
|
CMMLog.Debug($"包装下线流程:AMS调用API成功!");
|
//记录包装间下料信息
|
MongoDBSingleton.Instance.Insert<packageInfoModel>(new packageInfoModel { machineNo = tray.machineNo, trayCode = tray.trayCode, time = DateTime.Now.ToString("yyyy-MM-dd"), weight = tray.oneTrayWeight });
|
break;
|
}
|
else CMMLog.Debug($"包装下线流程:AMS调用API失败,开始重新调用!");
|
}
|
CMMLog.Debug($"包装下线流程:接受并读取包装机通道里面的物料信息,并将其写入MachineInfo中间表中!接收到的信息:{JsonConvert.SerializeObject(trayCode.result)}");
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"包装下线流程二期:tray==null!,未在MachineInfo表中查询到包装机号:{pmInfo.location}");
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"包装下线流程:3楼包装至复称获取MODBUS值错误!trayCode.errCode:{trayCode.errCode},trayCode.result.Length:{trayCode.result.Length}");
|
}
|
}
|
else CMMLog.Debug($"包装下线流程:MES接口数据返回空值!MES接口数据:{info}");
|
}
|
else if (Settings.mesOpen == "1")
|
{
|
//可以生成任务,调mes接口获取生产信息 2022.7.28 变更 MES可能需要1~2年才能上线,先把MES功能注销
|
CMMLog.Debug($"二期包装下线流程-{pmInfo.location}:获取MES之后进入info判断!");
|
var trayCode = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = pmInfo.readAddr + 5,
|
dataNum = 95,////ERP变更:90 原先:80
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (trayCode.errCode == 0 && trayCode.result.Length == 95)
|
{
|
//获取托盘码等信息 读取通道 11、12、13的数据作为托盘码 读取其它通道 重量 叠包等信息 所有数据存入MachineInfo表
|
string flLoc = "";
|
string location = "";
|
GetMachineData(pmInfo,ref location, trayCode.result, false, "2");
|
if (pmInfo.location.Contains("FLZT"))
|
{
|
flLoc = pmInfo.location;
|
pmInfo.location = location;
|
}
|
var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
|
if (tray != null)
|
{
|
bool IsContLaterCode = true;
|
if (ERPService.ERPSwitch01 == "1")
|
{
|
// 判断当前【员工编号】通道信息读出来的员工编号是否已经存在于我们的员工信息表-ERPEmployeeTable(查询字段-employee_id)
|
var erpEmployeeInfo = MongoDBSingleton.Instance.FindOne<ERPEmployeeTable>(Query.EQ("employee_id", tray.empCode), "ERPEmployeeTable");
|
var erpItemInfo = MongoDBSingleton.Instance.FindOne<ERPItemTable>(Query.EQ("item_code", tray.materialCode), "ERPItemTable");
|
if (string.IsNullOrEmpty(tray.empCode) || string.IsNullOrEmpty(tray.materialCode) || erpEmployeeInfo == null || erpEmployeeInfo == null)
|
{
|
CMMLog.Info($"包装下线流程-{pmInfo.location}:人员表或者物料表未找到该数据,员工编号:{tray.empCode},物料编码:{tray.materialCode}!");
|
IsContLaterCode = false;
|
}
|
}
|
|
if (IsContLaterCode)
|
{
|
if (tray.addState == 0)
|
{
|
MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", tray.machineNo), RemoveFlags.Single);
|
//if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
|
CMMLog.Debug("二期包装下线任务,叠托层数为0,不生成任务");
|
}
|
if (tray.bagNo == "0")
|
{
|
MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo", RemoveFlags.None);
|
//if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:袋号为0,不允许生成任务");
|
|
}
|
else if (tray.trayCode != "0" && !string.IsNullOrEmpty(tray.trayCode))
|
{
|
CMMLog.Info($"物料编码:{tray.materialCode},批次号:{tray.lotNo}");
|
string timeStamp = ProcessHelper.GetTimeStamp(31, 1, 1);
|
pmInfo.location = !string.IsNullOrEmpty(flLoc) ? flLoc : pmInfo.location;
|
HHAmsExecuteResult req;
|
if (pmInfo.deviceType == "22")
|
{
|
req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3楼包装取料", 0, tray.trayCode, timeStamp);
|
}
|
else
|
{
|
req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "地面货位取料", 0, tray.trayCode, timeStamp);
|
}
|
|
//包装取料卸货完成,设备生产数量加一
|
//判断是否有当天的数据,如果没有,则生成数据
|
#region
|
var proInfo = MongoDBSingleton.Instance.FindOne<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", tray.machineNo)), "ProductList");
|
if (proInfo != null)
|
{
|
proInfo.total = proInfo.total + 1;
|
proInfo.percentOfPass = Math.Round(((proInfo.qualifiedQuantity / proInfo.total) * 100), 2);
|
MongoDBSingleton.Instance.Update<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", tray.machineNo)), Update.Set("total", proInfo.total).Set("percentOfPass", proInfo.percentOfPass), UpdateFlags.None);
|
|
//MongoDBSingleton.Instance.Update<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", tray.machineNo)), Update.Set("total", proInfo.total), UpdateFlags.None);
|
}
|
else
|
{
|
ProductList machine = new ProductList
|
{
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
machine = tray.machineNo,
|
total = 1,
|
qualifiedQuantity = 0,
|
percentOfPass = 0,
|
overallPassRate = 0
|
};
|
MongoDBSingleton.Instance.Insert(machine);
|
}
|
#endregion
|
|
//记录包装间下料信息
|
if (req.success)
|
{
|
ProcessHelper.deleteInfo(pmInfo.location + "-包装下线");
|
string Weight = (decimal.Parse(tray.oneTrayWeight1) / 100).ToString("F2");
|
MongoDBSingleton.Instance.Insert<packageInfoModel>(new packageInfoModel { machineNo = tray.machineNo, trayCode = tray.trayCode, batchNo = tray.lotNo, time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), weight = Weight });
|
}
|
}
|
}
|
else
|
{
|
//检索员工信息失败写入对方通道值1 读取地址+3
|
var wirteall01 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = pmInfo.readAddr + 3,
|
host = pmInfo.ip,
|
port = pmInfo.port,
|
data = 1
|
});
|
}
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:tray==null!");
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:3楼包装至复称获取MODBUS值错误!trayCode.errCode:{trayCode.errCode},trayCode.result.Length:{trayCode.result.Length}");
|
}
|
}
|
else
|
{
|
var task = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.Or(Query.EQ("CN_S_START_BIT", PlcBit02), Query.EQ("CN_S_END_BIT", PlcBit02)), "TN_I_TASK_MST");
|
if (task != null) CMMLog.Debug($"包装下线流程:检查复称中间表是否为空,不为空则检查其数据full以及ng是否为0和1!任务号为:{task.CN_S_TASK_NO}");
|
else CMMLog.Debug("包装下线流程:检查复称中间表是否为空,不为空则检查其数据full以及ng是否为0和1!");
|
ProcessHelper.recordInfo(pmInfo.location + "-包装下线", $"当前复称口已有物料,复位口:{PlcBit02}");
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:包装机起点或者复称起点终点有任务在执行中!包装机点位:{pmInfo.location},复称点位:{PlcBit02}");
|
|
ProcessHelper.recordInfo(pmInfo.location + "-包装下线", $"当前复位口被其他任务占用,复位口:{PlcBit02}");
|
}
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:包装机通道0里面的数据不为1!result为:{JsonConvert.SerializeObject(result)}");
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:未读取到包装机通道0里面的数据!!!result:{JsonConvert.SerializeObject(result)}");
|
}
|
else CMMLog.Debug($"包装下线流程-{pmInfo.location}:未读取到包装机通道0里面的数据!!!result:{JsonConvert.SerializeObject(result)}");
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Debug($"包装下线流程-{pmInfo.location}:" + ex.Message);
|
}
|
}
|
else
|
{
|
CMMLog.Debug($"当前包装机起点终点有任务正在执行,请确认当前包装机的任务是否取货卸货完成!包装机货位编码:{pmInfo.location}");
|
}
|
}
|
else CMMLog.Debug($"当前machineInfo中间表已存在数据:{JsonConvert.SerializeObject(count)}");
|
}
|
|
#endregion
|
|
#region 包装机MODBUS交互(开始取料,取料完成)
|
|
/// 小车请求进料 1 AMS写,PLC读 1-请求进入;2-到位后,请求接驳滚动;3-取货完成;4-离开安全门外,清零通道
|
/// 设备允许出料 1 PLC写,AMS读 1-XXXXXXXX;2-允许进入;3-接驳滚动,送出物料 ;4-结束;5-安全门关闭
|
|
/// <summary>
|
/// 小车到达包装机安全门口请求进入
|
/// </summary>
|
/// <param name="ips"></param>
|
internal static void PickUpFullDoorUnload(string ip, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
//ASM写入通道0小车动作,1-取料
|
int[] num = new int[2] { 1, 1 };
|
var writeRes0 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
host = ip,
|
addr = plc.writeAddr,
|
data = num,//原先是1,单个写入
|
port = plc.port
|
});
|
DateTime dateTime = DateTime.Now;
|
if (writeRes0.errCode == 0)
|
{
|
//小车请求进入安全门交互
|
//小车请求进料,并且查询设备是否允许AGV进入
|
//读地址1设备是否 2-可以进入
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = ip,
|
addr = plc.readAddr + 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
//Console.WriteLine($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if (readRes.result[0] == 2)
|
{
|
//设备允许进入,改参数通知AGV
|
WorkFlowAction.TrackLog(taskNo, 10, 1012, "success");
|
TSHelper.GoToAGV(taskNo, 10, 1);
|
}
|
}
|
else CMMLog.Debug($"包装下线:1012,readRes:{readRes},readRes.errCode:{readRes.errCode}");
|
}
|
}
|
/// <summary>
|
/// 小车请求取货
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void PickUpFullUnload(string ip , string taskNo, int port)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip && a.port == port).FirstOrDefault();
|
if (ip != "")
|
{
|
//小车请求出料,并且查询设备是否允许AGV进入
|
//读地址2设备是否 2-允许进料 保险起见,可以不读
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = ip,
|
addr = plc.readAddr + 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
//Console.WriteLine($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if (readRes.result[0] == 2)
|
{
|
//TSHelper.GoToAGV(taskNo, 10, 2);//原先先改AGV参数
|
var writeRes1 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = ip,
|
addr = plc.writeAddr + 1,
|
data = 2,
|
port = plc.port
|
});
|
if(writeRes1.errCode == 0) TSHelper.GoToAGV(taskNo, 10, 2);
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为2.");
|
//Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为2.");
|
}
|
}
|
else CMMLog.Debug($"包装下线,1112,readRes={readRes}");
|
}
|
else CMMLog.Debug($"包装下线,1112,ip=null!");
|
}
|
/// <summary>
|
/// 小车取货完成--二期协议无此指令动作
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void PickUpFullComplete(string ip, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
if (ip != "")
|
{
|
//小车请求出料,并且查询设备是否允许AGV进入
|
//读地址2设备是否 2-允许进料
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = ip,
|
addr = plc.readAddr+1,
|
port = plc.port
|
});
|
CMMLog.Debug($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
//Console.WriteLine($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
DateTime dateTime = DateTime.Now;
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if (readRes.result[0] == 3)
|
{
|
var writeRes1 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = ip,
|
addr = plc.writeAddr+1,
|
data = 3,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为3.");
|
//Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为3.");
|
}
|
else if(readRes.result[0] == 4)
|
{
|
WorkFlowAction.TrackLog(taskNo, 10, 1212, "success");
|
TSHelper.GoToAGV(taskNo, 10, 5);
|
}
|
}
|
else CMMLog.Debug($"包装下线,1212,readRes={readRes}!");
|
}
|
else CMMLog.Debug($"包装下线,1212,ip=null!");
|
}
|
/// <summary>
|
/// 小车卸货完成离开安全门后通知包装机
|
/// </summary>
|
/// <param name="ips"></param>
|
/// <param name="taskNo"></param>
|
internal static void PickUpFullDoorComplete(string ip, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
if (plc != null)
|
{
|
if (plc.location.Contains("FLZT"))
|
{
|
//写入返料站台--取货完成
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = ip,
|
addr = plc.writeAddr,
|
data = 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为1.");
|
}
|
else
|
{
|
//写入包装机--安全门关门指令
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = ip,
|
addr = plc.writeAddr + 1,
|
data = 3,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为3.");
|
}
|
|
}
|
else CMMLog.Debug($"包装下线,4,ip=null!");
|
}
|
#endregion
|
|
#region 复称平台交互
|
|
///小车请求进料 1 AMS写,PLC读 1-请求进入;2-小车进料,输送托盘;3-XXXXXXX
|
///设备允许出料 1 PLC写,AMS读 1-XXXXXXXX;2-允许进料,开始滚动;3-上料完成
|
///复称平台小车动作: 1:上料复称;2:上砝码教称;3:取复称NG托盘,4:取砝码到包装机
|
|
/// <summary>
|
///复称平台安全请求进入——因为现场需求,所以额外增加一个类似安全门的交互,直接改参数就行
|
/// </summary>
|
internal static void SecondWeightSafe(string ip,string taskNo, int port)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip && a.port == port).FirstOrDefault();
|
//ASM写入小车动作,1:上料复称;2:上砝码教称;3:取复称NG托盘,4:取砝码到包装机
|
int[] num = new int[2] { 1, 1 };
|
var writeRes0 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
host = ip,
|
addr = plc.writeAddr,
|
data = num,//原先是1,单个写入
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为1.");
|
//Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr}里面数据为1.");
|
///小车和复称位对接
|
//小车请求进料,并且查询设备是否允许AGV进入
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = plc.ip,
|
addr = plc.readAddr + 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
//Console.WriteLine($"读取设备{plc.location}通道{plc.readAddr + 1}里面数据为{readRes.result[0]}.");
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if(readRes.result[0] == 2)
|
{
|
WorkFlowAction.TrackLog(taskNo, 10, 1013, "success");
|
TSHelper.GoToAGV(taskNo, 10, 3);
|
}
|
}
|
|
|
//将数据写入通道
|
}
|
/// <summary>
|
/// 复称卸货
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void CheckUpReqUnload(Settings.PlcInfo plc, TN_I_TASK_MST mst)
|
{
|
///小车和复称位对接
|
if (plc != null)
|
{
|
//设备允许进入,改参数通知AGV
|
//WorkFlowAction.TrackLog(taskNo, 10, 1113, "success");
|
//TSHelper.GoToAGV(taskNo, 10, 4);
|
//CMMLog.Debug($"改AGV参数:10,4");
|
//判断任务起点,找到起点包装机设备号,在中间表MachineInfo中查找上一台设备(包装机)的数据,通过modbus通道传入(数据需要转换,ASCII转16short,可能还需要数据拆分)
|
var machine = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("trayCode", mst.CN_S_BATCH_NO), "MachineInfo");
|
if (machine != null)
|
{
|
CMMLog.Debug("进入machine判断");
|
//向复称卸货复称,并将从包装机获取到的数据写入通道中
|
#region 多个数据写入MODBUS
|
|
var arr = JsonConvert.DeserializeObject<List<int>>(machine.jsonData);
|
int[] num = new int[23];
|
for(int i = 0; i <= 22; i++) num[i] = arr[i];
|
|
num[19] = int.Parse(machine.overlappingLayers);
|
num[20] = int.Parse(machine.bagNo);
|
|
int[] num2 = new int[17];
|
for(int i = 0; i <= 16; i++) num2[i] = arr[i + 23];
|
|
CMMLog.Debug($"num:{JsonConvert.SerializeObject(num)}");
|
//变更注释
|
CMMLog.Debug($"num2:{JsonConvert.SerializeObject(num2)}");
|
|
var wirteall = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 5,
|
host = plc.ip,
|
data = num,
|
port = plc.port
|
});
|
var wirteal3 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 100,
|
host = plc.ip,
|
data = num2,
|
port = plc.port
|
});
|
|
var writeRes1 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr + 1,
|
data = 2,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为2.");
|
//Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为2.");
|
#endregion
|
}
|
else CMMLog.Debug($"machine判断错误,为null!");
|
}
|
else CMMLog.Debug($"包装下线,1113,ip=null!");
|
}
|
/// <summary>
|
/// 复称卸货完成
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="cN_S_TASK_NO"></param>
|
/// <returns></returns>
|
internal static void CheckUpUnloadComplete(string ip, string cN_S_TASK_NO,string machineNo, int port)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip && a.port == port).FirstOrDefault();
|
|
int[] num = new int[1] { 2 };
|
var writeRes0 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
host = ip,
|
addr = plc.writeAddr + 1,
|
data = num,//原先是1,单个写入
|
port = plc.port
|
});
|
|
var tray = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", cN_S_TASK_NO), "TN_I_TASK_MST");
|
|
var query = Query.And(Query.EQ("actionNo", "1"), Query.EQ("ext1", ip), Query.EQ("ext2", tray.CN_S_BATCH_NO));
|
var ActionControlInfo = MongoDBSingleton.Instance.FindOne<ActionControlModel>(query, "ActionControlModel");
|
if (ActionControlInfo == null)
|
{
|
MongoDBSingleton.Instance.Insert<ActionControlModel>(new ActionControlModel
|
{
|
actionNo = "1",
|
ext1 = ip,
|
ext2 = tray.CN_S_BATCH_NO,
|
ext3 = plc.port,
|
machince = machineNo
|
}, "ActionControlModel");
|
}
|
}
|
/// <summary>
|
/// 复称平台安全退出(已退出)--二期无需执行此指令动作
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="cN_S_TASK_NO"></param>
|
/// <returns></returns>
|
internal static bool SecondWeightSafeComplete(string ip, string cN_S_TASK_NO)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
bool result = true;
|
if(ip != "")
|
{
|
//var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
//{
|
// addr = plc.writeAddr,
|
// data = 0,
|
// host = ip,
|
// port = plc.port
|
//});
|
//CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为0.");
|
////Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr}里面数据为0.");
|
//var wirte1 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
//{
|
// addr = plc.writeAddr + 1,
|
// data = 0,
|
// host = ip,
|
// port = plc.port
|
//});
|
//CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为0.");
|
////Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为0.");
|
result = true;
|
}
|
else
|
{
|
CMMLog.Debug($"包装下线,4,ip=null!");
|
}
|
return result;
|
}
|
|
internal static void SecondWeightActionOne(ActionControlModel model)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == model.ext1 && a.port == model.ext3).FirstOrDefault();
|
|
if (plc != null)
|
{
|
bool req = false;
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 28,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Info("SecondWeightActionOne----" + JsonConvert.SerializeObject(result) + $"{result.result.Length}");
|
if(result.result.Length > 0)
|
{
|
CMMLog.Debug($"读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 1}里面数据为{result.result[2]}.");
|
MongoDBSingleton.Instance.Update<MachineInfo>(Query.EQ("trayCode", model.ext2), Update.Set("secondNg", result.result[2]), UpdateFlags.None);
|
//获取从复称平台读出的 时间戳,并转换处理为 string 字符串
|
string timeStamp = Convert.ToInt32(Completion(result.result[25]) + Completion(result.result[26]), 2).ToString();
|
string wmstaskno = "";
|
string traycode = "";
|
CMMLog.Info($"SecondWeightActionOne:readData:{JsonConvert.SerializeObject(result.result)},timeStamp:{timeStamp}");
|
|
if (result.result[0] == 3)
|
{
|
int[] num = new int[1] { 0 };
|
var writeRes0 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
host = plc.ip,
|
addr = plc.writeAddr + 1,
|
data = num,//原先是1,单个写入
|
port = plc.port
|
});
|
}
|
if (result.result[2] != 1 && result.result[2] != 2)
|
{
|
ProcessHelper.recordInfo(plc.location + "-复称入缓存架", "复称平台未给复称结果");
|
}
|
|
if (result.result[0] == 3 && result.result[2] == 1)
|
{
|
CMMLog.Debug($"准备生成复称入缓存架任务,开始确定托盘号:{model.ext2}");
|
|
//更新复称平台的数据到中间表
|
var trayCode = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = plc.readAddr + 20,
|
dataNum = 10,//数据个数要增加
|
host = plc.ip,
|
port = plc.port
|
});
|
if (trayCode.errCode == 0 && trayCode.result.Length == 10)
|
{
|
//获取复称OK数据存入MachineInfo表
|
GetOKWeight(trayCode.result, model.ext2);
|
}
|
else
|
{
|
CMMLog.Debug($"复称OK流程:读取复称平台重量错误!trayCode.errCode:{trayCode.errCode},trayCode.result.Length:{trayCode.result.Length}");
|
}
|
req = WMSHelper.WMSIn(plc.location, model.ext2, ref wmstaskno, ref traycode);
|
|
|
if (req)
|
{
|
ProcessHelper.deleteInfo(plc.location + "-复称下线");
|
var queryList = MongoDBSingleton.Instance.Find<packageInfoModel>(Query.And(Query.EQ("machineNo", model.machince), Query.EQ("trayCode", model.ext2), Query.EQ("weight2", "")), "packageInfoModel");
|
if (queryList.Count > 0)
|
{
|
packageInfoModel query = queryList.OrderByDescending(a => a.time).First();
|
if (query != null)
|
{
|
CMMLog.Debug($"machine:{query.machineNo},trayCode:{query.trayCode},weight:{query.weight}");
|
//读取复称平台的重量
|
double x = (double)Convert.ToInt32(Completion(trayCode.result[8]) + Completion(trayCode.result[9]), 2) / 100;
|
//double x = (double)Convert.ToInt32(Completion(result[8]) + Completion(result[9]), 2) / 100;
|
string weight = x.ToString();
|
CMMLog.Debug($"读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 28}里面数据为{trayCode.result[8]}.");
|
CMMLog.Debug($"读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 29}里面数据为{trayCode.result[9]}.");
|
CMMLog.Debug($"weight:{weight}");
|
|
//重量差值
|
string weightDifference = Math.Round((double.Parse(query.weight) - x), 2).ToString();
|
|
//将复称平台重量写入中间表
|
MongoDBSingleton.Instance.Update<packageInfoModel>(Query.And(Query.EQ("machineNo", model.machince), Query.EQ("time", query.time), Query.EQ("trayCode", query.trayCode), Query.EQ("weight2", "")), Update.Set("weight2", weight).Set("weightDifference", weightDifference), UpdateFlags.None);
|
|
}
|
else CMMLog.Debug($"数据查询失败");
|
}
|
else CMMLog.Debug($"packageInfoModel未找到数据,machineNo:{model.machince},trayCode:{model.ext2}");
|
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 3,
|
host = plc.ip,
|
port = plc.port,
|
data = 1
|
});
|
|
CMMLog.Debug($"复称任务任务生成完成,ip:{plc.ip},端口:{plc.port},写入通道{plc.writeAddr + 3} 的值为1");
|
|
//复称合格,更新表数据
|
var proInfo = MongoDBSingleton.Instance.FindOne<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", model.machince)), "ProductList");
|
if (proInfo != null)
|
{
|
proInfo.qualifiedQuantity = proInfo.qualifiedQuantity + 1;
|
proInfo.percentOfPass = Math.Round(((proInfo.qualifiedQuantity / proInfo.total) * 100), 2);
|
MongoDBSingleton.Instance.Update<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", model.machince)), Update.Set("percentOfPass", proInfo.percentOfPass).Set("qualifiedQuantity", proInfo.qualifiedQuantity), UpdateFlags.None);
|
}
|
}
|
else
|
{
|
ProcessHelper.recordInfo(plc.location + "-复称下线", "当前半成品库区未获取到可用货位,检查是否已满");
|
}
|
|
}
|
if (result.result[2] == 2)
|
{
|
CMMLog.Debug($"准备生成复称入缓存架NG任务,开始确定托盘号:{model.ext2}");
|
|
//复称平台复称货物NG——进入NG复称流程 调用WMS接口分配货架库位
|
req = WMSHelper.WMSIn(plc.location, model.ext2, ref wmstaskno, ref traycode, timeStamp);
|
if (req)
|
{
|
ProcessHelper.deleteInfo(plc.location + "-复称下线");
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 3,
|
host = plc.ip,
|
port = plc.port,
|
data = 1
|
});
|
CMMLog.Debug($"复称入缓存架NG流程:WMS生成任务成功!");
|
|
//更新复称平台的数据到中间表
|
var trayCode = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = plc.readAddr + 28,
|
dataNum = 2,//数据个数要增加
|
host = plc.ip,
|
port = plc.port
|
});
|
if (trayCode.errCode == 0 && trayCode.result.Length == 2)
|
{
|
var queryList = MongoDBSingleton.Instance.Find<packageInfoModel>(Query.And(Query.EQ("machineNo", model.machince), Query.EQ("trayCode", model.ext2), Query.EQ("weight2", "")), "packageInfoModel");
|
if (queryList.Count > 0)
|
{
|
packageInfoModel query = queryList.OrderByDescending(a => a.time).First();
|
if (query != null)
|
{
|
CMMLog.Debug($"machine:{query.machineNo},trayCode:{query.trayCode},weight:{query.weight}");
|
//读取复称平台的重量
|
double x = (double)Convert.ToInt32(Completion(trayCode.result[0]) + Completion(trayCode.result[1]), 2) / 100;
|
//double x = (double)Convert.ToInt32(Completion(result[8]) + Completion(result[9]), 2) / 100;
|
string weight = x.ToString();
|
CMMLog.Debug($"读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 28}里面数据为{trayCode.result[0]}.");
|
CMMLog.Debug($"读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 29}里面数据为{trayCode.result[1]}.");
|
CMMLog.Debug($"weight:{weight}");
|
|
//重量差值
|
string weightDifference = Math.Round((double.Parse(query.weight) - x), 2).ToString();
|
|
//将复称平台重量写入中间表
|
MongoDBSingleton.Instance.Update<packageInfoModel>(Query.And(Query.EQ("machineNo", model.machince), Query.EQ("time", query.time), Query.EQ("trayCode", query.trayCode), Query.EQ("weight2", "")), Update.Set("weight2", weight).Set("weightDifference", weightDifference), UpdateFlags.None);
|
}
|
else CMMLog.Debug($"数据查询失败");
|
}
|
else CMMLog.Debug($"packageInfoModel未找到数据,machineNo:{model.machince},trayCode:{model.ext2}");
|
}
|
}
|
else
|
{
|
ProcessHelper.recordInfo("复称下线", "当前NG库区未获取到可用货位,检查是否已满");
|
CMMLog.Debug($"复称入缓存架NG流程:WMS生成任务失败!");
|
}
|
}
|
string PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == "2").FirstOrDefault().location;
|
UpdateBuilder update = Update.Set("ng", result.result[2]);
|
if (MongoDBSingleton.Instance.Update<SecondWeighState>(Query.EQ("location", PlcBit02), update, "SecondWeighState", UpdateFlags.None))
|
{
|
CMMLog.Debug($"中间表SecondWeighState数据插入成功,location:{PlcBit02}");
|
}
|
if (req)
|
{
|
if (MongoDBSingleton.Instance.Remove<ActionControlModel>(Query.EQ("_id", model._id), "ActionControlModel", RemoveFlags.Single))
|
{
|
CMMLog.Debug($"中间表ActionControlModel数据删除成功,id:{model._id}");
|
}
|
}
|
}
|
else
|
{
|
ProcessHelper.recordInfo(plc.location + "-复称入缓存架","信号检测失败,请检查信号通道通讯是否正常");
|
}
|
}
|
else CMMLog.Debug($"复称平台未配置,ip:{model.ext1},端口:{model.ext3}");
|
}
|
|
|
private static void GetOKWeight(int[] result, string ItemCode)
|
{
|
var info = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("trayCode", ItemCode), "MachineInfo");
|
if(info != null)
|
{
|
CMMLog.Info($"从包装机获取的物料重量:{info.oneTrayWeight}");
|
var newWeight = Convert.ToInt32(Completion(result[0]) + Completion(result[1]), 2).ToString();
|
//更新数据
|
CMMLog.Info($"从复称平台获取的物料重量:{newWeight}");
|
|
UpdateBuilder update = Update.Set("oneTrayWeight", newWeight);
|
MongoDBSingleton.Instance.Update<MachineInfo>(Query.EQ("trayCode", ItemCode), update, "MachineInfo", UpdateFlags.None);
|
|
//MongoDBSingleton.Instance.Update<MachineInfo>(Query.EQ("trayCode", ItemCode), Update.Set("oneTrayWeight", info.oneTrayWeight), "MachineInfo", UpdateFlags.None);
|
CMMLog.Info("复称OK的重量更新到中间表MachineInfo");
|
}
|
|
var infoTwo = MongoDBSingleton.Instance.FindOne<MachineInfoTwo>(Query.EQ("trayCode", ItemCode), "MachineInfo");
|
if (infoTwo != null)
|
{
|
var newWeight = (Convert.ToInt32(Completion(result[8]) + Completion(result[9]), 2) / 100).ToString();
|
//var newWeight = result[8] + "," + result[9];
|
//更新数据
|
CMMLog.Info($"从复称平台获取的物料重量:{newWeight}");
|
|
UpdateBuilder update = Update.Set("oneTrayWeightFC", newWeight);
|
MongoDBSingleton.Instance.Update<MachineInfoTwo>(Query.EQ("trayCode", ItemCode), update, "MachineInfoTwo", UpdateFlags.None);
|
|
CMMLog.Info("复称毛重更新到中间表MachineInfoTwo");
|
}
|
}
|
|
|
#endregion
|
|
#endregion
|
|
#region 3楼复称平台入3楼双层缓存架流程——需回报WMS任务状态——3楼复称入缓存架——已完成(待测试)
|
|
/// <summary>
|
/// 判断复称通道3里面的值是否为1,并且复称平台上有货,调WMS生成入缓存架任务
|
/// </summary>
|
/// <param name="pmInfo"></param>
|
internal static void SecondWeightInCache(Settings.PlcInfo pmInfo)
|
{
|
//检查复称平台通道3是否值为1,并且复称平台上有货
|
if(ProcessHelper.CheckStartFree(GetSecondWeighBit()) && ProcessHelper.CheckEndFree(GetSecondWeighBit()))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr + 3,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
//复称平台 重新复核称重后,发送结果给AMS 1:OK,2:NG,当检测到通道2或者4的值为
|
if (result.result[0] == 1)
|
{
|
//判断一下当前复称点有没有任务占用中
|
if (ProcessHelper.CheckStartFree(GetSecondWeighBit()) && ProcessHelper.CheckEndFree(GetSecondWeighBit()))
|
{
|
//判断复称位置,产品NG合格值为1并且复称上有货
|
var state = GetSecondWeighState(pmInfo.location,"");
|
if (state.full == 1 && state.ng == 1)
|
{
|
//#region 获取托盘码
|
//CMMLog.Info("复称入缓存:获取托盘,fc01");
|
//string traycode = GetMachineTrayCode();
|
//#endregion
|
|
//string wmstaskno = "";
|
//bool req = WMSHelper.WMSIn(pmInfo.location, traycode, ref wmstaskno, ref traycode);
|
//if (req)
|
//{
|
// CMMLog.Info($"复称入缓存架:WMS生成任务成功!");
|
//}
|
//else
|
//{
|
// CMMLog.Info($"复称入缓存架:WMS生成任务失败!");
|
//}
|
}
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
}
|
|
#region 复称交互
|
public static int SecondRelax = 0;
|
/// <summary>
|
/// 请求进入复称取货
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void SecondWeightInCache1012(string ip, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
if (ip != null)
|
{
|
CMMLog.Info($"ip:{ip}");
|
///小车和复称位对接
|
if (ip != "")
|
{
|
//小车请求进料,并且查询设备是否允许AGV进入
|
WorkFlowAction.TrackLog(taskNo, 10, 1012, "success");
|
TSHelper.GoToAGV(taskNo, 10, 1);
|
SecondRelax = 0;
|
}
|
else CMMLog.Info($"复称入缓存架,1012,ip=null!");
|
}
|
else CMMLog.Info($"地址{ip}的设备为配置");
|
}
|
/// <summary>
|
/// 取货完成,离开复称,复位通道,并读取设备通道数据
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void SecondWeightInCache4(string ip, string taskNo)
|
{
|
CMMLog.Info("离开复称平台,任务处理开始");
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == ip).FirstOrDefault();
|
|
var trayCodeTask = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), "TN_I_TASK_MST");
|
if(trayCodeTask != null)
|
{
|
string trayCodeNo = trayCodeTask.CN_S_BATCH_NO;
|
if(trayCodeNo != "")
|
{
|
//var status = MongoDBSingleton.Instance.FindOne<SecondWeighState>(Query.EQ("location", GetSecondWeighBit()), "SecondWeighState");
|
//UpdateBuilder update = Update.Set("full", 0);
|
//if (status.ng != 2)
|
//{
|
// update = Update.Set("ng", 0).Set("full", 0);
|
//}
|
UpdateBuilder update = Update.Set("full", 0).Set("ng",0);
|
CMMLog.Info($"开始更改复称状态中间表状态:full:0");
|
CMMLog.Info($"三楼双层缓存架卸货交互:trayCode:{trayCodeTask.CN_S_BATCH_NO}");
|
if (MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("trayCode", trayCodeTask.CN_S_BATCH_NO), "MachineInfo", RemoveFlags.Single))
|
{
|
CMMLog.Info($"删除中间表MachineInfo的数据成功,tray:{trayCodeTask.CN_S_BATCH_NO}");
|
}
|
else
|
{
|
CMMLog.Info($"删除中间表MachineInfo的数据失败,tray:{trayCodeTask.CN_S_BATCH_NO}");
|
|
}
|
if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("trayCode", trayCodeTask.CN_S_BATCH_NO), "MachineInfoTwo", RemoveFlags.Single);
|
//MongoDBSingleton.Instance.Update<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), Update.Set("CN_S_BATCH_NO", trayCodeNo), UpdateFlags.None);
|
MongoDBSingleton.Instance.Update<SecondWeighState>(Query.EQ("location", plc.location), update, "SecondWeighState", UpdateFlags.None);
|
}
|
}
|
if (plc != null)
|
{
|
var writeRes1 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr + 3,// + 4
|
data = 1,
|
port = plc.port
|
});
|
|
//通道写入4,ok流程可以直接写,ng流程需要等到小车取货完之后写入(注:该流程测试通过,暂时可以不改,现场出现问题在更改)
|
//var writeRes1 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
//{
|
// host = plc.ip,
|
// addr = plc.writeAddr + 3,
|
// data = 1,
|
// port = plc.port
|
//});
|
}
|
}
|
|
#endregion
|
|
#region 三楼双层缓存架交互
|
|
/// <summary>
|
/// 请求进入三楼双层缓存架
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void SecondWeightInCache1013(string taskNo)
|
{
|
TSHelper.GoToAGV(taskNo,10,3);
|
}
|
/// <summary>
|
/// 离开三楼双层缓存架回报信息
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static bool SecondWeightInCache6(string ip, string cN_S_TASK_NO)
|
{
|
//CMMLog.Info($"三楼双层缓存架卸货交互:trayCode:{trayCode}");
|
//MongoDBSingleton.Instance.Remove<MachineInfo>(Query.Not(Query.EQ("trayCode", trayCode)), RemoveFlags.Single);
|
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
|
if (plc != null)
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 28,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
var tray = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", cN_S_TASK_NO), "TN_I_TASK_MST");
|
MongoDBSingleton.Instance.Update<MachineInfo>(Query.EQ("trayCode", tray.CN_S_BATCH_NO), Update.Set("secondNg", result.result[2]), UpdateFlags.None);
|
//获取从复称平台读出的 时间戳,并转换处理为 string 字符串
|
string timeStamp = Convert.ToInt32(Completion(result.result[26]) + Completion(result.result[27]), 2).ToString();
|
string wmstaskno = "";
|
string traycode = "";
|
if (result.result[0] == 3 && result.result[2] == 1)
|
{
|
CMMLog.Debug($"准备生成复称入缓存架任务,开始确定托盘号:{tray.CN_S_BATCH_NO}");
|
bool req = WMSHelper.WMSIn(plc.location, tray.CN_S_BATCH_NO, ref wmstaskno, ref traycode, timeStamp);
|
if (req) TSHelper.GoToAGV(cN_S_TASK_NO, 10, 6);
|
else CMMLog.Debug($"WMS返回{req}");
|
}
|
if (result.result[2] == 2)
|
{
|
//复称平台复称货物NG——进入NG复称流程 调用WMS接口分配货架库位
|
TSHelper.GoToAGV(cN_S_TASK_NO, 10, 6);
|
bool req = WMSHelper.WMSIn(plc.location, tray.CN_S_BATCH_NO, ref wmstaskno, ref traycode, timeStamp);
|
if (req) CMMLog.Debug($"复称入缓存架NG流程:WMS生成任务成功!");
|
else CMMLog.Debug($"复称入缓存架NG流程:WMS生成任务失败!");
|
}
|
string PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == "2").FirstOrDefault().location;
|
CMMLog.Info($"SecondWeighState改值开始,时间:{DateTime.Now}");
|
UpdateBuilder update = Update.Set("ng", result.result[2]).Set("full", 1);
|
MongoDBSingleton.Instance.Update<SecondWeighState>(Query.EQ("location", PlcBit02), update, UpdateFlags.None);
|
CMMLog.Info($"SecondWeighState该full值为1,时间:{DateTime.Now}");
|
}
|
else CMMLog.Debug($"包装下线,1213,ip=null!");
|
|
|
return true;
|
}
|
|
#endregion
|
|
#endregion
|
|
#region 3楼双层缓存货架到三楼叠托口——需回报WMS任务状态——3楼缓存架入叠托——半完成(待测试)
|
|
/// <summary>
|
/// 判断三楼叠托口是否有允许上料请求(通道1参数1),有就调WMS生成缓存架到叠托口任务
|
/// </summary>
|
/// <param name="pmInfo"></param>
|
internal static void CacheStackingMouth(Settings.PlcInfo pmInfo)
|
{
|
//需要设置时间延迟
|
try
|
{
|
//读取通道1里面参数是否为1,判断叠盘机是否需要上料
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 3,
|
addr = pmInfo.readAddr + 1,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
//参数1表示叠托点申请入料
|
if (result.result[0] == 1)
|
{
|
var tasks = MongoDBSingleton.Instance.Find<TN_I_TASK_MST>(Query.EQ("CN_S_END_BIT", pmInfo.location), "TN_I_TASK_MST");
|
//判断一下当前叠托点是否有任务占用
|
if (ProcessHelper.CheckEndFree(pmInfo.location) && tasks.Count == 0)
|
{
|
string trayType = result.result[2] == 1 ? "田字托" : result.result[2] == 2 ? "川字托" : "4小包";
|
if (result.result[2] >= 1 && result.result[2] <= 3)
|
{
|
//可以生成任务,调WMS接口获取任务信息
|
bool req = WMSHelper.WMSOut(pmInfo.location, "", trayType);
|
if (req) CMMLog.Debug($"调用WMS获取碟盘出库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
|
else CMMLog.Debug($"调用WMS获取碟盘出库生成任务失败!");
|
}
|
else CMMLog.Debug($"CacheStackingMouth: 托盘类型不正确,托盘类型:{result.result[2]}");
|
|
}
|
else CMMLog.Debug($"检查当前叠托点是否有任务占用,或者MST主表中有缓存架入叠盘机的任务!");
|
}
|
}
|
else CMMLog.Debug($"缓存入叠盘机,创建任务,result={result.errMsg}");
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
|
#region 三楼叠托机交互
|
|
/// <summary>
|
/// 请求进入三楼叠托机
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void CacheStackingMouth1013(string ip,string taskNo, string CN_S_END_BIT)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == ip).FirstOrDefault();
|
if(plc != null)
|
{
|
var readres = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (readres.result[0] == 0 || readres.result[0] == 1)
|
{
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
host = plc.ip,
|
port = plc.port,
|
data = 1
|
});
|
}
|
else if (readres.result[0] == 2)
|
{
|
TSHelper.GoToAGV(taskNo, 10, 3);
|
}
|
}
|
else CMMLog.Debug($"缓存入叠盘机,1013,plc=null!");
|
}
|
|
/// <summary>
|
/// 三楼叠托机扫码
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void CacheStackingMouth1313(string dev,string taskNo)
|
{
|
CMMLog.Info($"【叠包入口】任务流程处理开始------------");
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == dev).FirstOrDefault();
|
if(plc != null)
|
{
|
var readres = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 2,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if(readres != null)
|
{
|
var taskInfo = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), "TN_I_TASK_MST");
|
CMMLog.Info($"【叠包入口】读取通道{plc.readAddr + 1}的信号为[{readres.result[0]}],收到通道{plc.readAddr + 2}的信号为[{readres.result[1]}]");
|
if (readres.result[0] == 3)
|
{
|
if (readres.result[1] == 1)
|
{
|
CMMLog.Info($"读码信息比对结果:条码与传送的数据一致");
|
//读码信息比对结果:OK 读到通道2参数为1时,小车将托盘放置在叠盘机上(改参数10为7)
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
host = plc.ip,
|
data = 3,//4
|
port = plc.port
|
});
|
CMMLog.Info($"【叠包入口】写入通道{plc.writeAddr + 1}的信号为{3},返回值:{wirte.errCode}");
|
if (wirte.errCode == 0)
|
{
|
//并删除WMSInfo中间表中对应托盘号的数据(也可在小车离开叠盘机之后删除,暂定通道2参数1)
|
CMMLog.Info($"读码信息比对结果:OK ,并删除WMSInfo中间表中对应托盘号的数据");
|
MongoDBSingleton.Instance.Remove<WMSInfo>(Query.EQ("trayCode", taskInfo.CN_S_BATCH_NO), RemoveFlags.Single);
|
TSHelper.GoToAGV(taskNo, 10, 7);
|
}
|
|
//通道写入4,ok流程可以直接写,ng流程需要等到小车取货完之后写入(注:该流程测试通过,暂时可以不改,现场出现问题在更改)
|
PLCControl.CacheStackingMouth6(plc);
|
}
|
else if(readres.result[1] == 2)
|
{
|
CMMLog.Info($"读码信息比对结果:条码与传送的数据不一致");
|
//二期--调用 WMS 改道接口 获取 目标点位,并 更改 AGV 站点
|
string ChangeBit = WMSHelper.WmsUpdateWay(taskInfo.CN_S_SOURCE_NO, plc.Extend);
|
if (!string.IsNullOrEmpty(ChangeBit))
|
{
|
ProcessHelper.deleteInfo("叠包NG");
|
CMMLog.Info($"起点:{taskInfo.CN_S_END_BIT}");
|
CMMLog.Info($"终点:{ChangeBit}");
|
int[] parms = { StockInstance.Instance.GetAGVCodeForBitCode(taskInfo.CN_S_END_BIT), StockInstance.Instance.GetAGVCodeForBitCode(ChangeBit) };
|
//TSHelper.ChangeParam(taskNo, 1, StockInstance.Instance.GetAGVCodeForBitCode(taskInfo.CN_S_END_BIT));
|
//TSHelper.ChangeParam(taskNo, 2, StockInstance.Instance.GetAGVCodeForBitCode(ChangeBit));
|
TSHelper.ChangeParam(taskNo, 1, parms);
|
TSHelper.GoToAGV(taskNo, 3, 1);
|
TSHelper.GoToAGV(taskNo, 10, 8);
|
|
MongoDBSingleton.Instance.Update<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), Update.Set("CN_S_END_BIT", ChangeBit).Set("CN_S_START_BIT", taskInfo.CN_S_END_BIT), "TN_I_TASK_MST", UpdateFlags.None);
|
|
MongoDBSingleton.Instance.Remove<WMSInfo>(Query.EQ("trayCode", taskInfo.CN_S_BATCH_NO), RemoveFlags.Single);
|
|
}
|
else
|
{
|
CMMLog.Debug($"调用WMS改道接口,未获取到可用点位。");
|
ProcessHelper.recordInfo("叠包NG","NG库区未获取到可用货位,检查NG库区是否已满");
|
}
|
}
|
|
}
|
}
|
}
|
CMMLog.Info($"【叠包入口】任务流程处理结束------------");
|
}
|
|
/// <summary>
|
/// 卸货离开三楼叠托机--二期:需要和TS对接,让小车 卸货完成等到 小车离开之后再发送
|
/// </summary>
|
/// <param name="ip"></param>
|
internal static bool CacheStackingMouth6(Settings.PlcInfo plc)
|
{
|
bool result = false;
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
data = 4,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (wirte.errCode == 0) result = true;
|
return result;
|
}
|
#endregion
|
|
#endregion
|
|
#region 3楼包装机空托补给3楼包装机流程——无需回报WMS任务状态——3楼包装补空——已完成(待测试)
|
|
/// <summary>
|
/// 3楼包装机补空托流程——任务开始前,判断包装机有没有下线信号,并判断当前包装机对应的地堆位是否有任务占用
|
/// </summary>
|
/// <param name="pmInfo"></param>
|
internal static void PickUpBlank(Settings.PlcInfo pmInfo)
|
{
|
/* 包装补空流程:
|
* 先判断包装机是否有任务占用,若无任务占用则判断是否需要补空托
|
* 判断起点是否有任务占用
|
* **/
|
|
//包装补空缺陷,同时会有两个空托点补一个包装机
|
|
try
|
{
|
if (ProcessHelper.PickUpEndFree(pmInfo.location))
|
{
|
//读取输入寄存器还是输出寄存器待定,读取通道0的数据
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
|
CMMLog.Info($"包装机补空托流程:判断包装机通道{pmInfo.readAddr}值为{JsonConvert.SerializeObject(result)},ip:{pmInfo.ip}");
|
if (result != null && result.errCode == 0)
|
{
|
//1:取料;3:人工叫空托盘
|
if (result.result[0] == 3)
|
{
|
//包装线补空流程
|
//判断空托缓存点(5 对 2)是否有空托,有空托判断是否有任务,有任务则判断另一个点位
|
var locInfo = Settings.GetAGVLocationList().Where(b => b.machineLoc.Contains(pmInfo.location) && b.Enabel == 1).First();
|
if (locInfo != null)
|
{
|
CMMLog.Info($"包装机点位:{pmInfo.location}");
|
foreach(var a in locInfo.ddLoc)
|
{
|
if (ProcessHelper.PickUpEndFree(pmInfo.location) && ProcessHelper.PickUpStartFree(a))
|
{
|
var empInfo = MongoDBSingleton.Instance.FindOne<BZEmptyPoint>(Query.EQ("Bit", a), "BZEmptyPoint");
|
if (empInfo != null && empInfo.Quantity > 0)
|
{
|
CMMLog.Info($"包装线补空任务,包装机点位:{pmInfo.location},周转托盘位:{a},周转托盘位数量:{empInfo.Quantity}");
|
HHAmsExecuteResult amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), a, pmInfo.location, "包装线补空", 0, "");
|
if (amsResult.success)
|
{
|
CMMLog.Info($"包装线补空任务生成成功");
|
break;
|
}
|
}
|
}
|
}
|
}
|
else
|
{
|
CMMLog.Info("配置文件未配置包装机空托缓存点");
|
}
|
}
|
}
|
else
|
{
|
CMMLog.Info($"err 包装机通道{pmInfo.readAddr} ip:{pmInfo.ip}");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
|
static object PickUpBlankCompleteLock = new object();
|
|
/// <summary>
|
/// 包装补空任务完成--复位 收到上空信号 为 0
|
/// </summary>
|
/// <param name="PlcBitCache01"></param>
|
internal static void PickUpBlankComplete(string PlcBitCache01,string Extend = "")
|
{
|
lock (PickUpBlankCompleteLock)
|
{
|
CMMLog.Info("包装线补空流程任务处理");
|
try
|
{
|
if (Extend != "")
|
{
|
CMMLog.Info($"当前周转托盘位:{Extend}");
|
int addr = 0;
|
int qun = 0;
|
//修改中间表的值,若中间表的数量为0,则调用解绑方法
|
var bzEmp = MongoDBSingleton.Instance.FindOne<BZEmptyPoint>(Query.EQ("Bit", Extend), "BZEmptyPoint");
|
if (bzEmp != null)
|
{
|
CMMLog.Info($"当前货位的数量:{bzEmp.Quantity}");
|
if (bzEmp.Quantity == 1)
|
{
|
CMMLog.Info($"调用解绑接口");
|
//解绑
|
if (WMSHelper.WMSEmptyUnbind(Extend))
|
{
|
//删除中间表数据
|
MongoDBSingleton.Instance.Remove<BZEmptyPoint>(Query.EQ("Bit", Extend), RemoveFlags.Single);
|
}
|
}
|
else
|
{
|
var quantity = bzEmp.Quantity - 1;
|
var updateBuider = Update.Set("Quantity", quantity);
|
MongoDBSingleton.Instance.Update<BZEmptyPoint>(Query.EQ("Bit", Extend), updateBuider, UpdateFlags.None);
|
CMMLog.Info($"减去当前周转托盘位数量之后,数量为:{quantity}");
|
qun = quantity;
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error($"PickUpBlankComplete Error:" +ex.Message);
|
}
|
}
|
|
}
|
|
#endregion
|
|
#region 3楼补给成品空托区到3楼拆盘机流程——需回报WMS任务状态——3楼拆盘补空——已完成(待测试)
|
|
/// <summary>
|
/// 线程循环查询拆盘机是否需要补空托
|
/// </summary>
|
/// <param name="plc"></param>
|
internal static void CheckPackingLineEmpty(Settings.PlcInfo plc)
|
{
|
//读plc信号,看有没有叫料请求,判断是否已经有任务
|
//没有任务,调WMS生成空托补充任务
|
try
|
{
|
//RegisterReadInPut 读取输入寄存器还是输出寄存器待定,读取通道1的数据
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 2,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
//1.补空托盘
|
if (result.result[0] == 1)
|
{
|
//判断3楼拆盘机(补空托盘点位)终点是否有任务占用,没有则生成任务
|
if (ProcessHelper.CheckEndFree(plc.location))
|
{
|
string wmstaskno = "";
|
string traycode = "";
|
string trayType = "";
|
if (result.result[1] == 1) trayType = "田字托";
|
else trayType = "川字托";
|
//bool req = WMSHelper.WMSEmptyOut(plc.location, "",ref wmstaskno, ref traycode);
|
bool req = WMSHelper.WMSEmptyOut(plc.location, "",trayType, ref wmstaskno, ref traycode);
|
if (req) CMMLog.Debug($"调用WMS获取三楼拆盘机生成任务成功!");
|
else CMMLog.Debug($"调用WMS获取三楼拆盘机生成任务失败!");
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
|
#region 拆盘机交互
|
|
/// 小车请求出料 1 AMS写,PLC读 1-请求出料;2-出料进行中;3-动作完成
|
/// 设备允许进料 1 PLC写,AMS读 1-允许进料;2-进料进行中;3-动作完成
|
/// <summary>
|
/// 向拆盘机请求卸货
|
/// </summary>
|
/// <param name="ips"></param>
|
internal static void DiscRemoverReqUnload(string ip, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == ip).FirstOrDefault();
|
if (plc != null)
|
{
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
host = plc.ip,
|
port = plc.port,
|
data = 1
|
});
|
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.readAddr + 1
|
});
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if (readRes.result[0] == 0 || readRes.result[0] == 1)
|
{
|
//不允许进料,ams写入请求出料
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr + 1,
|
data = 1
|
});
|
}
|
else if (readRes.result[0] == 2)
|
{
|
//设备允许进料
|
//改参数通知agv
|
if (TSHelper.GoToAGV(taskNo, 10, 3))
|
{
|
WorkFlowAction.TrackLog(taskNo, 10, 1013, "success");
|
//改成出料进行中
|
CMMLog.Debug("三楼拆盘机:小车正在卸空盘中!");
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr + 1,
|
data = 2
|
});
|
}
|
else CMMLog.Debug($"三楼拆盘补空,1013,TS,10,3,false!");
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 小车卸货完成离开通知拆盘机
|
/// </summary>
|
/// <param name="ips"></param>
|
/// <param name="taskNo"></param>
|
internal static bool DiscRemoverUnloadComplete(string ip, string taskNo)
|
{
|
var result = false;
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == ip).FirstOrDefault();
|
if (plc != null)
|
{
|
//1.0 读地址1设备是否动作完成
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.readAddr + 1
|
});
|
CMMLog.Info($"读{plc.ip}取通道{plc.readAddr + 1}的数据为{readRes.result[0]}");
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if (readRes.result[0] == 2)
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr + 1,
|
data = 3
|
});
|
CMMLog.Info($"写入{plc.ip}通道{plc.writeAddr + 1}的数据为{3}");
|
result = true;
|
CMMLog.Debug("读取设备【参数不为0】,AMS设置小车【动作完成】,等待设备【参数为0】时再改参数通知agv");
|
}
|
}
|
}
|
else CMMLog.Info($"deviceType:{ip},未找到");
|
return result;
|
}
|
|
#endregion
|
|
#endregion
|
|
#region 3楼叠盘机满托下线入库流程——需回报WMS任务状态——3楼叠盘下线--已完成(待测试)
|
|
/// <summary>
|
/// 线程循环查询叠盘机是否需要下满托
|
/// </summary>
|
/// <param name="plc"></param>
|
internal static void StackingLineEmpty(Settings.PlcInfo plc)
|
{
|
//读plc信号,看有没有叫料请求,判断是否已经有任务
|
//没有任务,调WMS生成空托补充任务
|
try
|
{
|
//RegisterReadInPut 读取输入寄存器还是输出寄存器待定,读取通道1的数据
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
//1.满托下线
|
if (result.result[0] == 1)
|
{
|
//判断3楼叠盘起点是否有任务占用,没有则生成任务
|
if (ProcessHelper.CheckStartFree(plc.location))
|
{
|
string wmstaskno = "";
|
string traycode = "";
|
bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
|
if (req)
|
{
|
CMMLog.Debug($"调用WMS获取三楼叠盘机生成任务成功!");
|
ProcessHelper.deleteInfo("叠盘下线");
|
}
|
else
|
{
|
ProcessHelper.recordInfo("叠盘下线", "叠盘机下线库区未查询到可用货位,检查叠盘机下线库区是否已满");
|
CMMLog.Debug($"调用WMS获取三楼叠盘机生成任务失败!");
|
}
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
|
#region 叠盘机交互
|
|
/// 小车请求出料 1 AMS写,PLC读 1-请求出料;2-出料进行中;3-动作完成
|
/// 设备允许进料 1 PLC写,AMS读 1-允许进料;2-进料进行中;3-动作完成
|
/// <summary>
|
/// 向叠盘机请求取货
|
/// </summary>
|
/// <param name="ips"></param>
|
internal static void StackingReqUnload(string ip, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == ip).FirstOrDefault();
|
if (plc != null)
|
{
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
host = plc.ip,
|
port = plc.port,
|
data = 1
|
});
|
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.readAddr + 1
|
});
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if (readRes.result[0] == 0 || readRes.result[0] == 1)
|
{
|
//不允许进料,ams写入请求出料
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr + 1,
|
data = 1
|
});
|
}
|
else if (readRes.result[0] == 2)
|
{
|
//设备允许进料
|
//改参数通知agv
|
if (TSHelper.GoToAGV(taskNo, 10, 1))
|
{
|
WorkFlowAction.TrackLog(taskNo, 10, 1013, "success");
|
//改成出料进行中
|
CMMLog.Debug("三楼叠盘机:小车正在取托盘中!");
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr + 1,
|
data = 2
|
});
|
}
|
else CMMLog.Debug($"三楼叠盘机,1013,TS,10,3,false!");
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 小车取货完成离开通知叠盘机
|
/// </summary>
|
/// <param name="ips"></param>
|
/// <param name="taskNo"></param>
|
internal static bool StackingComplete(string ip, string taskNo)
|
{
|
var result = false;
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == ip).FirstOrDefault();
|
if (plc != null)
|
{
|
//1.0 读地址1设备是否动作完成
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr + 1,
|
data = 3
|
});
|
result = true;
|
CMMLog.Debug("读取设备【参数不为0】,AMS设置小车【动作完成】,等待设备【参数为0】时再改参数通知agv");
|
}
|
return result;
|
}
|
|
#endregion
|
|
#endregion
|
|
#region 包装线补空任务
|
internal static void PackingLine(string ip, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
//ASM写入小车动作,1:上料复称;2:上砝码教称;3:取复称NG托盘,4:取砝码到包装机
|
int[] num = new int[1] { 1 };
|
var writeRes0 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
host = ip,
|
addr = plc.writeAddr + 2,
|
data = num,//原先是1,单个写入
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为1.");
|
//Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为1.");
|
///小车和复称位对接
|
//小车请求进料,并且查询设备是否允许AGV进入
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
host = plc.ip,
|
addr = plc.readAddr + 2,
|
port = plc.port
|
});
|
CMMLog.Debug($"读取设备{plc.location}通道{plc.readAddr + 2}里面数据为{JsonConvert.SerializeObject(readRes)}.");
|
//Console.WriteLine($"读取设备{plc.location}通道{plc.readAddr + 2}里面数据为{readRes.result[0]}.");
|
if (readRes != null && readRes.errCode == 0)
|
{
|
if (readRes.result[0] == 2)
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = ip,
|
addr = plc.writeAddr + 2,
|
data = 2,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为2.");
|
//Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为2.");
|
|
WorkFlowAction.TrackLog(taskNo, 10, 1013, "success");
|
TSHelper.GoToAGV(taskNo, 10, 3);
|
}
|
}
|
}
|
#endregion
|
|
#endregion
|
|
#region 跨楼层任务
|
|
#region 货物入库流程——满托入库
|
|
#region 收到打包机下线信号,判断条件是否允许,选择性下发任务
|
/// <summary>
|
/// 3楼打包机下线,判断打包机是否由生成打包下线的任务,如果有,自己生成两条任务
|
/// </summary>
|
/// <param name="plc"></param>
|
internal static void CheckPackingLineFull(Settings.PlcInfo plc)
|
{
|
//读plc信号,看有没有下线请求,判断是否已经有任务
|
//没有任务,继续plc,包装下线的物料信号
|
//检查打包机通道1是否有出料任务信号,如果有生成取料任务。
|
if (CheckStartFree(plc.location))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1)
|
{
|
//获取MODBUS通道里面存放的时间戳
|
var resultTime = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = plc.readAddr + 10,
|
host = plc.ip,
|
port = plc.port,
|
dataNum = 2
|
});
|
if (resultTime.errCode == 0)
|
{
|
string wmstaskno = "";
|
string traycode = "";
|
if (Settings.packChange == "0")
|
{
|
string timeCuoData = (resultTime.result[0] * 65536 + resultTime.result[1]).ToString();
|
CMMLog.Info($"获取到的MODBUS时间戳:{timeCuoData}");
|
//Console.WriteLine($"获取到的MODBUS时间戳:{timeCuoData}");
|
//这里需要调用照相机接口,获取数据存入中间表,等到入库流程完成,将数据传送给WMS
|
string deviceNo = "";
|
var timecuo = TimeCuo(timeCuoData, ref deviceNo);
|
if (timecuo != null)
|
{
|
string timeStamp = timecuo.data.First().timeStamp.ToString();
|
//bool req = WMSHelper.WMSIn(plc.location, "time", ref wmstaskno, ref timeStamp, timeStamp);
|
|
# region 打包下线任务
|
//判断电动连接门是否关门到位
|
var plcInfoList = Settings.GetPlcInfo().Where(a => a.device == "25").ToList();
|
if (plcInfoList.Count > 0)
|
{
|
//获取MODBUS通道里面存放的时间戳
|
var result1 = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = plcInfoList[0].readAddr,
|
host = plc.ip,
|
port = plc.port,
|
dataNum = 1
|
});
|
var result2 = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = plcInfoList[1].readAddr,
|
host = plc.ip,
|
port = plc.port,
|
dataNum = 1
|
});
|
CMMLog.Debug($"打包下线流程:读取电动门1的通道号为:{plcInfoList[0].readAddr}的值为:{result1.result[0]}");
|
CMMLog.Debug($"打包下线流程:读取电动门2的通道号为:{plcInfoList[1].readAddr}的值为:{result1.result[0]}");
|
if (result1 != null && result2 != null && result1.errCode == 0 && result2.errCode == 0)
|
{
|
if (result1.result[0] == 2 && result2.result[0] == 2)
|
{
|
//可生成入立库任务
|
var CBInfo = Settings.GetConnectingbitsList().Where(a => a.enable == 1).ToList();
|
if (CBInfo != null)
|
{
|
foreach (var a in CBInfo)
|
{
|
if (!string.IsNullOrEmpty(a.locCode))
|
{
|
//在中间表中查找点位
|
var CBTable = MongoDBSingleton.Instance.FindOne<ConnectingBits>(Query.EQ("Bit", a.locCode), "ConnectingBits");
|
if (CBTable != null && string.IsNullOrEmpty(CBTable.trayCode))
|
{
|
//生成任务,并且将点位写入中间表
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "3楼打包下线", 0, traycode);
|
if (amsResult.success)
|
{
|
CMMLog.Debug($"3楼打包下线:任务生成成功!");
|
MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("Bit", a.locCode), Update.Set("trayCode", traycode), UpdateFlags.None);
|
break;
|
}
|
else CMMLog.Debug($"3楼打包下线:任务生成失败!");
|
}
|
else
|
{
|
//生成任务,并且将点位写入中间表
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "3楼打包下线", 0, traycode);
|
if (amsResult.success)
|
{
|
CMMLog.Debug($"3楼打包下线:任务生成成功!");
|
MongoDBSingleton.Instance.Insert<ConnectingBits>(new ConnectingBits { Bit = a.locCode, trayCode = traycode, state = "0" });
|
break;
|
}
|
else CMMLog.Debug($"3楼打包下线:任务生成失败!");
|
}
|
}
|
else CMMLog.Info("打包下线口接驳位点位未配置");
|
}
|
}
|
else CMMLog.Info("打包下线口接驳位未配置");
|
}
|
else
|
{
|
//生成到成品货架的任务
|
if (WMSHelper.WMSIn(plc.location, "打包下线", ref wmstaskno, ref timeStamp, timeStamp, "CPHJ"))
|
{
|
CMMLog.Debug($"3楼打包下线:AMS调用API成功!");
|
}
|
else CMMLog.Debug($"3楼打包下线:AMS调用API失败,开始重新调用!");
|
}
|
}
|
else CMMLog.Info("连廊 电动门的信息未配置");
|
}
|
#endregion
|
}
|
else CMMLog.Info($"时间戳接口返回值为空!");
|
}
|
else if (Settings.packChange == "1")
|
{
|
bool req = WMSHelper.WMSIn(plc.location, "打包下线", ref wmstaskno, ref traycode, "CPHJ");
|
}
|
}
|
else CMMLog.Info($"MODBUS时间戳数据返回值错误:返回值解析:{JsonConvert.SerializeObject(result)}");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message);
|
}
|
}
|
}
|
|
internal static void CheckPackingLineFull1(Settings.PlcInfo plc)
|
{
|
//读plc信号,看有没有下线请求,判断是否已经有任务
|
//没有任务,继续plc,包装下线的物料信号
|
//检查打包机通道1是否有出料任务信号,如果有生成取料任务。
|
if (CheckStartFree(plc.location))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Debug($"打包下线流程:读取通道号为:{plc.readAddr + 1},ip:{plc.ip},端口:{plc.port}");
|
CMMLog.Debug($"值为:{result.result[0]}");
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1)
|
{
|
//获取MODBUS通道里面存放的时间戳
|
var resultTime = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = plc.readAddr + 10,
|
host = plc.ip,
|
port = plc.port,
|
dataNum = 2
|
});
|
if (resultTime.errCode == 0)
|
{
|
string timeCuoData = (resultTime.result[0] * 65536 + resultTime.result[1]).ToString();
|
CMMLog.Info($"获取到的MODBUS时间戳:{timeCuoData},地址:{plc.ip},端口:{plc.port},通道:{plc.readAddr + 10}、{plc.readAddr + 11}");
|
//Console.WriteLine($"获取到的MODBUS时间戳:{timeCuoData}");
|
//这里需要调用照相机接口,获取数据存入中间表,等到入库流程完成,将数据传送给WMS
|
string deviceNo = "";
|
var timecuo = TimeCuo(timeCuoData, ref deviceNo);
|
string traycode = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
|
//可生成任务
|
var CBInfo = Settings.GetConnectingbitsList().Where(a => a.enable == 1).ToList();
|
if (CBInfo != null && timecuo != null)
|
{
|
string timeStamp = timecuo.data.First().timeStamp.ToString();
|
foreach (var a in CBInfo)
|
{
|
if (!string.IsNullOrEmpty(a.locCode))
|
{
|
//在中间表中查找点位
|
var CBTable = MongoDBSingleton.Instance.FindOne<ConnectingBits>(Query.EQ("Bit", a.locCode), "ConnectingBits");
|
if (CBTable != null)
|
{
|
if (string.IsNullOrEmpty(CBTable.trayCode))
|
{
|
//生成任务,并且将点位写入中间表
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "3楼打包下线", 0, traycode);
|
if (amsResult.success)
|
{
|
CMMLog.Debug($"3楼打包下线:AMS调用API成功!");
|
MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("Bit", a.locCode), Update.Set("trayCode", traycode).Set("timeCuo", timeStamp), UpdateFlags.None);
|
|
break;
|
}
|
else CMMLog.Debug($"3楼打包下线:AMS调用API失败,开始重新调用!");
|
}
|
}
|
else
|
{
|
//生成任务,并且将点位写入中间表
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "3楼打包下线", 0, traycode);
|
if (amsResult.success)
|
{
|
CMMLog.Debug($"3楼打包下线:AMS调用API成功!");
|
//打包下线任务生成成功,向中间表插入数据
|
|
MongoDBSingleton.Instance.Insert<ConnectingBits>(new ConnectingBits { Bit = a.locCode, trayCode = traycode, state = "0",timeCuo = timeStamp });
|
break;
|
}
|
else CMMLog.Debug($"3楼打包下线:AMS调用API失败,开始重新调用!");
|
}
|
}
|
else CMMLog.Debug("打包下线口接驳位点位未配置");
|
}
|
}
|
else CMMLog.Debug("打包下线口接驳位未配置");
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Debug(ex.Message+ "CheckPackingLineFull1");
|
}
|
}
|
}
|
|
|
public class MATERIALSync
|
{
|
public ObjectId _id { get; set; }
|
/// <summary>
|
/// 名称
|
/// </summary>
|
public string FName { get; set; }
|
/// <summary>
|
/// 流水号
|
/// </summary>
|
public string FNumber { get; set; }
|
public string FExpUnit { get; set; }
|
public string FStoreUnit { get; set; }
|
/// <summary>
|
/// 员工编号
|
/// </summary>
|
public string EMP_FNumber { get; set; }
|
/// <summary>
|
/// 员工名称
|
/// </summary>
|
public string EMP_FName { get; set; }
|
public DateTime time { get; set; }
|
}
|
|
#endregion
|
|
#region 打包机出口MODBUS交互(开始取料,取料完成)
|
|
/// 小车请求进料 1 AMS写,PLC读 1-AGV到位信号;2-到位后,请求接驳滚动;3-取货完成;
|
/// 设备允许出料 1 PLC写,AMS读 1-设备请求出料;2-允许进入;3-确认货物取走,送出物料;
|
|
///打包线下线——小车开始取货
|
internal static void PackingLineUnload1012(string ip, string taskNo)
|
{
|
CMMLog.Info($"【打包下线】起点安全请求进入流程处理开始--------");
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == "4").FirstOrDefault();
|
if (plc != null)
|
{
|
try
|
{
|
var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (readRes != null && readRes.errCode == 0)
|
{
|
CMMLog.Info($"【打包下线】读取通道{plc.readAddr + 1}的数据为:{readRes.result[0]}");
|
if (readRes.result[0] == 1)
|
{
|
var write = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
data = 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Info($"【打包下线】写入通道{plc.writeAddr + 1}的数据为:{1}");
|
}
|
else if (readRes.result[0] == 2)
|
{
|
TSHelper.GoToAGV(taskNo, 10, 1);
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
data = 2,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Info($"【打包下线】写入通道{plc.writeAddr + 1}的数据为:{2}");
|
}
|
}
|
else CMMLog.Info($"【打包下线】读取通道{plc.readAddr + 1}的数据失败");
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info(ex.Message);
|
}
|
}
|
else CMMLog.Info($"ip为:{ip}的设备未配置");
|
CMMLog.Info($"【打包下线】起点安全请求进入流程处理结束--------");
|
}
|
|
/// <summary>
|
/// 打包线下线——小车取货完成
|
/// </summary>
|
/// <param name="ip"></param>
|
/// <param name="taskNo"></param>
|
internal static void PackingLineComplete4(string ip, string taskNo)
|
{
|
CMMLog.Info($"【打包下线】起点安全请求退出流程处理开始-------------");
|
//取货完成后需要读取设备时间戳里面的数据,并将其暂存至中间表等到入库任务完成传输给WMS
|
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == "4").FirstOrDefault();
|
if (plc != null)
|
{
|
try
|
{
|
//var readRes = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
//{
|
// dataNum = 1,
|
// addr = plc.readAddr + 1,
|
// host = plc.ip,
|
// port = plc.port
|
//});
|
//if (readRes != null && readRes.errCode == 0)
|
//{
|
// CMMLog.Info($"【打包下线】读取通道{plc.readAddr + 1}的值为{readRes.result[0]}");
|
// if (readRes.result[0] == 3)
|
// {
|
var write = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
data = 3,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Info($"【打包下线】写入通道{plc.writeAddr + 1}的值为{3}");
|
// }
|
//}
|
//else CMMLog.Info($"【打包下线】读取通道{plc.readAddr + 1}的值失败");
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info(ex.Message);
|
}
|
}
|
else CMMLog.Info($"ip为{ip}的设备未配置");
|
CMMLog.Info($"【打包下线】起点安全请求退出流程处理结束-------------");
|
}
|
#endregion
|
|
#region 电梯安全门对接
|
/// <summary>
|
/// 入库一段任务请求进入
|
/// </summary>
|
/// <param name="mst"></param>
|
/// <param name="startfloor"></param>
|
internal static void RuKuOne1013(TN_I_TASK_MST mst, int startfloor)
|
{
|
//对电梯的modbus通道进行安全开门对接,
|
//var pmInfo = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.deviceType == "8").FirstOrDefault();
|
var pmInfo = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.location == mst.Ext3).FirstOrDefault();
|
if (pmInfo != null)
|
{
|
try
|
{
|
//读取输入寄存器还是输出寄存器待定,读取通道0的数据
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr + 5,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
var result2 = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr + 6,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (result != null && result2 != null)
|
{
|
CMMLog.Info($"startFloor:{startfloor}");
|
if (result.result[0] == 1 && result2.result[0] == startfloor)
|
{
|
var eleBit = MongoDBSingleton.Instance.FindOne<ElevatorTask>(Query.EQ("taskNo",mst.CN_S_SOURCE_NO), "ElevatorTask");
|
//改终点为开启的电梯
|
TSHelper.GoToAGV(mst.CN_S_TASK_NO, 2, StockInstance.Instance.GetAGVCodeForBitCode(eleBit.endBit));
|
//AMSHelper.TaskTrackLogMessage(action.CN_S_TASK_NO, action.CN_N_ORDER.ToString(), action.CN_N_ACTION_CODE.ToString(), "修改终点");
|
//TSHelper.GoToAGV(mst.CN_S_TASK_NO, 10, 3);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
else CMMLog.Info($"请检查电梯配置中心有没有开启,当前电梯点位:{mst.Ext3}");
|
}
|
|
/// <summary>
|
/// 入库一段任务请求退出
|
/// </summary>
|
/// <param name="mst"></param>
|
/// <param name="startfloor"></param>
|
internal static bool RuKuOne6(TN_I_TASK_MST mst, int startfloor)
|
{
|
bool req = false;
|
//Console.WriteLine($"ext3:{mst.Ext3}");
|
//对电梯的modbus通道进行安全开门对接,
|
var pmInfo = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.location == mst.Ext3).FirstOrDefault();
|
if (pmInfo != null)
|
{
|
try
|
{
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = pmInfo.writeAddr,
|
data = 1,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
req = true;
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
else CMMLog.Info($"请检查电梯配置中心有没有开启,当前电梯点位:{mst.Ext3}");
|
return req;
|
}
|
|
/// <summary>
|
/// 入库二段任务请求进入
|
/// </summary>
|
/// <param name="mst"></param>
|
/// <param name="startfloor"></param>
|
internal static void RuKuOne1012(TN_I_TASK_MST mst, int endfloor)
|
{
|
//对电梯的modbus通道进行安全开门对接,
|
var eleBit = MongoDBSingleton.Instance.FindOne<ElevatorTask>(Query.EQ("taskNo", mst.CN_S_SOURCE_NO), "ElevatorTask");
|
if(eleBit == null) CMMLog.Info($"当前任务来源号:{mst.CN_S_SOURCE_NO},请在ElevatorTask表中查询字段taskNo为当前任务来源号");
|
var pmInfo = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.location == eleBit.endBit02).FirstOrDefault();
|
CMMLog.Info($"二段任务 1312 1 bit:{eleBit.endBit02} deivicetype:{pmInfo.deviceType}");
|
if (pmInfo != null)
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr + 5,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
var result2 = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = pmInfo.readAddr + 6,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (result != null && result2 != null)
|
{
|
if (result.result[0] == 1 && result2.result[0] == endfloor)
|
{
|
//TSHelper.GoToAGV(mst.CN_S_TASK_NO, 10, 1);
|
//改终点为开启的电梯
|
TSHelper.GoToAGV(mst.CN_S_TASK_NO, 1, StockInstance.Instance.GetAGVCodeForBitCode(eleBit.endBit02));
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
else CMMLog.Info($"请检查电梯配置中心有没有开启,当前电梯点位:{eleBit.endBit02}");
|
}
|
|
/// <summary>
|
/// 入库二段任务请求退出
|
/// </summary>
|
/// <param name="mst"></param>
|
/// <param name="startfloor"></param>
|
internal static bool RuKuOne4(TN_I_TASK_MST mst, int endfloor)
|
{
|
bool req = false;
|
var eleBit = MongoDBSingleton.Instance.FindOne<ElevatorTask>(Query.EQ("taskNo", mst.CN_S_SOURCE_NO), "ElevatorTask");
|
if (eleBit == null) CMMLog.Info($"当前任务来源号:{mst.CN_S_SOURCE_NO},请在ElevatorTask表中查询字段taskNo为当前任务来源号");
|
var pmInfo = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.location == eleBit.endBit02).FirstOrDefault();
|
CMMLog.Info($"二段任务 1312 2 bit:{eleBit.endBit02} deivicetype:{pmInfo.deviceType}");
|
if (pmInfo != null)
|
{
|
try
|
{
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = pmInfo.writeAddr+1,
|
data = 3,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
req = true;
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Error(ex.Message, ex);
|
}
|
}
|
else CMMLog.Info($"请检查电梯配置中心有没有开启,当前电梯点位:{eleBit.endBit02}");
|
return req;
|
}
|
#endregion
|
|
#endregion
|
|
#region 电梯选择以及电梯点位赋值
|
|
/// <summary>
|
/// 读取MODBUS返回允许使用的电梯点位,如果没有电梯可以使用,返回0
|
/// </summary>
|
/// <returns></returns>
|
internal static string ElevatorTaskBit(string bit)
|
{
|
//Console.WriteLine("进入电梯选择判断!");
|
CMMLog.Info("进入电梯选择判断!");
|
string location = "";
|
string PlcBit04 = Settings.GetPlcInfo().Where(a => a.deviceType == "4").FirstOrDefault().location;
|
if (bit == PlcBit04)
|
{
|
CMMLog.Info("满托入库流程,判断三楼两部电梯设备");
|
//满托入库流程,判断三楼两部电梯设备
|
var plc = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.deviceType == "8").FirstOrDefault();
|
var plc2 = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.deviceType == "11").FirstOrDefault();
|
if (plc != null || plc2 != null)
|
{
|
if (plc != null)
|
{
|
CMMLog.Info("进入3楼电梯1判断是否开启");
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = plc.readAddr + 7,
|
dataNum = 2,//数据个数要增加 addr以及dataNum的具体数据为16个
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result != null && result.result.Length == 2)
|
{
|
if (result.result[0] == 1 && result.result[1] == 1) location = plc.location;
|
}
|
}
|
if(plc2 != null)
|
{
|
CMMLog.Info("进入三楼电梯2判断是否开启");
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 2,
|
addr = plc2.readAddr + 7,
|
host = plc2.ip,
|
port = plc2.port
|
});
|
if (result != null && result.result.Length == 2)
|
{
|
if (result.result[0] == 1 && result.result[1] == 1) location = plc2.location;
|
}
|
}
|
if (location == "")
|
{
|
//Console.WriteLine("无电梯开启!");
|
CMMLog.Info("无电梯开启!");
|
location = "0";
|
}
|
}
|
else
|
{
|
CMMLog.Info("检查配置文件里面两部电梯是否有开启!");
|
return "0";
|
}
|
}
|
//Console.WriteLine("电梯选择判断结束!");
|
CMMLog.Info("电梯选择判断结束!");
|
return location;
|
}
|
/// <summary>
|
/// 获取电梯点位赋值
|
/// </summary>
|
/// <param name="eleBit"></param>
|
/// <returns></returns>
|
internal static string ElevatorTaskBit02(string eleBit)
|
{
|
CMMLog.Info("赋值阶段2任务电梯起点");
|
string bit = "";
|
if (eleBit != "")
|
{
|
CMMLog.Info("两部电梯,四个配置均需要开启");
|
//1号电梯三楼和一楼电梯点位
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == "8").FirstOrDefault();
|
var plc2 = Settings.GetPlcInfo().Where(a => a.deviceType == "12").FirstOrDefault();
|
//2号电梯三楼和一楼电梯点位
|
var plc3 = Settings.GetPlcInfo().Where(a => a.deviceType == "11").FirstOrDefault();
|
var plc4 = Settings.GetPlcInfo().Where(a => a.deviceType == "13").FirstOrDefault();
|
if (eleBit == plc.location) bit = plc2.location;
|
else if(eleBit == plc2.location) bit = plc.location;
|
else if(eleBit == plc3.location) bit = plc4.location;
|
else if(eleBit == plc4.location) bit = plc3.location;
|
}
|
else CMMLog.Info("EleBit is null!");
|
CMMLog.Info("获取电梯二段任务电梯点位:"+bit);
|
return bit;
|
}
|
internal static void ElevatorTaskFloor(int startFloor,string bit)
|
{
|
var pmInfo = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.location == bit).FirstOrDefault();
|
var write = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = pmInfo.writeAddr+2,
|
data = 1,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
var write0 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = pmInfo.writeAddr,
|
data = startFloor,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
}
|
#endregion
|
|
#endregion
|
|
public static DateTime TenMin = DateTime.MinValue;
|
/// <summary>
|
/// 每隔十分钟往所有开启的打包下线口MODBUS通道里面写小车电量
|
/// 其实地址26,连续往里面写入四个值
|
/// </summary>
|
internal static void WriteBattery()
|
{
|
CMMLog.Info("写入小车电量:进入写入电量信息流程!");
|
////Console.WriteLine("写入小车电量:进入写入电量信息流程!");
|
if(TenMin == DateTime.MinValue) TenMin = DateTime.Now;
|
else if (DateTime.Now.Subtract(TenMin).TotalMinutes >= 10)
|
{
|
//Console.WriteLine("写入小车电量:写入所有开启的打包下线口MODBUS通道电量值,并重置时间为当前时间");
|
CMMLog.Info("写入小车电量:写入所有开启的打包下线口MODBUS通道电量值,并重置时间为当前时间");
|
//写入所有开启的打包下线口MODBUS通道电量值,并重置时间为当前时间
|
//获取所有电量值
|
int[] num = ProcessHelper.GetBatteryHang();
|
CMMLog.Info($"写入小车电量:写入数据:{JsonConvert.SerializeObject(num)}");
|
//Console.WriteLine($"写入小车电量:写入数据:{JsonConvert.SerializeObject(num)}");
|
var PlcInfo04 = Settings.GetPlcInfo().Where(a => a.enable == 1 && a.deviceType == "4").FirstOrDefault();//plcInfo
|
if (PlcInfo04 != null)
|
{
|
var wirteall = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = PlcInfo04.writeAddr + 5,
|
host = PlcInfo04.ip,
|
data = num,
|
port = PlcInfo04.port
|
});
|
}
|
TenMin = DateTime.Now;
|
}
|
}
|
#region 数据处理业务
|
|
/// <summary>
|
/// 获取设备的包装物料信息(并写入中间表)
|
/// </summary>
|
/// <param name="info"></param>
|
/// <param name="result"></param>
|
/// <param name="noPack">true : MES交互方式 false : 无MES交互方式</param>
|
private static void GetMachineData(Settings.PlcInfo pmInfo, ref string loc, int[] result ,bool noPack = true,string isOne = "")
|
{
|
//Console.WriteLine($"进入数据处理流程!");
|
CMMLog.Info($"进入数据处理流程!");
|
|
string empCode = RemoveNull(GetTrayCode(result.Take(5).ToArray()));//员工编码
|
string trayCode = RemoveNull(GetTrayCode(result.Skip(5).Take(3).ToArray()));//托盘码
|
string location = RemoveNull(GetTrayCode(result.Skip(8).Take(1).ToArray()));//设备货位编码
|
loc = location;
|
#region 2024-12-30 变更 加入mes生产订单编号 分录ID 变更注释
|
string orderCode = ""; //生产订单编号
|
int fEntryID = 0; //分录ID
|
var OrderCode = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
addr = pmInfo.readAddr + 260,
|
dataNum = 17,
|
host = pmInfo.ip,
|
port = pmInfo.port
|
});
|
if (OrderCode.result != null && OrderCode.errCode == 0)
|
{
|
orderCode = RemoveNull(GetTrayCode(OrderCode.result.Take(15).ToArray()));
|
//fEntryID = Convert.ToInt32(Completion(OrderCode.result[15]), 2);
|
fEntryID = Convert.ToInt32(Completion(OrderCode.result[15]) + Completion(OrderCode.result[16]), 2);
|
}
|
#endregion
|
if (trayCode != null && location != null)
|
{
|
CMMLog.Info($"empCode:{empCode},trayCode:{trayCode},location:{location}");
|
var json = "";
|
if (!noPack)
|
{
|
CMMLog.Info($"数据处理流程:包装机无MES情况下,自动生成以当前包装机号{location}为首的数据");
|
var task = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", location), "MachineInfo");
|
if(task == null)
|
{
|
if (MongoDBSingleton.Instance.Insert<MachineInfo>(new MachineInfo
|
{
|
machineNo = location,
|
isOne = isOne,
|
})) CMMLog.Info($"MachineInfo中插入数据,包装机号:{location}");
|
|
}
|
else CMMLog.Info($"数据处理流程:包装机无MES情况下,模拟MES数据,中间表<MachineInfo>中已有当前包装机号{location}为首的数据");
|
|
var taskTwo = MongoDBSingleton.Instance.FindOne<MachineInfoTwo>(Query.EQ("trayCode", trayCode), "MachineInfoTwo");
|
if(taskTwo != null)
|
{
|
MongoDBSingleton.Instance.Update<MachineInfoTwo>(Query.EQ("trayCode", trayCode), Update.Set("machineNo", location).Set("isOne", isOne), UpdateFlags.None);
|
CMMLog.Info($"MachineInfoTwo中更新入数据,托盘号:{trayCode}");
|
}
|
else
|
{
|
if (MongoDBSingleton.Instance.Insert<MachineInfoTwo>(new MachineInfoTwo
|
{
|
machineNo = location,
|
trayCode = trayCode,
|
isOne = isOne
|
})) CMMLog.Info($"MachineInfoTwo中插入数据,包装机号:{location}");
|
}
|
|
}
|
try
|
{
|
var info = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", location), "MachineInfo");
|
|
if (info != null)
|
{
|
CMMLog.Info($"info:{JsonConvert.SerializeObject(info)}");
|
#region 获取设备通道信息
|
|
#region 转换后
|
info.location = location;
|
info.trayCode = trayCode;
|
info.empCode = empCode;
|
//变更注释
|
info.orderCode = orderCode;
|
info.FEntryID = fEntryID;
|
//获取重量 叠包等其它信息
|
info.productWeight = Convert.ToInt32(Completion(result[9]) + Completion(result[10]), 2).ToString();
|
//info.trayCodeWeight = Convert.ToInt32(Completion(result[6]) + Completion(result[7]), 2).ToString();
|
info.oneTrayWeight1 = Convert.ToInt32(Completion(result[13]) + Completion(result[14]), 2).ToString();
|
//double x = (double)Convert.ToInt32(Completion(result[15]) + Completion(result[16]), 2) / 100;
|
info.oneTrayWeight = Convert.ToInt32(Completion(result[15]) + Completion(result[16]), 2).ToString();
|
info.trayType = Convert.ToInt32(Completion(result[18]), 2).ToString();
|
info.addState = Convert.ToInt32(Completion(result[19]), 2);
|
if (info.addState == 0) CMMLog.Error($"获取MODBUS信息异常:是否叠包值为0."); //是否叠包
|
info.packageCode = Convert.ToInt32(Completion(result[20]), 2).ToString(); //袋号
|
info.productTime = Convert.ToInt32(Completion(result[21]) + Completion(result[22]), 2).ToString();
|
|
|
//info.addWeight = Convert.ToInt32(Completion(result[10]) + Completion(result[11]), 2).ToString();
|
//info.packNg = 1;//不需要此参数 result[12]
|
//info.secondNg = Convert.ToInt32(Completion(result[13]), 2);
|
|
//CMMLog.Debug($"获取MODBUS转换后的数据信息:location:{info.location},trayCode:{info.trayCode},empCode:{info.empCode},productWeight:{info.productWeight}" +
|
// $",oneTrayWeight1:{info.oneTrayWeight1},oneTrayWeight:{info.oneTrayWeight}" +
|
// $",trayType:{info.trayType},addState:{info.addState},packageCode:{info.packageCode},productTime:{info.productTime}");
|
|
//变更注释
|
CMMLog.Debug($"获取MODBUS转换后的数据信息:location:{info.location},trayCode:{info.trayCode},empCode:{info.empCode},productWeight:{info.productWeight}" +
|
$",oneTrayWeight1:{info.oneTrayWeight1},oneTrayWeight:{info.oneTrayWeight}" +
|
$",trayType:{info.trayType},addState:{info.addState},packageCode:{info.packageCode},productTime:{info.productTime}" +
|
$",orderCode:{info.orderCode},fEntryID:{info.FEntryID}");
|
|
|
//Console.WriteLine($"获取MODBUS转换后的数据信息:location:{info.location},trayCode:{info.trayCode},productWeight:{info.productWeight}" +
|
// $",trayCodeWeight:{info.trayCodeWeight},oneTrayWeight:{info.oneTrayWeight},addWeight:{info.addWeight}" +
|
// $",packNg:{info.packNg},secondNg:{info.secondNg},addState:{info.addState},packageCode:{info.packageCode}");
|
#endregion
|
//Console.WriteLine();
|
|
#region 转换前
|
for (int i = 0; i <= 22; i++)
|
{
|
info.machinedown[i] = result[i];
|
}
|
|
|
CMMLog.Debug($"orderCode length:{OrderCode.result.Length},{JsonConvert.SerializeObject(OrderCode.result)}");
|
//变更注释
|
for (int i = 23; i <= 39; i++)
|
{
|
info.machinedown[i] = OrderCode.result[i - 23];
|
}
|
|
//将数组数据接受转换为JSON数据并在后续方法判断中存入中间表
|
json = JsonConvert.SerializeObject(info.machinedown);
|
CMMLog.Debug($"获取MODBUS转换前的数据信息:{json}");
|
//Console.WriteLine($"获取MODBUS转换前的数据信息:{json}");
|
#endregion
|
|
#endregion
|
}
|
else CMMLog.Info($"请查询<MachineInfo>表中machineNo字段是否为当前包装机号,并且trayCode是否为0");
|
|
var infoPack = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.And(Query.EQ("machineNo", location), Query.EQ("trayCode", "0")), "MachineInfo");
|
|
if (infoPack != null)
|
{
|
//包装机下线至复称,读取包装机平台数据
|
CMMLog.Info("进入info判断01");
|
//AMS包装机下线首先调用MES,之后获取新的设备数据存入中间表
|
//根据托盘号获取指定的通道的JSON数据,将其转换为数组类型——写入通道数据时会使用
|
//var arr = JsonConvert.DeserializeObject<List<int>>(json);
|
if (!noPack)
|
{
|
CMMLog.Info($"数据处理流程:包装机无MES情况下,获取以往MES传输的数据,并原样写入原先MES字段中。");
|
|
//info.lotNo = RemoveNull(GetTrayCode(result.Skip(20).Take(20).ToArray()).Trim().ToString());
|
info.lotNo = RemoveNull(GetTrayCode(result.Skip(25).Take(20).ToArray()).Trim().ToString());
|
//info.productType = RemoveNull(GetTrayCode(result.Skip(40).Take(10).ToArray()).Trim().ToString());
|
info.productType = RemoveNull(GetTrayCode(result.Skip(45).Take(10).ToArray()).Trim().ToString());
|
info.materialCode = RemoveNull(GetTrayCode(result.Skip(55).Take(20).ToArray()).Trim().ToString());
|
info.materialName = RemoveNull(GetTrayCode(result.Skip(75).Take(15).ToArray()).Trim().ToString());
|
info.measurementUnit = RemoveNull(GetTrayCode(result.Skip(90).Take(5).ToArray()).Trim().ToString());
|
|
CMMLog.Info($"数据处理流程:包装机无MES情况下,获取以往MES传输的数据,新获得数据,lotNo:{info.lotNo},productType:{info.productType},materialCode:{info.materialCode},materialName:{info.materialName},measurementUnit:{info.measurementUnit}");
|
|
//注意:这里赋值中间表参数请对照信息交互表具体通道值对应
|
UpdateBuilder update = Update.Set("palletLayers", info.secondNg.ToString()).Set("overlappingLayers", info.addState.ToString()).Set("bagNo", info.packageCode).
|
Set("lotNo", info.lotNo).Set("productType", info.productType).Set("materialCode", info.materialCode).Set("materialName", info.materialName).Set("measurementUnit", info.measurementUnit);
|
MongoDBSingleton.Instance.Update<MachineInfo>(Query.EQ("machineNo", location), update, UpdateFlags.None);
|
MongoDBSingleton.Instance.Update<MachineInfoTwo>(Query.EQ("trayCode", trayCode), update, UpdateFlags.None);
|
|
}
|
//在中间表中找到刚刚插入的MES数据(目前还没有读取并写入设备数据)
|
//var query1 = Query.And(Query.EQ("machineNo", location), Query.EQ("trayCode", "0"));
|
//UpdateBuilder updateBuider = Update.Set("location", info.location).Set("empCode", info.empCode).
|
// Set("trayCode", info.trayCode).Set("productWeight", info.productWeight).
|
// Set("oneTrayWeight1", info.oneTrayWeight1).Set("oneTrayWeight", info.oneTrayWeight).
|
// Set("trayType", info.trayType).Set("addState", info.addState).Set("packageCode", info.packageCode).Set("productTime", info.productTime).
|
// Set("jsonData", json).Set("modify", DateTime.Now);
|
//变更注释
|
var query1 = Query.And(Query.EQ("machineNo", location), Query.EQ("trayCode", "0"));
|
UpdateBuilder updateBuider = Update.Set("location", info.location).Set("empCode", info.empCode).
|
Set("trayCode", info.trayCode).Set("productWeight", info.productWeight).
|
Set("oneTrayWeight1", info.oneTrayWeight1).Set("oneTrayWeight", info.oneTrayWeight).
|
Set("trayType", info.trayType).Set("addState", info.addState).Set("packageCode", info.packageCode).Set("productTime", info.productTime).
|
Set("jsonData", json).Set("modify", DateTime.Now).Set("orderCode", info.orderCode).Set("FEntryID", info.FEntryID);
|
MongoDBSingleton.Instance.Update<MachineInfo>(query1, updateBuider, UpdateFlags.None);
|
MongoDBSingleton.Instance.Update<MachineInfoTwo>(Query.EQ("trayCode", trayCode), updateBuider, UpdateFlags.None);
|
CMMLog.Info($"MachineInfo:更新MachineInfo中间表刚刚插入的MES数据!设备号为:{location},托盘号为:{trayCode}");
|
CMMLog.Info($"MachineInfo:更新MachineInfoTwo中间表刚刚插入的MES数据!设备号为:{location},托盘号为:{trayCode}");
|
}
|
else
|
{
|
//复称入缓存架,读取复称平台数据
|
CMMLog.Info("进入info判断02");
|
//读取除包装机外其他设备的信息,更新包装机下线时的数据
|
var query2 = Query.And(Query.EQ("machineNo", location), Query.EQ("trayCode", trayCode));
|
var info2 = MongoDBSingleton.Instance.FindOne<MachineInfo>(query2, "MachineInfo");
|
if (info2 != null)
|
{
|
//UpdateBuilder updateBuider = Update.Set("location", info.location).Set("empCode", info.empCode).
|
// Set("trayCode", info.trayCode).Set("productWeight", info.productWeight).
|
// Set("oneTrayWeight1", info.oneTrayWeight1).Set("oneTrayWeight", info.oneTrayWeight).
|
// Set("trayType", info.trayType).Set("addState", info.addState).Set("packageCode", info.packageCode).Set("productTime", info.productTime).
|
// Set("jsonData", json).Set("modify", DateTime.Now);
|
//变更注释
|
UpdateBuilder updateBuider = Update.Set("location", info.location).Set("empCode", info.empCode).
|
Set("trayCode", info.trayCode).Set("productWeight", info.productWeight).
|
Set("oneTrayWeight1", info.oneTrayWeight1).Set("oneTrayWeight", info.oneTrayWeight).
|
Set("trayType", info.trayType).Set("addState", info.addState).Set("packageCode", info.packageCode).Set("productTime", info.productTime).
|
Set("jsonData", json).Set("modify", DateTime.Now).Set("orderCode", info.orderCode).Set("FEntryID", info.FEntryID);
|
MongoDBSingleton.Instance.Update<MachineInfo>(query2, updateBuider, UpdateFlags.None);
|
MongoDBSingleton.Instance.Update<MachineInfoTwo>(Query.EQ("trayCode", trayCode), updateBuider, UpdateFlags.None);
|
CMMLog.Info($"MachineInfo:更新MachineInfo中间表其他设备的数据!设备号为:{location},托盘号为:{trayCode}");
|
}
|
else CMMLog.Info($"MachineInfo:无法在MachineInfo中间表中找到当前设备编号的数据!当前设备编号为:{location},托盘码为:{trayCode}");
|
}
|
}
|
catch(Exception ex)
|
{
|
CMMLog.Info("包装机数据处理异常:"+ex.Message);
|
MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", location), RemoveFlags.None);
|
}
|
}
|
else
|
{
|
//Console.WriteLine("数据流程处理托盘号或包装机号为空值!");
|
CMMLog.Info("数据流程处理托盘号或包装机号为空值!");
|
}
|
//Console.WriteLine($"数据处理流程结束!");
|
CMMLog.Info($"数据处理流程结束!");
|
}
|
|
/// <summary>
|
/// 获取复称点状态信息
|
/// </summary>
|
/// <returns></returns>
|
public static SecondWeighState GetSecondWeighState(string location,string devicetype)
|
{
|
//传入当前设备编号,并将传入的设备编号放入复称中间表的来源变量中
|
string PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == devicetype).FirstOrDefault().location;
|
var query = Query.EQ("location", PlcBit02);
|
var model = MongoDBSingleton.Instance.FindOne<SecondWeighState>(query, "SecondWeighState");
|
if (model == null)
|
{
|
MongoDBSingleton.Instance.Insert<SecondWeighState>(new SecondWeighState { location = PlcBit02, from = location,full = 0,ng = 1 });
|
CMMLog.Debug($"判断复称状态信息服务,复称中间表数据为空,开始插入默认值!");
|
}
|
else MongoDBSingleton.Instance.Update<SecondWeighState>(query, Update.Set("from", location), "SecondWeighState", UpdateFlags.None);
|
return model;
|
}
|
|
/// <summary>
|
/// 复称平台数据
|
/// </summary>
|
public class SecondWeighState
|
{
|
public ObjectId _id { get; set; }
|
public string location { get; set; }
|
/// <summary>
|
/// 0未知 1合格 2不合格
|
/// </summary>
|
public int ng { get; set; }
|
/// <summary>
|
/// 复称平台货从哪里来的
|
/// </summary>
|
public string from { get; set; }
|
/// <summary>
|
/// 批次号
|
/// </summary>
|
public string batchNo { get; set; }
|
/// <summary>
|
/// 包装机下线重量
|
/// </summary>
|
public int weight { get; set; }
|
/// <summary>
|
/// 1 满 0 空
|
/// </summary>
|
public int full { get; set; }
|
public string mesInfo { get; set; }
|
}
|
|
/// <summary>
|
/// 获取复称点位位置
|
/// </summary>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public static string GetSecondWeighBit()
|
{
|
//改成读settings
|
var plc = Settings.GetPlcInfo().Where(a => a.deviceType == "2").FirstOrDefault();
|
return plc.location;
|
}
|
|
/// <summary>
|
/// 将设备通道里面读取的16位short转成ascii字符串
|
/// </summary>
|
/// <param name="data"></param>
|
/// <returns></returns>
|
private static string GetTrayCode(int[] data)
|
{
|
StringBuilder sb = new StringBuilder();
|
data.ToList().ForEach(a => {
|
var bytes = BitConverter.GetBytes((short)a).Reverse().ToArray();
|
sb.Append(Encoding.ASCII.GetString(bytes));
|
});
|
return sb.ToString();
|
}
|
|
/// <summary>
|
/// 十进制转换为2进制(自动补全16位)
|
/// </summary>
|
/// <param name="data"></param>
|
/// <returns></returns>
|
public static string Completion(int data)
|
{
|
var result = Convert.ToString(data, 2).PadLeft(16, '0');
|
return result;
|
}
|
|
/// <summary>
|
/// ascii转10进制(通过16进制中转)
|
/// </summary>
|
/// <param name="data"></param>
|
/// <returns></returns>
|
public static string AsciiToTen(string data)
|
{
|
byte[] oneSixbad = System.Text.ASCIIEncoding.Default.GetBytes(data);
|
StringBuilder oneSixsb = new StringBuilder();
|
foreach (byte b in oneSixbad)
|
{
|
oneSixsb.Append(b.ToString("x"));
|
}
|
int oneSixA2 = Convert.ToInt32(oneSixsb.ToString(), 16);
|
return oneSixA2.ToString();
|
}
|
|
#region 叠盘机批量写入数据
|
|
#region 产品型号分离处理方法
|
//public static int[] DiePan(WMSInfo machine)
|
//{
|
// //偏移量 +11 通道范围: 40311 ~ 40370
|
// CMMLog.Info($"进入DiePan数据处理方法");
|
// //10~19通道
|
// int[] num = new int[60];
|
// int[] num3 = new int[40];
|
// int a = 0;//托盘码处理
|
// for (int b = 0; b <= 2; b++)
|
// {
|
// num[b] = int.Parse(AsciiToTen(machine.trayCode.Substring(a, 2)));
|
// a = a + 2;
|
// }
|
// num[3] = int.Parse(AsciiToTen(machine.location));//包装机号
|
// for (int b = 4; b <= 5; b++)
|
// {
|
// int k = b % 2 == 0 ? 0 : 16;
|
// num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.productWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
// }
|
// for (int b = 6; b <= 7; b++)
|
// {
|
// int k = b % 2 == 0 ? 0 : 16;
|
// num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.trayCodeWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
// }
|
// for (int b = 8; b <= 9; b++)
|
// {
|
// int k = b % 2 == 0 ? 0 : 16;
|
// num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
// }
|
// for (int b = 10; b <= 12; b++) num[b] = 0;// 叠包后实际重量 && 复称结果 默认:0
|
// num[13] = string.IsNullOrEmpty(machine.palletLayers) ? 0 : int.Parse(machine.palletLayers);//是否需要叠托盘
|
// num[14] = machine.addState;//是否需要叠包
|
// num[15] = int.Parse(machine.packageCode);//袋号
|
// //时间戳处理
|
// string timeStamp = ProcessHelper.GetTimeStamp(32, 1, 1);
|
// for (int b = 16; b <= 17; b++)
|
// {
|
// int k = b % 2 == 0 ? 0 : 16;
|
// num[b] = Convert.ToInt32(Convert.ToString(int.Parse(timeStamp), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
// }
|
// for (int b = 18; b <= 19; b++) num[b] = 0;//预留的两个通道 默认:0
|
|
// //19 = 30 31 ~ 60
|
// //30~59通道 60~70通道
|
// string pcHead = "";
|
// string cpHead = "";
|
// #region 31~60
|
|
// string data = machine.itemPCode;
|
// CMMLog.Info($"31~60data1_1:{data}");
|
// if (data.Length % 2 != 0)
|
// {
|
// data = "0" + machine.itemPCode;
|
// pcHead = "" + machine.itemPCode.Substring(0, 1);
|
// }
|
// CMMLog.Info($"31~60data1_2:{data}");
|
// int x = data.Length / 2;
|
// int aa = 0;
|
// for (int i = 0; i <= x - 1; i++)
|
// {
|
// num3[i] = int.Parse(AsciiToTen(data.Substring(aa, 2)));
|
// aa = aa + 2;
|
// }
|
// for (int m = x; m <= 29; m++) num3[m] = 0;//将产品批次号无数据的通道全部置为 0
|
// CMMLog.Info($"itemPCode:" + JsonConvert.SerializeObject(num3));
|
// #endregion
|
|
// #region 61~70
|
|
// string data2 = machine.itemCode;
|
// CMMLog.Info($"61~70data2_1:{data2}");
|
// if (data2.Length % 2 != 0)
|
// {
|
// data2 = "0" + machine.itemCode;
|
// cpHead = "" + machine.itemCode.Substring(0, 1);
|
// }
|
// CMMLog.Info($"61~70data2_2:{data2}");
|
// int y = data2.Length / 2;
|
// CMMLog.Info($"{y}");
|
// int aaa = 0;
|
// //4 2 32 9 41
|
// for (int i = 30; i <= y + 29; i++)
|
// {
|
// num3[i] = int.Parse(AsciiToTen(data2.Substring(aaa, 2)));
|
// CMMLog.Info(JsonConvert.SerializeObject(num3[i]));
|
// aaa = aaa + 2;
|
// }
|
// int mm = y + 30;
|
// CMMLog.Info($"mm:{mm}");
|
// for (int mmm = mm; mmm <= 39; mmm++)
|
// {
|
// num3[mmm] = 0;
|
// CMMLog.Info(JsonConvert.SerializeObject(num3[mmm]));
|
// }
|
// CMMLog.Info($"itemPCode+itemCode:{JsonConvert.SerializeObject(num3)}");
|
// #endregion
|
|
// for (int i = 20; i <= 60; i++) num[i] = num3[i - 20];
|
|
// // 如果 产品批次号 或者 产品型号 位数 为 奇数,则将提前取出的 首字符 重新转码 写入 其所对应通道区域的 首通道
|
// if (pcHead != "" || cpHead != "")
|
// {
|
// if (pcHead != "") num[20] = int.Parse(AsciiToTen(pcHead));
|
// if (cpHead != "") num[50] = int.Parse(AsciiToTen(cpHead));
|
// CMMLog.Info($"产品型号或批次号数量为奇数,特将首位取出单独处理,以下为批次号和产品型号的十进制数值{num[20]},{num[50]}");
|
// }
|
// CMMLog.Info($"DiePan数据处理方法完毕");
|
|
// return num;
|
//}
|
#endregion
|
|
public static int[] DiePan(WMSInfo machine)
|
{
|
//偏移量 +11 通道范围: 40311 ~ 40370
|
CMMLog.Info($"叠盘机数据处理.");
|
//10~19通道
|
int[] num = new int[60];//总长度:60
|
|
#region 0~19 => 11~30
|
|
int a = 0;//托盘码处理
|
for (int b = 0; b <= 2; b++)
|
{
|
num[b] = int.Parse(AsciiToTen(machine.trayCode.Substring(a, 2)));
|
a = a + 2;
|
}
|
num[3] = int.Parse(AsciiToTen(machine.location));//包装机号
|
for (int b = 4; b <= 5; b++)
|
{
|
int k = b % 2 == 0 ? 0 : 16;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.productWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 6; b <= 7; b++)
|
{
|
int k = b % 2 == 0 ? 0 : 16;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.trayCodeWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 8; b <= 9; b++)
|
{
|
int k = b % 2 == 0 ? 0 : 16;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 10; b <= 12; b++) num[b] = 0;// 叠包后实际重量 && 复称结果 默认:0
|
num[13] = string.IsNullOrEmpty(machine.palletLayers) ? 0 : int.Parse(machine.palletLayers);//是否需要叠托盘
|
num[14] = machine.addState;//是否需要叠包
|
num[15] = int.Parse(machine.packageCode);//袋号
|
//时间戳处理
|
string timeStamp = ProcessHelper.GetTimeStamp(32, 1, 1);
|
for (int b = 16; b <= 17; b++)
|
{
|
int k = b % 2 == 0 ? 0 : 16;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(timeStamp), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 18; b <= 19; b++) num[b] = 0;//预留的两个通道 默认:0
|
|
#endregion
|
|
string pcHead = "";
|
string cpHead = "";
|
|
#region 20~49 => 31~60 产品批次号
|
|
string data = machine.itemPCode;
|
CMMLog.Info($"31~60data1_1:{data}");
|
if (data.Length % 2 != 0)
|
{
|
data = "0" + machine.itemPCode;
|
pcHead = "" + machine.itemPCode.Substring(0, 1);
|
}
|
CMMLog.Info($"31~60data1_2:{data}");
|
//字符串长度 / 2 = 写入通道数量(两位一转) 列: 3L0050 写入三个通道
|
int maxLength = 19 + (data.Length / 2);// data.Length / 2 至少为 1
|
int aa = 0;
|
for (int i = 20; i <= maxLength; i++)
|
{
|
num[i] = int.Parse(AsciiToTen(data.Substring(aa, 2)));
|
aa = aa + 2;
|
}
|
for (int x = maxLength + 1; x <= 49; x++) num[x] = 0;//将产品批次号无数据的通道全部置为 0
|
#endregion
|
|
#region 50~59 => 61~70 产品型号
|
|
string data2 = machine.itemCode;
|
CMMLog.Info($"61~70data2_1:{data2}");
|
if (data2.Length % 2 != 0)
|
{
|
data2 = "0" + machine.itemCode;
|
cpHead = "" + machine.itemCode.Substring(0, 1);
|
}
|
CMMLog.Info($"61~70data2_2:{data2}");
|
maxLength = 49 + (data2.Length / 2);
|
int aaa = 0;
|
for (int i = 50; i <= maxLength; i++)
|
{
|
num[i] = int.Parse(AsciiToTen(data2.Substring(aaa, 2)));
|
aaa = aaa + 2;
|
}
|
for (int x = maxLength + 1; x <= 59; x++) num[x] = 0;//将产品型号无数据的通道全部置为0
|
#endregion
|
|
// 如果 产品批次号 或者 产品型号 位数 为 奇数,则将提前取出的 首字符 重新转码 写入 其所对应通道区域的 首通道
|
if (pcHead != "") num[20] = int.Parse(AsciiToTen(pcHead));
|
if (cpHead != "") num[50] = int.Parse(AsciiToTen(cpHead));
|
if (pcHead != "" || cpHead != "") CMMLog.Info($"产品型号或批次号数量为奇数,特将首位取出单独处理,以下为批次号和产品型号的十进制数值{num[20]},{num[50]}");
|
|
CMMLog.Info($"叠盘机数据处理完毕:{JsonConvert.SerializeObject(num)}");
|
|
return num;
|
}
|
|
internal static void PackingLineComplete(string ip)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
|
if (plc != null)
|
{
|
//写入包装机--安全门关门指令
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = ip,
|
addr = plc.writeAddr + 2,
|
data = 3,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为3.");
|
}
|
else CMMLog.Debug($"包装线空托上线,3,ip=null!");
|
}
|
|
internal static void BZBKComplete(string PlcBitCache01, string Extend = "")
|
{
|
var plcInfo = Settings.GetPlcInfo().Where(a => a.location == PlcBitCache01).FirstOrDefault();
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plcInfo.ip,
|
addr = plcInfo.writeAddr + 2,
|
data = 3,
|
port = plcInfo.port
|
});
|
CMMLog.Debug($"写入设备{plcInfo.location}通道{plcInfo.writeAddr + 2}里面数据3");
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plcInfo.readAddr + 2,
|
host = plcInfo.ip,
|
port = plcInfo.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
//3:安全门关闭,等待关闭到位后,清零本通道
|
if (result.result[0] == 3)
|
{
|
CMMLog.Debug($"读取设备{plcInfo.location}通道{plcInfo.readAddr + 2}里面数据3");
|
writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plcInfo.ip,
|
addr = plcInfo.writeAddr + 2,
|
data = 0,
|
port = plcInfo.port
|
});
|
}
|
}
|
}
|
|
internal static void writeStackingMouth6(string loca, string taskNo)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.location == loca && a.enable == 1).FirstOrDefault();
|
CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询设备信息:{JsonConvert.SerializeObject(plc)}。");
|
if (plc != null)
|
{
|
var task = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), "TN_I_TASK_MST");
|
CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询任务信息:{JsonConvert.SerializeObject(task)}。");
|
var machine = MongoDBSingleton.Instance.FindOne<WMSInfo>(Query.EQ("trayCode", task.CN_S_BATCH_NO), "WMSInfo");
|
CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询WMSInfo表信息:{JsonConvert.SerializeObject(machine)}。");
|
if (machine != null)
|
{
|
WriteCacheStackingData(plc, task, machine);
|
}
|
}
|
}
|
|
private static void WriteCacheStackingData(Settings.PlcInfo plc, TN_I_TASK_MST task, WMSInfo machine)
|
{
|
try
|
{
|
var machineTwo = MongoDBSingleton.Instance.FindOne<MachineInfoTwo>(Query.EQ("trayCode", task.CN_S_BATCH_NO), "MachineInfoTwo");
|
CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询MachineInfoTwo表信息:{JsonConvert.SerializeObject(machineTwo)}。");
|
if (machineTwo != null)
|
{
|
CMMLog.Info($"3楼缓存架入叠托:获取数据:{JsonConvert.SerializeObject(machineTwo)},IPort:{plc.ip},{plc.port}");
|
int[] num;
|
if (task.CN_S_BATCH_NO.Substring(0, 3) == "VWT")
|
{
|
//四小包
|
//num = new int[143];
|
num = DiePanThree(task.CN_S_BATCH_NO);
|
}
|
else
|
{
|
//num = new int[95];
|
num = DiePanTwo(machine, machineTwo);
|
}
|
//int[] num = DiePanTwo(machine, machineTwo);
|
int i = 0;
|
while (!writeInfo(plc, task, machineTwo, num) && i <= 3)
|
{
|
i++;
|
}
|
CMMLog.Info($"删除中间表MachineInfoTwo数据:" + JsonConvert.SerializeObject(machineTwo));
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 1,
|
host = plc.ip,
|
port = plc.port,
|
data = 2
|
});
|
CMMLog.Info($"writeStackingMouth6缓存架入叠托:2写入完成");
|
}
|
} catch (Exception ex)
|
{
|
CMMLog.Info("查询失败 :" + ex.Message);
|
}
|
|
}
|
|
private static bool writeInfo(Settings.PlcInfo plc, TN_I_TASK_MST task, MachineInfoTwo machineTwo, int[] num)
|
{
|
CMMLog.Info($"3楼缓存架入叠托:写入数据:{JsonConvert.SerializeObject(num)},IPort:{plc.ip},{plc.port}");
|
if (task.CN_S_BATCH_NO.Substring(0, 3) == "VWT")
|
{
|
int[] firstNum = new int[127];
|
|
// 将,的前127个元素复制到firstNum中
|
Array.Copy(num, firstNum, firstNum.Length);
|
|
CMMLog.Info($"3楼缓存架入叠托:写入数据1:{JsonConvert.SerializeObject(firstNum)},IPort:{plc.ip},{plc.port}");
|
// 创建一个新数组来存储剩余的数据
|
int[] secNum = new int[num.Length - firstNum.Length];
|
|
// 将num中剩余的元素复制到secNum中
|
Array.Copy(num, firstNum.Length, secNum, 0, secNum.Length);
|
|
CMMLog.Info($"3楼缓存架入叠托:写入数据2:{JsonConvert.SerializeObject(secNum)},IPort:{plc.ip},{plc.port}");
|
var wirteall01 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 5,
|
host = plc.ip,
|
port = plc.port,
|
data = firstNum
|
});
|
CMMLog.Debug($"3楼缓存架入叠托:返回数据1:{JsonConvert.SerializeObject(wirteall01)},IPort:{plc.ip},{plc.port}");
|
wirteall01 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 132,
|
host = plc.ip,
|
port = plc.port,
|
data = secNum
|
});
|
CMMLog.Debug($"3楼缓存架入叠托:返回数据2:{JsonConvert.SerializeObject(wirteall01)},IPort:{plc.ip},{plc.port}");
|
|
#region 写入分录ID 和订单编号
|
|
var FADInfo = MongoDBSingleton.Instance.Find<MachineInfoTwo>(Query.EQ("trayCode", task.CN_S_BATCH_NO), "MachineInfoTwo");
|
for (int i = 1; i <= FADInfo.Count; i++)
|
{
|
MachineInfoTwo fAdInfo = FADInfo[i - 1];
|
var arr = JsonConvert.DeserializeObject<List<int>>(machineTwo.jsonData);
|
int[] num2 = new int[23];
|
for (int x = 0; x < 23; i++)
|
{
|
num2[x] = arr[x + 22];
|
}
|
CMMLog.Info($"3楼缓存架入叠托:写入订单号:{JsonConvert.SerializeObject(num2)},IPort:{plc.ip},{plc.port}");
|
var wirteall02 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 150,
|
host = plc.ip,
|
port = plc.port,
|
data = num2
|
});
|
CMMLog.Info($"3楼缓存架入叠托:返回数据:{JsonConvert.SerializeObject(wirteall02)},IPort:{plc.ip},{plc.port}");
|
|
if (wirteall01.errCode == 0 && wirteall02.errCode == 0)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
#endregion
|
}
|
else
|
{
|
var wirteall01 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 5,
|
host = plc.ip,
|
port = plc.port,
|
data = num
|
});
|
CMMLog.Info($"3楼缓存架入叠托:返回数据:{JsonConvert.SerializeObject(wirteall01)},IPort:{plc.ip},{plc.port}");
|
|
#region 写入分录ID 和订单编号
|
var arr = JsonConvert.DeserializeObject<List<int>>(machineTwo.jsonData);
|
int[] num2 = new int[17];
|
for (int i = 0; i < 17; i++)
|
{
|
num2[i] = arr[i + 23];
|
}
|
CMMLog.Info($"3楼缓存架入叠托:写入订单号:{JsonConvert.SerializeObject(num2)},IPort:{plc.ip},{plc.port}");
|
var wirteall02 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 150,
|
host = plc.ip,
|
port = plc.port,
|
data = num2
|
});
|
CMMLog.Info($"3楼缓存架入叠托:返回数据:{JsonConvert.SerializeObject(wirteall02)},IPort:{plc.ip},{plc.port}");
|
#endregion
|
|
if (wirteall01.errCode == 0 && wirteall02.errCode == 0)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
return false;
|
}
|
|
private static int[] DiePanThree(string trayCode)
|
{
|
int[] num = new int[143];//总长度:143
|
CMMLog.Info($"叠盘机四小包数据处理.");
|
|
var machineTwo = MongoDBSingleton.Instance.Find<MachineInfoTwo>(Query.EQ("trayCode", trayCode), "MachineInfoTwo");
|
for(int i = 1;i <= machineTwo.Count; i++)
|
{
|
MachineInfoTwo machine = machineTwo[i - 1];
|
CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询MachineInfoTwo表信息:{JsonConvert.SerializeObject(machine)}");
|
var ErpItemInfo = new SqlHelper<object>().GetInstance(false).Queryable<T_JY_MATERIALSync>().Where(x => x.FNumber == machine.materialCode).First();
|
CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询T_JY_MATERIALSync表信息:{JsonConvert.SerializeObject(ErpItemInfo)}。");
|
if(i == 1)
|
{
|
var arr = JsonConvert.DeserializeObject<List<int>>(machine.jsonData);
|
#region 0~25 => 6~30
|
for (int x = 0; x < 5; x++)
|
{
|
num[x] = arr[x];//员工编号
|
}
|
for (int b = 5; b <= 7; b++)
|
{
|
num[b] = 0; //四小包无托盘码
|
}
|
num[8] = int.Parse(AsciiToTen(machine.location));//包装机号
|
for (int b = 9; b <= 10; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.productWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 13; b <= 14; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight1), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 15; b <= 16; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
//for (int b = 17; b <= 18; b++) num[b] = 0;// 叠包后实际重量 && 复称结果 默认:0
|
|
num[18] = 3; //物料打包类型
|
|
//num[19] = 2;//是否需要叠托盘 // string.IsNullOrEmpty(machine.palletLayers) ? 0 : int.Parse(machine.palletLayers)
|
num[19] = machine.addState; //是否需要叠包
|
num[20] = int.Parse(machine.packageCode);//袋号
|
//时间戳处理
|
for (int x = 21; x <= 22; x++)
|
{
|
num[x] = arr[x];//生产日期
|
}
|
//string timeStamp = ProcessHelper.GetTimeStamp(32, 1, 1);
|
//for (int b = 16; b <= 17; b++)
|
//{
|
// int k = b % 2 == 0 ? 0 : 16;
|
// num[b] = Convert.ToInt32(Convert.ToString(int.Parse(timeStamp), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
//}
|
//for (int b = 18; b <= 19; b++) num[b] = 0;//预留的两个通道 默认:0
|
|
#endregion
|
|
string pcHead = "";
|
string cpHead = "";
|
string mtHead = "";// 设备的真实物料编码
|
|
#region 25~44 => 31~50 产品批次号
|
|
string data = machine.lotNo;
|
CMMLog.Info($"31~50data1_1:{data}");
|
if (data.Length % 2 != 0)
|
{
|
data = "0" + machine.lotNo;
|
pcHead = "" + machine.lotNo.Substring(0, 1);
|
}
|
CMMLog.Info($"31~50data1_2:{data}");
|
//字符串长度 / 2 = 写入通道数量(两位一转) 列: 3L0050 写入三个通道
|
int maxLength = 24 + (data.Length / 2);// data.Length / 2 至少为 1
|
int aa = 0;
|
for (int j = 25; j <= maxLength; j++)
|
{
|
num[j] = int.Parse(AsciiToTen(data.Substring(aa, 2)));
|
aa = aa + 2;
|
}
|
for (int x = maxLength + 1; x <= 44; x++) num[x] = 0;//将产品批次号无数据的通道全部置为 0
|
#endregion
|
|
#region 45~54 => 51~60 产品型号
|
|
ERPService.HandleItemInfo(ErpItemInfo.FSpecification, 45, 54, num);// 45~54 => 51~60
|
|
//string data2 = machine.itemCode;
|
//CMMLog.Info($"51~50data2_1:{data2}");
|
//if (data2.Length % 2 != 0)
|
//{
|
// data2 = "0" + machine.itemCode;
|
// cpHead = "" + machine.itemCode.Substring(0, 1);
|
//}
|
//CMMLog.Info($"51~60data2_2:{data2}");
|
//maxLength = 39 + (data2.Length / 2);
|
//int aaa = 0;
|
//for (int i = 40; i <= maxLength; i++)
|
//{
|
// num[i] = int.Parse(AsciiToTen(data2.Substring(aaa, 2)));
|
// aaa = aaa + 2;
|
//}
|
//for (int x = maxLength + 1; x <= 49; x++) num[x] = 0;//将产品型号无数据的通道全部置为0
|
#endregion
|
|
#region 55~74 => 61~80 物料编码
|
|
string data3 = machine.materialCode;
|
CMMLog.Info($"61~80data3_1:{data3}");
|
if (data3.Length % 2 != 0)
|
{
|
data3 = "0" + machine.materialCode;
|
mtHead = "" + machine.materialCode.Substring(0, 1);
|
}
|
CMMLog.Info($"61~80data3_2:{data3}");
|
maxLength = 54 + (data3.Length / 2);
|
int aaaa = 0;
|
for (int j = 55; j <= maxLength; j++)
|
{
|
num[j] = int.Parse(AsciiToTen(data3.Substring(aaaa, 2)));
|
aaaa = aaaa + 2;
|
}
|
for (int x = maxLength + 1; x <= 74; x++) num[x] = 0;//将产品型号无数据的通道全部置为0
|
#endregion
|
|
ERPService.HandleItemInfoChina(ErpItemInfo.FName, 75, 89, num);// 中文处理 75~89 81~95
|
ERPService.HandleItemInfo(ErpItemInfo.FStoreUnit, 90, 94, num);// 90~94 96~100
|
|
// 如果 产品批次号 或者 产品型号 位数 为 奇数,则将提前取出的 首字符 重新转码 写入 其所对应通道区域的 首通道
|
if (pcHead != "") num[25] = int.Parse(AsciiToTen(pcHead));
|
if (cpHead != "") num[45] = int.Parse(AsciiToTen(cpHead));
|
if (mtHead != "") num[55] = int.Parse(AsciiToTen(mtHead));
|
if (pcHead != "" || cpHead != "") CMMLog.Info($"产品型号或批次号数量为奇数,特将首位取出单独处理,以下为批次号和产品型号的十进制数值{num[25]},{num[55]}");
|
|
CMMLog.Info($"叠盘机数据处理完毕:{JsonConvert.SerializeObject(num)}");
|
}
|
else
|
{
|
CMMLog.Info($"四小包流程第{i}包");
|
var arr = JsonConvert.DeserializeObject<List<int>>(machine.jsonData);
|
CMMLog.Info("arr:"+JsonConvert.SerializeObject(arr));
|
int x = 95 + 16 * (i - 2);
|
num[x] = int.Parse(machine.packageCode); // 袋号
|
for (int b = x + 1; b <= x + 2; b++)
|
{
|
int k = b % 2 == 0 ? 0 : 16;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.productWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = x + 3; b <= x + 4; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight1), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = x + 5; b <= x + 6; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = x + 7; b <= x + 8; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeightFC), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
|
//生产日期
|
num[x + 9] = arr[21];
|
num[x + 10] = arr[22];
|
//员工编号
|
num[x + 11] = arr[0];
|
num[x + 12] = arr[1];
|
num[x + 13] = arr[2];
|
num[x + 14] = arr[3];
|
num[x + 15] = arr[4];
|
CMMLog.Info($"叠盘机数据处理完毕:{JsonConvert.SerializeObject(num)}");
|
}
|
}
|
return num;
|
}
|
|
private static int[] DiePanTwo(WMSInfo machine, MachineInfoTwo machineInfoTwo)
|
{
|
//var ErpItemInfo = MongoDBSingleton.Instance.FindOne<T_JY_MATERIALSync>(Query.EQ("FNumber", machineInfoTwo.materialCode), "ERPItemTable");
|
var ErpItemInfo = new SqlHelper<object>().GetInstance(false).Queryable<T_JY_MATERIALSync>().Where(x => x.FNumber == machineInfoTwo.materialCode).First();
|
//var ErpEmpInfo = MongoDBSingleton.Instance.FindOne<T_JY_EMPINFOSync>(Query.EQ("item_code", machineInfoTwo.materialCode), "ERPItemTable");
|
CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询T_JY_MATERIALSync表信息:{JsonConvert.SerializeObject(ErpItemInfo)}。");
|
//CMMLog.Info($"3楼缓存架入叠托:收到信号6,查询T_JY_MATERIALSync表信息:{JsonConvert.SerializeObject(ErpEmpInfo)}。");
|
|
//偏移量 +11 通道范围: 40311 ~ 40390
|
CMMLog.Info($"叠盘机数据处理.");
|
//10~19通道
|
int[] num = new int[95];//总长度:95
|
var arr = JsonConvert.DeserializeObject<List<int>>(machineInfoTwo.jsonData);
|
#region 0~25 => 6~30
|
for(int x = 0; x < 5; x++)
|
{
|
num[x] = arr[x];//员工编号
|
}
|
int a = 0;//托盘码处理
|
for (int b = 5; b <= 7; b++)
|
{
|
num[b] = int.Parse(AsciiToTen(machine.trayCode.Substring(a, 2)));
|
a = a + 2;
|
}
|
num[8] = int.Parse(AsciiToTen(machine.location));//包装机号
|
for (int b = 9; b <= 10; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.productWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 13; b <= 14; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machineInfoTwo.oneTrayWeight1), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
for (int b = 15; b <= 16; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machineInfoTwo.oneTrayWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
//for (int b = 17; b <= 18; b++) num[b] = 0;// 叠包后实际重量 && 复称结果 默认:0
|
|
num[18] = int.Parse(machineInfoTwo.trayType); //物料打包类型
|
//num[19] = 2;//是否需要叠托盘 // string.IsNullOrEmpty(machine.palletLayers) ? 0 : int.Parse(machine.palletLayers)
|
num[19] = machine.addState; //是否需要叠包
|
num[20] = int.Parse(machine.packageCode);//袋号
|
//时间戳处理
|
for (int x = 21; x <= 22; x++)
|
{
|
num[x] = arr[x];//生产日期
|
}
|
for (int b = 23; b <= 24; b++)
|
{
|
int k = b % 2 == 0 ? 16 : 0;
|
num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machineInfoTwo.oneTrayWeightFC), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
|
}
|
#endregion
|
|
string pcHead = "";
|
string cpHead = "";
|
string mtHead = "";// 设备的真实物料编码
|
string mtTail = "";// 设备的真实物料编码
|
|
#region 25~44 => 31~50 产品批次号
|
|
string data = machineInfoTwo.lotNo;
|
CMMLog.Info($"31~50data1_1:{data}");
|
if (data.Length % 2 != 0)
|
{
|
data = "0" + machineInfoTwo.lotNo;
|
pcHead = "" + machineInfoTwo.lotNo.Substring(0, 1);
|
}
|
CMMLog.Info($"31~50data1_2:{data}");
|
//字符串长度 / 2 = 写入通道数量(两位一转) 列: 3L0050 写入三个通道
|
int maxLength = 24 + (data.Length / 2);// data.Length / 2 至少为 1
|
int aa = 0;
|
for (int i = 25; i <= maxLength; i++)
|
{
|
num[i] = int.Parse(AsciiToTen(data.Substring(aa, 2)));
|
aa = aa + 2;
|
}
|
for (int x = maxLength + 1; x <= 44; x++) num[x] = 0;//将产品批次号无数据的通道全部置为 0
|
#endregion
|
|
#region 45~54 => 51~60 产品型号
|
|
ERPService.HandleItemInfo(ErpItemInfo.FSpecification, 45, 54, num);// 45~54 => 51~60
|
|
//string data2 = machine.itemCode;
|
//CMMLog.Info($"51~50data2_1:{data2}");
|
//if (data2.Length % 2 != 0)
|
//{
|
// data2 = "0" + machine.itemCode;
|
// cpHead = "" + machine.itemCode.Substring(0, 1);
|
//}
|
//CMMLog.Info($"51~60data2_2:{data2}");
|
//maxLength = 39 + (data2.Length / 2);
|
//int aaa = 0;
|
//for (int i = 40; i <= maxLength; i++)
|
//{
|
// num[i] = int.Parse(AsciiToTen(data2.Substring(aaa, 2)));
|
// aaa = aaa + 2;
|
//}
|
//for (int x = maxLength + 1; x <= 49; x++) num[x] = 0;//将产品型号无数据的通道全部置为0
|
#endregion
|
|
#region 55~74 => 61~80 物料编码
|
|
string data3 = machineInfoTwo.materialCode;
|
CMMLog.Info($"61~80data3_1:{data3}");
|
if (data3.Length % 2 != 0)
|
{
|
mtTail = machineInfoTwo.materialCode.Substring(data3.Length - 1, 1) + "";
|
CMMLog.Info($"mtTail:{mtTail}");
|
data3 = machineInfoTwo.materialCode +" " ;
|
//mtHead = "" + machineInfoTwo.materialCode.Substring(0, 1);
|
//CMMLog.Info($"mtHead:{mtHead}");
|
}
|
CMMLog.Info($"61~80data3_2:{data3}");
|
maxLength = 54 + (data3.Length / 2);
|
int aaaa = 0;
|
for (int i = 55; i <= maxLength; i++)
|
{
|
num[i] = int.Parse(AsciiToTen(data3.Substring(aaaa, 2)));
|
aaaa = aaaa + 2;
|
}
|
for (int x = maxLength + 1; x <= 74; x++) num[x] = 0;//将产品型号无数据的通道全部置为0
|
#endregion
|
|
ERPService.HandleItemInfoChina(ErpItemInfo.FName, 75, 89, num);// 中文处理 75~89 81~95
|
ERPService.HandleItemInfo(ErpItemInfo.FStoreUnit, 90, 94, num);// 90~94 96~100
|
|
// 如果 产品批次号 或者 产品型号 位数 为 奇数,则将提前取出的 首字符 重新转码 写入 其所对应通道区域的 首通道
|
if (pcHead != "") num[25] = int.Parse(AsciiToTen(pcHead));
|
if (cpHead != "") num[45] = int.Parse(AsciiToTen(cpHead));
|
//if (mtHead != "") num[55] = int.Parse(AsciiToTen(mtHead));
|
//CMMLog.Info($"55:{num[55]}");
|
if (mtTail != "") num[maxLength] = tailToTen(mtTail);
|
CMMLog.Info($"{maxLength}:{num[maxLength]}");
|
if (pcHead != "" || cpHead != "") CMMLog.Info($"产品型号或批次号数量为奇数,特将首位取出单独处理,以下为批次号和产品型号的十进制数值{num[25]},{num[45]}");
|
|
CMMLog.Info($"叠盘机数据处理完毕:{JsonConvert.SerializeObject(num)}");
|
|
return num;
|
}
|
|
private static int tailToTen(string mtTail)
|
{
|
//int number = int.Parse(mtTail);
|
//string binaryString = Convert.ToString(number, 2).PadLeft(8, '0'); // 转换为二进制并补齐到8位
|
//string highBits = binaryString.Substring(0, 8); // 取高8位
|
//string lowBits = new string('0', 8); // 低8位补0
|
//string combinedBinary = highBits + lowBits; // 组合成16位二进制字符串
|
//int result = Convert.ToInt32(combinedBinary, 2); // 转换为十进制
|
char inputChar = mtTail[0]; // 获取字符串的第一个字符
|
int asciiValue = (int)inputChar; // 转换为ASCII码
|
string hexValue = asciiValue.ToString("X2"); // 转换为16进制
|
string binaryValue = Convert.ToString(asciiValue, 2).PadLeft(8, '0'); // 转换为8位二进制
|
string finalBinaryValue = binaryValue + "00000000"; // 补8个二进制0
|
int finalDecimalValue = Convert.ToInt32(finalBinaryValue, 2); // 转换为10进制
|
|
return finalDecimalValue;
|
}
|
|
internal static bool writeStackingMouth5(string loc)
|
{
|
bool result = false;
|
var plc = Settings.GetPlcInfo().Where(a => a.location == loc).FirstOrDefault();
|
if (plc != null)
|
{
|
var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
addr = plc.writeAddr + 2,
|
data = 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (wirte.errCode == 0) result = true;
|
}
|
else CMMLog.Debug($"缓存入叠盘机,5,plc=null!");
|
return result;
|
}
|
|
/// <summary>
|
/// 接驳位入立库任务 辅材流程
|
/// </summary>
|
/// <param name="locCode"></param>
|
internal static void InWarehouse(string locCode)
|
{
|
try
|
{
|
var locInfo = MongoDBSingleton.Instance.FindOne<ConnectingBits>(Query.EQ("Bit", locCode), "ConnectingBits");
|
if (locInfo != null)
|
{
|
if (locInfo.state == "1")
|
{
|
//变更注释
|
//if (string.IsNullOrEmpty(locInfo.END_LOC))
|
//{
|
CMMLog.Info("InWarehouse:" + JsonConvert.SerializeObject(locInfo));
|
string wmstaskno = "";
|
string trayCode = locInfo.timeCuo;
|
//string trayCode = "1";
|
//货位上有货物,生成从接驳位到立库的任务 调用wms入库接口
|
bool req = WMSHelper.WMSIn(locCode, "打包下线", ref wmstaskno, ref trayCode, "", "CKHJ");
|
//bool req = WMSHelper.WMSIn(locCode, "time", ref wmstaskno, ref trayCode, "");
|
if (req)
|
{
|
CMMLog.Info($"接驳位入立库流程:WMS生成任务成功!");
|
MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("Bit", locCode), Update.Set("state", "2"), "ConnectingBits", UpdateFlags.None);
|
|
var coonInfo = MongoDBSingleton.Instance.FindOne<ConnectingBits>(Query.EQ("Bit", locCode), "ConnectingBits");
|
if (coonInfo != null)
|
{
|
//根据时间戳获取任务
|
//var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(Query.EQ("timeStamp", int.Parse(trayCode)), "TimeCuoInfoCom");
|
//if(time != null)
|
//{
|
// ERPService.SendERPTaskInfoTwo(time);
|
//}
|
}
|
}
|
else CMMLog.Info($"接驳位入立库流程:WMS生成任务失败!");
|
//}
|
//else
|
//{
|
// //防止辅材回库的终点货位数据没删,导致入库任务计算成了辅材任务,这里需要二次判断
|
// if(locInfo.trayCode.Substring(0,3) == "SWT")
|
// {
|
// HHAmsExecuteResult req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), locCode, locInfo.END_LOC, "辅材转运", 0, locInfo.trayCode);
|
// }
|
// else
|
// {
|
// MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("_id", locInfo._id), Update.Set("END_LOC", ""), UpdateFlags.None);
|
// }
|
//}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info("InWarehouse" + ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 四钴接驳位入立库任务
|
/// </summary>
|
/// <param name="locCode"></param>
|
internal static void DGInWarehouse(string locCode)
|
{
|
try
|
{
|
var locInfo = MongoDBSingleton.Instance.FindOne<DGConnectingBits>(Query.EQ("Bit", locCode), "DGConnectingBits");
|
if (locInfo != null)
|
{
|
if (locInfo.state == "1")
|
{
|
CMMLog.Info("DGInWarehouse:" + JsonConvert.SerializeObject(locInfo));
|
string wmstaskno = "";
|
string trayCode = "";
|
bool req = WMSHelper.WMSIn(locCode, "电钴打包下线", ref wmstaskno, ref trayCode, "", "CKHJ");
|
if (req)
|
{
|
CMMLog.Info($"电钴接驳位入立库流程:WMS生成任务成功!");
|
MongoDBSingleton.Instance.Update<DGConnectingBits>(Query.EQ("Bit", locCode), Update.Set("state", "2"), "DGConnectingBits", UpdateFlags.None);
|
}
|
else CMMLog.Info($"电钴接驳位入立库流程:WMS生成任务失败!");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info("DGInWarehouse" + ex.Message);
|
}
|
}
|
|
internal static void outWare(string taskNo,bool flage)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.Extend == "2" && a.enable == 1).FirstOrDefault();
|
if(plc != null)
|
{
|
if (flage)
|
{
|
//电动门开门步骤:
|
//1、在通道【40101】中写入1,发送开门信号
|
//2、读取通道【40001】中的值,如果为2,表示开门到位,通知小车进去
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr,
|
data = 1
|
});
|
CMMLog.Info($"发送开门信号,在通道{plc.writeAddr}中写入1,ip:{plc.ip},端口:{plc.port}");
|
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 2,
|
addr = plc.readAddr,
|
host = plc.ip,
|
port = plc.port
|
});
|
|
if (result != null && result.errCode == 0)
|
{
|
CMMLog.Info($"电动门开门流程:读取电动门通道号为:{plc.readAddr}里面的值为{result.result[0]},{plc.readAddr + 1}里面的值为{result.result[1]}");
|
//Console.WriteLine($"电动门开门流程:读取电动门通道号为:{plc.readAddr}里面的值为{result.result[0]},{plc.readAddr + 1}里面的值为{result.result[1]}");
|
if (result.result[0] == 1 && result.result[1] == 1)
|
{
|
//推送小车进去
|
CMMLog.Info($"电动门已经打开,门号:2");
|
|
TSHelper.GoToAGV(taskNo, 10, 3);
|
}
|
}
|
else CMMLog.Info($"电动门开门流程:未读取到包装机通道{plc.readAddr}里面的数据!!!result:{JsonConvert.SerializeObject(result)}");
|
}
|
else
|
{
|
//电动门关门步骤
|
//1、小车通过电动门后,在通道【40101】中写入2
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
port = plc.port,
|
addr = plc.writeAddr,
|
data = 2
|
});
|
CMMLog.Info($"电动门关门流程,在通道{plc.writeAddr}中写入2,ip:{plc.ip},端口:{plc.port}");
|
}
|
}
|
else CMMLog.Info($"门号为【2】的门未在配置文件配置或者未启用");
|
}
|
|
/// <summary>
|
/// 缓存架入入料口
|
/// </summary>
|
/// <param name="plc"></param>
|
/// <exception cref="NotImplementedException"></exception>
|
internal static void InInlet(Settings.PlcInfo plc)
|
{
|
var locInfo = MongoDBSingleton.Instance.FindOne<location>(Query.And(Query.EQ("S_LOC_STATE", "无"), Query.EQ("N_CURRENT_NUM", 0)), "location");
|
if(locInfo != null)
|
{
|
//判断上料是否有任务
|
if (CheckEndFree(plc.location))
|
{
|
var num = plc.device == "26" ? 1 : 2;
|
|
var result1 = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result1 != null && result1.errCode == 0)
|
{
|
if (result1.result[0] == num)
|
{
|
//上料平台为空,可生成任务
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), locInfo.S_LOC_CODE, plc.location, "3楼成品出库", 0, locInfo.S_TRAY_CODE);
|
if (amsResult.success)
|
{
|
CMMLog.Debug($"缓存架出库流程:AMS调用API成功!");
|
}
|
else CMMLog.Debug($"缓存架出库流程:AMS调用API失败,开始重新调用!");
|
}
|
}
|
}
|
}
|
}
|
|
internal static void machine()
|
{
|
//MongoDBSingleton.Instance.Remove<packageInfoModel>(Query.EQ("weight2", ""), RemoveFlags.Single);
|
|
//获取当天的所有合格率
|
var proInfoList = MongoDBSingleton.Instance.Find<ProductList>(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), "ProductList").ToList();
|
if (proInfoList.Count > 0)
|
{
|
double sum = 0;
|
int flage = 0;
|
proInfoList.ForEach(a => {
|
if (!string.IsNullOrEmpty(a.machine))
|
{
|
sum = sum + a.percentOfPass;
|
}
|
else flage = 1;
|
});
|
|
sum = flage == 0 ? Math.Round((sum / proInfoList.Count), 2) : Math.Round((sum / (proInfoList.Count - 1)), 2);
|
|
//计算当天的总合格率
|
var HGL = MongoDBSingleton.Instance.FindOne<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", "")), "ProductList");
|
if (HGL != null)
|
{
|
HGL.overallPassRate = sum;
|
MongoDBSingleton.Instance.Update<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", "")), Update.Set("overallPassRate", HGL.overallPassRate), UpdateFlags.None);
|
}
|
else
|
{
|
ProductList machine = new ProductList
|
{
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
machine = "",
|
total = 0,
|
qualifiedQuantity = 0,
|
percentOfPass = 0,
|
overallPassRate = sum
|
};
|
MongoDBSingleton.Instance.Insert(machine);
|
}
|
}
|
}
|
|
internal static void deleteTableTask()
|
{
|
int dayNum = 0;
|
if (!string.IsNullOrEmpty(Settings.packageDate))
|
{
|
dayNum = int.Parse(Settings.packageDate);
|
}
|
int dayNumTwo = 0;
|
if (!string.IsNullOrEmpty(Settings.productDate))
|
{
|
dayNumTwo = int.Parse(Settings.productDate);
|
}
|
var request = MongoDBSingleton.Instance.FindAll<packageInfoModel>();
|
if (request.Count > 0)
|
{
|
request.ForEach(a =>
|
{
|
DateTime CreateTime = Convert.ToDateTime(a.time);
|
|
if (DateTime.Now.Subtract(CreateTime).TotalDays > dayNum)
|
{
|
MongoDBSingleton.Instance.Remove<packageInfoModel>(Query.EQ("_id", a._id), "packageInfoModel", RemoveFlags.None);
|
}
|
});
|
}
|
|
var requestTwo = MongoDBSingleton.Instance.FindAll<ProductList>();
|
if (requestTwo.Count > 0)
|
{
|
requestTwo.ForEach(a =>
|
{
|
DateTime CreateTime = Convert.ToDateTime(a.Date + " 00:00:00");
|
if (DateTime.Now.Subtract(CreateTime).TotalDays > dayNumTwo)
|
{
|
MongoDBSingleton.Instance.Remove<ProductList>(Query.EQ("_id", a._id), "ProductList", RemoveFlags.None);
|
}
|
});
|
}
|
}
|
|
internal static void productOutWare(string endBit, string taskNo, bool action)
|
{
|
var plc = Settings.GetPlcInfo().Where(a => a.location == endBit).FirstOrDefault();
|
if (plc != null)
|
{
|
if (action)
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr,
|
data = 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为1.");
|
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 2,
|
addr = plc.readAddr,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Debug($"查询设备{plc.location}通道{plc.readAddr}里面数据为{result.result[0]}、{result.result[1]}.");
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1 && result.result[1] == 1)
|
{
|
//推送小车进入
|
TSHelper.GoToAGV(taskNo, 10, 3);
|
}
|
}
|
}
|
else
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr,
|
data = 2,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为2.");
|
}
|
}
|
}
|
#region 写入看板信息
|
|
#region 写入小车信息
|
internal static void writeAGVInfo(string agvNo)
|
{
|
#region 写入小车状态
|
CMMLog.Info($"车辆状态处理:执行开始!,当前车号:{agvNo}");
|
try
|
{
|
//查询小车状态表,写入小车坐标和方向 并写入中间表
|
var agvState = MongoDBSingleton.Instance.FindAll<AGV_STATE>();
|
if (agvState.Count > 0)
|
{
|
agvState = int.Parse(agvNo) < 10 ? agvState.Where(a => int.Parse(a.forkliftNo) < 10).ToList() : agvState.Where(a => int.Parse(a.forkliftNo) > 10).ToList();
|
var Ware = int.Parse(agvNo) < 10 ? Settings.GetwareInfoList().Where(x => x.wareName == "车间" && x.enable == 1).FirstOrDefault() : Settings.GetwareInfoList().Where(x => x.wareName == "立库" && x.enable == 1).FirstOrDefault();
|
|
int[] num = int.Parse(agvNo) < 10 ? new int[70] : new int[35];
|
//int startNum = int.Parse(agvNo) < 10 ? (int.Parse(agvNo) - 1) * 7 : (int.Parse(agvNo) - 10) * 7;
|
|
agvState.ForEach(a =>
|
{
|
|
int startNum = int.Parse(a.forkliftNo) < 10 ? (int.Parse(a.forkliftNo) - 1) * 7 : (int.Parse(a.forkliftNo) - 10) * 7;
|
|
if (Ware != null)
|
{
|
int divisor = 65536; // 除数
|
int xPos = int.Parse(a.xPos);
|
int yPos = int.Parse(a.yPos);
|
|
int xquotient = xPos / divisor; // 计算商数
|
int xremainder = xPos % divisor; // 计算余数
|
|
int yquotient = yPos / divisor; // 计算商数
|
int yremainder = yPos % divisor; // 计算余数
|
|
|
num[startNum] = xquotient;
|
num[startNum + 1] = xremainder;
|
num[startNum + 2] = yquotient;
|
num[startNum + 3] = yremainder;
|
num[startNum + 4] = string.IsNullOrEmpty(a.Degree) ? 0 : int.Parse(a.Degree);
|
num[startNum + 5] = a.agvState;
|
num[startNum + 6] = a.haveItem;
|
}
|
else CMMLog.Info("writeAGVInfo 仓库未配置");
|
});
|
|
var wirtel = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = Ware.writeAddr,
|
host = Ware.ip,
|
port = Ware.port,
|
data = num
|
});
|
CMMLog.Info($"在通道{Ware.writeAddr}中写入{JsonConvert.SerializeObject(num)},ip:{Ware.ip},端口:{Ware.port}");
|
}
|
else CMMLog.Info("车辆状态处理:AGV_STATE 车辆状态表未获取到车辆状态数据!");
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info($"车辆状态处理-异常:{ex.Message}!");
|
}
|
#endregion
|
}
|
#endregion
|
|
internal static void writeCJQtt(Settings.wareInfo Ware)
|
{
|
var url = hao.WebUrl + "GlmSecAreaLoacNum";
|
int[] num = new int[14];
|
#region 写入空托流转数量
|
var empNum = MongoDBSingleton.Instance.FindAll<BZEmptyPoint>("BZEmptyPoint");
|
if(empNum.Count > 0)
|
{
|
for(int i = 0; i < empNum.Count; i++)
|
{
|
num[i * 2] = empNum[i].Quantity / 65536;
|
num[i * 2 + 1] = empNum[i].Quantity % 65536;
|
}
|
}
|
#endregion
|
|
#region 仓库货位数量
|
CJWareNum model = new CJWareNum
|
{
|
AreaCode = new List<string>
|
{
|
"BCPHJ",
|
"BCPHJ2",
|
"FCNG",
|
"FCK2NG",
|
"DBNG"
|
}
|
};
|
int BCPZ = 0;
|
int BCPUSE = 0;
|
int NGZ = 0;
|
int NGUSE = 0;
|
|
string msgData = JsonConvert.SerializeObject(model);
|
|
var feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim();
|
CMMLog.Info($"writeCJQtt:【调用wms获取入库货位信息】:接收数据:" + feedback);
|
if (!string.IsNullOrEmpty(feedback))
|
{
|
var wmsResponse = JsonConvert.DeserializeObject<CJInfoResModel>(feedback);
|
if(wmsResponse.Success == true)
|
{
|
wmsResponse.Data.ForEach(a =>
|
{
|
if (a.AreaCode.Contains("NG"))
|
{
|
NGZ = NGZ + a.ZHwNum;
|
NGUSE = NGUSE + a.NumM;
|
}
|
else
|
{
|
BCPZ = BCPZ + a.ZHwNum;
|
BCPUSE = BCPUSE + a.NumM;
|
}
|
});
|
}
|
}
|
|
num[6] = BCPZ / 65536;
|
num[7] = BCPZ % 65536;
|
num[8] = BCPUSE / 65536;
|
num[9] = BCPUSE % 65536;
|
num[10] = NGZ / 65536;
|
num[11] = NGZ % 65536;
|
num[12] = NGUSE / 65536;
|
num[13] = NGUSE % 65536;
|
#endregion
|
|
var wirte1 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = Ware.writeAddr + 70,
|
host = Ware.ip,
|
port = Ware.port,
|
data = num
|
});
|
CMMLog.Info($"在通道{Ware.writeAddr + 70}中写入{JsonConvert.SerializeObject(num)},ip:{Ware.ip},端口:{Ware.port}");
|
}
|
|
internal static void writeLKQtt()
|
{
|
var LKWare = Settings.GetwareInfoList().Where(a => a.wareName == "立库" && a.enable == 1).FirstOrDefault();
|
if (LKWare != null)
|
{
|
var url = hao.WebUrl + "GlmSecAreaLoacNum";
|
int[] num = new int[38];
|
int KWZ = 0; //库位总量
|
int KWUSE = 0; //库位已使用数量
|
int outTotal = 0; //出库总量
|
int inTotal = 0; //入库总量
|
int outTotalDay = 0; //当日出库数量
|
int inTotalDay = 0; //当日入库数量
|
int outTotalMon= 0; //当月出库数量
|
int inTotalMon = 0; //当月入库数量
|
int outTotalWee = 0; //当周出库数量
|
int inTotalWee = 0; //当周入库数量
|
|
#region 仓库货位数量
|
CJWareNum model = new CJWareNum
|
{
|
AreaCode = new List<string>
|
{
|
"CKHJ",
|
}
|
};
|
|
string msgData = JsonConvert.SerializeObject(model);
|
|
var feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim();
|
CMMLog.Info($"writeLKQtt:【调用wms获取入库货位信息】:接收数据:" + feedback);
|
if (!string.IsNullOrEmpty(feedback))
|
{
|
var wmsResponse = JsonConvert.DeserializeObject<CJInfoResModel>(feedback);
|
if (wmsResponse.Success == true)
|
{
|
KWZ = KWZ + wmsResponse.Data[0].ZHwNum;
|
KWUSE = KWUSE + wmsResponse.Data[0].NumM;
|
}
|
num[0] = KWZ / 65536;
|
num[1] = KWZ % 65536;
|
num[2] = KWUSE / 65536;
|
num[3] = KWUSE % 65536;
|
}
|
|
string year = DateTime.Now.ToString("yyyy");
|
string month = DateTime.Now.ToString("MM");
|
string day = DateTime.Now.ToString("dd");
|
|
// 获取当前日期所在的周的第一天(周日)
|
DateTime startOfWeek = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek);
|
// 获取当前日期所在的周的最后一天(周六)
|
DateTime endOfWeek = startOfWeek.AddDays(6);
|
|
var qunInfo = MongoDBSingleton.Instance.Find<InAndOutQuantity>(Query.EQ("Year", year), "InAndOutQuantity");
|
if(qunInfo.Count > 0)
|
{
|
qunInfo.ForEach(a =>
|
{
|
if(a.Type == "入库")
|
{
|
inTotal = inTotal + a.Quntity; //总入库数量
|
if (a.Month == month) inTotalMon = inTotalMon + a.Quntity; //当月入库数量
|
if (a.Day == day) inTotalDay = inTotalDay + a.Quntity; //当天入库数量
|
if (new DateTime(int.Parse(a.Year), int.Parse(a.Month), int.Parse(a.Day)) >= startOfWeek && new DateTime(int.Parse(a.Year), int.Parse(a.Month), int.Parse(a.Day)) <= endOfWeek) inTotalWee = inTotalWee + a.Quntity; //当周入库数量
|
}
|
else
|
{
|
outTotal = outTotal + a.Quntity; //总出库数量
|
if (a.Month == month) outTotalMon = outTotalMon + a.Quntity; //当月出库数量
|
if (a.Day == day) outTotalDay = outTotalDay + a.Quntity; //当天出库数量
|
if (new DateTime(int.Parse(a.Year), int.Parse(a.Month), int.Parse(a.Day)) >= startOfWeek && new DateTime(int.Parse(a.Year), int.Parse(a.Month), int.Parse(a.Day)) <= endOfWeek) outTotalWee = outTotalWee + a.Quntity; //当周出库数量
|
}
|
});
|
}
|
num[4] = outTotal / 65536;
|
num[5] = outTotal % 65536;
|
num[6] = inTotal / 65536;
|
num[7] = inTotal % 65536;
|
num[8] = outTotalDay % 65536;
|
num[9] = inTotalDay % 65536;
|
num[10] = outTotalMon / 65536;
|
num[11] = inTotalMon % 65536;
|
num[12] = outTotalWee / 65536;
|
num[13] = inTotalWee % 65536;
|
#endregion
|
#region 物料数量
|
List<string> itemList = new List<string> { "NC035S", "NCM50102(512)", "NCM60044(613)", "NCM552016(5520)", "NC034L-D", "NC034S-D"};
|
int x = 0;
|
itemList.ForEach(a =>
|
{
|
x = x + 1;
|
int startNum = (x - 1) * 4 + 14;
|
num[startNum] = x;
|
var itemInfo = new SqlHelper<object>().GetInstance(true, 2).Queryable<WMS_STOCK_VIEW>().Where(b => b.CN_S_STOCK_AREA == "CKHJ" && b.CN_S_LOT_NO == a).First();
|
if(itemInfo != null)
|
{
|
num[startNum +1] = itemInfo.sum_qty;
|
}
|
var itemQun = MongoDBSingleton.Instance.Find<InAndOutitem>(Query.And(Query.EQ("Day", DateTime.Now.ToString("yyyyMMdd")), Query.EQ("itemBatch", a)), "InAndOutitem");
|
if(itemQun.Count > 0)
|
{
|
itemQun.ForEach(b =>
|
{
|
if(b.Type == "入库")
|
{
|
num[startNum + 2] = b.Quntity;
|
}
|
else
|
{
|
num[startNum + 1] = b.Quntity;
|
}
|
});
|
}
|
|
});
|
#endregion
|
|
var wirte1 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = LKWare.writeAddr + 70,
|
host = LKWare.ip,
|
port = LKWare.port,
|
data = num
|
});
|
CMMLog.Info($"在通道{LKWare.writeAddr + 70}中写入{JsonConvert.SerializeObject(num)},ip:{LKWare.ip},端口:{LKWare.port}");
|
}
|
else CMMLog.Info("立库通道未配置");
|
}
|
|
internal static void fcrk(Settings.PlcInfo plc)
|
{
|
int[] num = new int[1] { 2 };
|
var wirte1 = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
|
{
|
addr = plc.writeAddr + 2,
|
host = plc.ip,
|
port = plc.port,
|
data = num
|
});
|
CMMLog.Info($"在通道{plc.writeAddr + 2}中写入{JsonConvert.SerializeObject(num)},ip:{plc.ip},端口:{plc.port}");
|
}
|
|
/// <summary>
|
/// 四钴A(洗板烘干机组)设备上空下满
|
/// </summary>
|
/// <param name="plc"></param>
|
/// <exception cref="NotImplementedException"></exception>
|
internal static void AMachine(Settings.PlcInfo plc)
|
{
|
if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1)
|
{
|
//送空
|
bool req = WMSHelper.WMSOut(plc.location, "", "");
|
if (req) CMMLog.Debug($"四钴A设备 调用WMS获取空托出库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
|
else CMMLog.Debug($"四钴A设备 调用WMS获取空托出库生成任务失败!");
|
}
|
if (result.result[0] == 2)
|
{
|
//取满
|
string wmstaskno = "";
|
string traycode = "";
|
bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
|
if (req) CMMLog.Debug($"四钴A设备 调用WMS获取满托入库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
|
else CMMLog.Debug($"四钴A设备 调用WMS获取满托入库生成任务失败!");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info($"四钴A设备 err:{ex.Message}");
|
}
|
}
|
}
|
|
/// <summary>
|
/// 四钴C(钴板剪切机组)设备上满下空
|
/// </summary>
|
/// <param name="a"></param>
|
/// <exception cref="NotImplementedException"></exception>
|
internal static void CMachine(Settings.PlcInfo plc)
|
{
|
if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1)
|
{
|
//送满
|
bool req = WMSHelper.WMSOut(plc.location, "", "");
|
if (req) CMMLog.Debug($"四钴C设备 调用WMS获取满托出库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
|
else CMMLog.Debug($"四钴C设备 调用WMS获取满托出库生成任务失败!");
|
}
|
if (result.result[0] == 2)
|
{
|
//取空
|
string wmstaskno = "";
|
string traycode = "";
|
bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
|
if (req) CMMLog.Debug($"四钴C设备 调用WMS获取空托入库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
|
else CMMLog.Debug($"四钴C设备 调用WMS获取空托入库生成任务失败!");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info($"四钴C设备 err:{ex.Message}");
|
}
|
}
|
}
|
|
internal static void DGMachine(Settings.PlcInfo plc, string taskNo, bool action)
|
{
|
if (action)
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr + 2,
|
data = 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为1.");
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 2,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Debug($"查询设备{plc.location}通道{plc.readAddr + 2}里面数据为{JsonConvert.SerializeObject(result)}.");
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1)
|
{
|
//推送小车进入
|
TSHelper.GoToAGV(taskNo, 10, 3);
|
writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr + 2,
|
data = 0,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为0.");
|
}
|
}
|
}
|
else
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr + 3,
|
data = 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 3}里面数据为1.");
|
}
|
}
|
|
internal static void DGMachineTwo(Settings.PlcInfo plc, string taskNo, bool action)
|
{
|
if (action)
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr,
|
data = 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为1.");
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr + 1,
|
host = plc.ip,
|
port = plc.port
|
});
|
CMMLog.Debug($"查询设备{plc.location}通道{plc.readAddr + 1}里面数据为{JsonConvert.SerializeObject(result)}.");
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1)
|
{
|
//推送小车进入
|
TSHelper.GoToAGV(taskNo, 10, 3);
|
writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr,
|
data = 0,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为0.");
|
}
|
}
|
}
|
else
|
{
|
var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
|
{
|
host = plc.ip,
|
addr = plc.writeAddr + 1,
|
data = 1,
|
port = plc.port
|
});
|
CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为1.");
|
}
|
}
|
|
internal static void DMachine(Settings.PlcInfo plc)
|
{
|
if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
|
{
|
try
|
{
|
var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
|
{
|
dataNum = 1,
|
addr = plc.readAddr,
|
host = plc.ip,
|
port = plc.port
|
});
|
if (result != null && result.errCode == 0)
|
{
|
if (result.result[0] == 1)
|
{
|
//成品下线任务生成到接驳平台
|
string traycode = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
|
//可生成任务
|
var CBInfo = Settings.GetDGConnectingbitsList().Where(a => a.enable == 1).ToList();
|
if (CBInfo != null)
|
{
|
//string timeStamp = timecuo.data.First().timeStamp.ToString();
|
string timeStamp = "";
|
foreach (var a in CBInfo)
|
{
|
if (!string.IsNullOrEmpty(a.locCode))
|
{
|
//在中间表中查找点位
|
var CBTable = MongoDBSingleton.Instance.FindOne<DGConnectingBits>(Query.EQ("Bit", a.locCode), "DGConnectingBits");
|
if (CBTable != null)
|
{
|
if (string.IsNullOrEmpty(CBTable.trayCode))
|
{
|
//生成任务,并且将点位写入中间表
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "包装机满托下线", 0, traycode);
|
if (amsResult.success)
|
{
|
CMMLog.Debug($"包装机满托下线:AMS调用API成功!");
|
MongoDBSingleton.Instance.Update<DGConnectingBits>(Query.EQ("Bit", a.locCode), Update.Set("trayCode", traycode).Set("timeCuo", timeStamp), UpdateFlags.None);
|
|
break;
|
}
|
else CMMLog.Debug($"包装机满托下线:AMS调用API失败,开始重新调用!");
|
}
|
}
|
else
|
{
|
//生成任务,并且将点位写入中间表
|
var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "包装机满托下线", 0, traycode);
|
if (amsResult.success)
|
{
|
CMMLog.Debug($"包装机满托下线:AMS调用API成功!");
|
//打包下线任务生成成功,向中间表插入数据
|
|
MongoDBSingleton.Instance.Insert<DGConnectingBits>(new DGConnectingBits { Bit = a.locCode, trayCode = traycode, state = "0", timeCuo = timeStamp });
|
break;
|
}
|
else CMMLog.Debug($"包装机满托下线:AMS调用API失败,开始重新调用!");
|
}
|
}
|
else CMMLog.Debug("打包下线口接驳位点位未配置");
|
}
|
}
|
else CMMLog.Debug("打包下线口接驳位未配置");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
CMMLog.Info($"四钴C设备 err:{ex.Message}");
|
}
|
}
|
}
|
|
#endregion
|
|
public class WMS_STOCK_VIEW
|
{
|
public string CN_S_STOCK_AREA { get; set; }
|
public string CN_S_LOT_NO { get; set; }
|
public int sum_qty { get; set; }
|
}
|
|
|
public class CJWareNum
|
{
|
public List<string> AreaCode { get; set; }
|
public string TrayCode { get; set; } = "";
|
}
|
public class CJInfoResModel
|
{
|
public int Status { get; set; }
|
public string Code { get; set; }
|
public string Msg { get; set; }
|
public List<CJData> Data { get; set; }
|
public int AffectedRows { get; set; }
|
|
public bool Success { get; set; }
|
}
|
|
public class CJData
|
{
|
public string AreaCode { get; set; }
|
/// <summary>
|
/// 货位总量
|
/// </summary>
|
public int ZHwNum { get; set; }
|
public int NumK { get; set; }
|
public int NumM { get; set; }
|
}
|
|
public class LKInfoResModel
|
{
|
public int Status { get; set; }
|
public string Code { get; set; }
|
public string Msg { get; set; }
|
public LKData Data { get; set; }
|
public int AffectedRows { get; set; }
|
|
public bool Success { get; set; }
|
}
|
|
public class LKData
|
{
|
public string CN_S_LOT_NO { get; set; }
|
public int CN_S_EXT8 { get; set; }
|
}
|
|
#endregion
|
|
#endregion
|
|
public class Z_ChaiPanEmptyOrFull
|
{
|
public ObjectId _id { get; set; }
|
/// <summary>
|
/// 拆盘点位
|
/// </summary>
|
public string ChaiPanBit { get; set; }
|
/// <summary>
|
/// 拆盘点位空满状态--空|满
|
/// </summary>
|
public string ChaiPanState { get; set; }
|
}
|
|
|
public class ActionControlModel
|
{
|
public ObjectId _id { get; set; }
|
/// <summary>
|
/// 功能码-- 1-生成复称平台入缓存架任务
|
/// </summary>
|
public string actionNo { get; set; } = "0";
|
/// <summary>
|
/// 1-ip
|
/// </summary>
|
public string ext1 { get; set; } = "";
|
/// <summary>
|
/// 1-CN_S_BATCH_NO
|
/// </summary>
|
public string ext2 { get; set; } = "";
|
public int ext3 { get; set; } = 0;
|
public string machince { get; set; } = "";
|
}
|
|
public class packageInfoModel
|
{
|
public ObjectId _id { get; set; }
|
/// <summary>
|
/// 包装机号
|
/// </summary>
|
public string machineNo { get; set; } = "";
|
/// <summary>
|
/// 托盘号
|
/// </summary>
|
public string trayCode { get; set; } = "";
|
/// <summary>
|
/// 批次号
|
/// </summary>
|
public string batchNo { get; set; } = "";
|
/// <summary>
|
/// 下料时间
|
/// </summary>
|
public string time { get; set; } = "";
|
/// <summary>
|
/// 重量
|
/// </summary>
|
public string weight { get; set; } = "";
|
/// <summary>
|
/// 复称重量
|
/// </summary>
|
public string weight2 { get; set; } = "";
|
/// <summary>
|
/// 重量差值
|
/// </summary>
|
public string weightDifference { get; set; } = "";
|
}
|
|
}
|
}
|