一楼调度

master
sunzy 2 years ago
parent eeb882a7c8
commit 4781bf8e66

@ -1,15 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Khd.Core.Domain.Dto.webapi;
using Khd.Core.Domain.Models;
namespace Khd.Core.Application.Interface
{
public interface IMesProdPlanApplication : IBaseApplication<MesProdPlan>
{
MesProdPlan Get(int id);
MesProdPlan Add(MesProdPlan model);
MesProdPlan Update(MesProdPlan model);
ReponseBase SaveProdPlan(RequestInfo model);
}
}

@ -1,73 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Khd.Core.Application.Interface;
using Khd.Core.Domain.Dto.webapi;
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Masuit.Tools.Logging;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.Extensions.DependencyInjection;
using Z.EntityFramework.Plus;
namespace Khd.Core.Application
{
public class MesProdPlanApplication : IMesProdPlanApplication
{
private readonly DefaultDbContext _dbContext;
public MesProdPlanApplication(IServiceProvider serviceProvider)
{
_dbContext = serviceProvider.GetService<DefaultDbContext>();
}
public MesProdPlan Get(int id)
{
var entity = _dbContext.MesProdPlan
.Where(c => 1== 1)
.FirstOrDefault();
return entity;
}
public MesProdPlan Add(MesProdPlan model)
{
model.CREATE_TIME = DateTime.Now.ToString();
var entity = _dbContext.Add(model);
_dbContext.SaveChanges();
return entity.Entity;
}
public ReponseBase SaveProdPlan(RequestInfo model)
{
ReponseBase reponseBase = new ReponseBase();
reponseBase.CODE = "S";
try
{
foreach (var item in model.DATA)
{
item.ID = Guid.NewGuid();
item.CREATE_TIME = DateTime.Now.ToString();
item.FLAG = "0";
var entity = _dbContext.Add(item);
}
_dbContext.SaveChanges();
reponseBase.MESSAGE = "接收成功!"; ;
}
catch (Exception ex)
{
reponseBase.CODE = "E";
reponseBase.MESSAGE = ex.Message;
}
return reponseBase;
}
public MesProdPlan Update(MesProdPlan model)
{
var list = _dbContext.MesProdPlan.Where(t => t.ID == model.ID).Update(a => model);
return model;
}
}
}

@ -48,7 +48,7 @@ namespace Khd.Core.Domain.Models
/// <summary>
/// 占用数量;申请时占用的数量,在出库时要减去出库数量,并且总数量要同步更新;
//或者在柜体拆分后返库后占用的数量,在组装时需要匹配出
/// </summary>
[Column("occupy_amount")]
public decimal? occupyAmount { get; set; }

@ -0,0 +1,175 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Khd.Core.Wcs
{
public class HttpHelper
{
public static string SendPostMessage(string ip,int port, string url, string message)
{
var contentType = "application/Text";
string retsult = HttpPost("http://" + ip+":"+ port + "/" + url, message, contentType, 30, null);
return retsult;
}
public static string SendGetMessage(string ip, int port, string url)
{
string retsult = HttpGet("http://" + ip+":"+ port + "/" + url);
return retsult;
}
/// <summary>
/// 发起POST同步请求
///
/// </summary>
/// <param name="url"></param>
/// <param name="postData"></param>
/// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
/// <param name="headers">填充消息头</param>
/// <returns></returns>
public static string HttpPost(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary<string, string> headers = null)
{
postData = postData ?? "";
using (HttpClient client = new HttpClient())
{
if (headers != null)
{
foreach (var header in headers)
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
using (HttpContent httpContent = new StringContent(postData, Encoding.UTF8))
{
if (contentType != null)
httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
HttpResponseMessage response = client.PostAsync(url, httpContent).Result;
return response.Content.ReadAsStringAsync().Result;
}
}
}
/// <summary>
/// 发起POST异步请求
/// </summary>
/// <param name="url"></param>
/// <param name="postData"></param>
/// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
/// <param name="headers">填充消息头</param>
/// <returns></returns>
public static async Task<string> HttpPostAsync(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary<string, string> headers = null)
{
postData = postData ?? "";
using (HttpClient client = new HttpClient())
{
client.Timeout = new TimeSpan(0, 0, timeOut);
if (headers != null)
{
foreach (var header in headers)
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
using (HttpContent httpContent = new StringContent(postData, Encoding.UTF8))
{
if (contentType != null)
httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
HttpResponseMessage response = await client.PostAsync(url, httpContent);
return await response.Content.ReadAsStringAsync();
}
}
}
/// <summary>
/// 发起GET同步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static string HttpGet(string url, Dictionary<string, string> headers = null)
{
using (HttpClient client = new HttpClient())
{
if (headers != null)
{
foreach (var header in headers)
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
HttpResponseMessage response = client.GetAsync(url).Result;
return response.Content.ReadAsStringAsync().Result;
}
}
/// <summary>
/// 发起GET异步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static async Task<string> HttpGetAsync(string url, Dictionary<string, string> headers = null)
{
using (HttpClient client = new HttpClient())
{
if (headers != null)
{
foreach (var header in headers)
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
HttpResponseMessage response = await client.GetAsync(url);
return await response.Content.ReadAsStringAsync();
}
}
/// <summary>
/// 发起GET同步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static string HttpDelete(string url, Dictionary<string, string> headers = null)
{
using (HttpClient client = new HttpClient())
{
if (headers != null)
{
foreach (var header in headers)
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
HttpResponseMessage response = client.DeleteAsync(url).Result;
return response.Content.ReadAsStringAsync().Result;
}
}
/// <summary>
/// 发起GET异步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static async Task<string> HttpDeleteAsync(string url, Dictionary<string, string> headers = null)
{
using (HttpClient client = new HttpClient())
{
if (headers != null)
{
foreach (var header in headers)
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
HttpResponseMessage response = await client.DeleteAsync(url);
return await response.Content.ReadAsStringAsync();
}
}
}
}

@ -43,16 +43,7 @@ namespace Khd.Core.Wcs
WcsChuLiWanCheng = getValue("2", "1");
//设置默认去向=>1为 Int16位
WcsMoRenQuXiang = getValue("2", "1");
//加载物料信息
//StaticData.MateriaList = dbContext.BaseMaterialinfo.Where(t => t.isDelete == 0).OrderBy(t => t.materialNo).ToList();
////加载库区信息
//StaticData.BaseAreaList = dbContext.BaseArea.Where(t => t.isDelete == 0).OrderBy(t => t.areaOrder).ToList();
////加载站台
//StaticData.SiteNodeList = dbContext.BaseSitenode.Where(t => t.isDelete == 0).OrderBy(t => t.siteNo).ToList();
////加载小车
//StaticData.CarList = dbContext.BaseCar.Where(t => t.isDelete == 0).OrderBy(t => t.carNo).ToList();
//加载点位
//StaticData.NodeSettingList = GetNodeSettingList(dbContext);
StaticData.BasePlcpointList = dbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList();
//加载配置项
@ -65,53 +56,19 @@ namespace Khd.Core.Wcs
if (plc.IsConnected)
if (true)
{
//启动处理订单线程
BackUpData orderbak = new BackUpData(this._host);
orderbak.StartPoint();
Console.WriteLine("处理订单线程启动完毕!");
//一楼调度线程
FirstFloor firstFloor = new FirstFloor(this._host,plc, "一楼输送线");
firstFloor.StartPoint();
Console.WriteLine("一楼调度线程开启!");
//二楼楼调度线程
//三楼调度线程
//四楼调度线程
//五楼调度线程
//启动上件点线程1
UpLine up1 = new UpLine(this._host, plc, "K46");
up1.StartPoint();
Console.WriteLine("2号上件点线程启动完毕!");
//启动上件点线程2
UpLine up2 = new UpLine(this._host, plc, "K48");
up2.StartPoint();
Console.WriteLine("1号上件点线程启动完毕!");
//启动流转点线程1
FlowPoint flow1 = new FlowPoint(this._host, plc, "K18");
flow1.StartPoint();
Console.WriteLine("K18流转点线程启动完毕!");
//启动流转点线程2
FlowPoint flow2 = new FlowPoint(this._host, plc, "K22");
flow2.StartPoint();
Console.WriteLine("K22流转点线程启动完毕!");
//启动流转点线程3
FlowPoint flow3 = new FlowPoint(this._host, plc, "K48");
flow3.StartPoint();
Console.WriteLine("K48流转点线程启动完毕!");
//启动下件点线程1
OutWarePoint out1 = new OutWarePoint(this._host, plc, "K07");
out1.StartPoint();
Console.WriteLine("K07下件点线程启动完毕!");
//启动下件点线程2
OutWarePoint out2 = new OutWarePoint(this._host, plc, "K02");
out2.StartPoint();
Console.WriteLine("K02下件点线程启动完毕!");
//启动入库点线程
//启动出库点线程
//启动出库线程
//报警监控线程
}
}
catch (Exception ex)
@ -129,51 +86,7 @@ namespace Khd.Core.Wcs
LogManager.Error(ex);
}
}
/// <summary>
/// 加载点位
/// </summary>
/// <param name="defaultDbContext"></param>
/// <returns></returns>
public List<NodeSetting> GetNodeSettingList(DefaultDbContext defaultDbContext)
{
try
{
var listSiteNode = defaultDbContext.BaseSitenode.Where(t => t.isDelete == 0).ToList();
var listPlcPoint = defaultDbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList();
var resultList = (from siteNode in listSiteNode
join plcPoint in listPlcPoint on siteNode.id equals plcPoint.sitenodeId
select new NodeSetting
{
// 根据需要设置NodeSetting的属性值
id = (Guid)siteNode.id,
siteNo = siteNode.siteNo,
siteName = siteNode.siteName,
siteTasktype = siteNode.siteTasktype,
siteIpaddress = siteNode.siteIpaddress,
siteServerport = siteNode.siteServerport,
thriftPort = siteNode.thriftPort,
isDelete = siteNode.isDelete,
plcpointNo = plcPoint.plcpointNo,
plcpointName = plcPoint.plcpointName,
plcpointLength = plcPoint.plcpointLength,
plcpointAddress = plcPoint.plcpointAddress,
plcpointEquipmentId = plcPoint.plcpointEquipmentId,
plcpointEquipmentNo = plcPoint.plcpointEquipmentNo,
plcpointEquipmentName = plcPoint.plcpointEquipmentName,
plcpointType = plcPoint.plcpointType
}).ToList();
if (resultList == null)
{
return null;
}
return resultList;
}
catch (Exception ex)
{
LogManager.Error(ex);
return null;
}
}
/// <summary>
/// 电气写入点位高低位转换
/// </summary>

@ -1,116 +0,0 @@
//-----------------------------------------------------------------------
//<copyright>
// * Copyright (C) 2021 KEHAIDASOFT All Rights Reserved
// * version : 4.0.30319.42000
// * author : khd by t4-2
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Khd.Core.Domain.Models
{
[Table("base_dictionary")]
public class BaseDictionary
{
[Key]
[Column("OBJID")]
public Guid objid { get; set; }
/// <summary>
/// 字典名
/// </summary>
[Column("DIC_NAME")]
public string dicName { get; set; }
/// <summary>
/// 字段名
/// </summary>
[Column("DIC_FIELD")]
public string dicField { get; set; }
/// <summary>
/// 对应名
/// </summary>
[Column("DIC_KEY")]
public string dicKey { get; set; }
/// <summary>
/// 对应值
/// </summary>
[Column("DIC_VALUE")]
public string dicValue { get; set; }
/// <summary>
/// 排序
/// </summary>
[Column("DIC_SORT")]
public string dicSort { get; set; }
/// <summary>
/// 是否允许编辑 1允许 0不允许
/// </summary>
[Column("IS_EDIT")]
public int? isEdit { get; set; }
/// <summary>
/// 是否可用 0:不可用 1:可用
/// </summary>
[Column("USE_FLAG")]
public int? useFlag { get; set; }
/// <summary>
/// 创建者
/// </summary>
[Column("CREATE_BY")]
public string createBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[Column("CREATE_TIME")]
public DateTime? createTime { get; set; }
/// <summary>
/// 更新者
/// </summary>
[Column("UPDATE_BY")]
public string updateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[Column("UPDATE_TIME")]
public DateTime? updateTime { get; set; }
/// <summary>
/// 备用字段1
/// </summary>
[Column("UD1")]
public string ud1 { get; set; }
/// <summary>
/// 备用字段2
/// </summary>
[Column("UD2")]
public string ud2 { get; set; }
/// <summary>
/// 备用字段3
/// </summary>
[Column("UD3")]
public string ud3 { get; set; }
/// <summary>
/// 备注
/// </summary>
[Column("REMARK")]
public string remark { get; set; }
}
}

@ -0,0 +1,217 @@
using Khd.Core.Domain.Dto.wcs;
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Khd.Core.Wcs.Global;
using Masuit.Tools.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using Thrift.Server;
using Thrift.Transport;
using ThriftService;
using static AngleSharp.Css.Values.CssRadialGradientValue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Thrift.Protocol;
using System.Security.Cryptography.Xml;
using Z.EntityFramework.Plus;
using System.Net.NetworkInformation;
namespace Khd.Core.Wcs.Wcs
{
/// <summary>
/// 一楼线程
/// </summary>
public class FirstFloor
{
private readonly IHost _host;
private readonly Plc.S7.Plc _plc;
/// <summary>
/// 一楼RFID 读
/// </summary>
BasePlcpoint? RFID001 { get; set; }
/// <summary>
/// 到位信号 读
/// </summary>
BasePlcpoint? linesignal01 { get; set; }
/// <summary>
/// 是否有托盘 读
/// </summary>
BasePlcpoint? ispallet01 { get; set; }
/// <summary>
/// 去向 写
/// </summary>
BasePlcpoint? wcsrun01 { get; set; }
/// <summary>
/// 流水号 读
/// </summary>
BasePlcpoint? serialno01 { get; set; }
/// <summary>
/// 反馈流水号 写
/// </summary>
BasePlcpoint? feedserialno01 { get; set; }
/// <summary>
/// 一楼提升机流水号 读
/// </summary>
BasePlcpoint? serialno06 { get; set; }
/// <summary>
/// 一楼提升机状态 读
/// </summary>
BasePlcpoint? equipstate06 { get; set; }
/// <summary>
/// 一楼提升机任务状态 读
/// </summary>
BasePlcpoint? taskstate06 { get; set; }
/// <summary>
/// 一楼提升机当前楼层 写
/// </summary>
BasePlcpoint? currentfloor06 { get; set; }
/// <summary>
/// 一楼提升机目的楼层 写
/// </summary>
BasePlcpoint? targetfloor06 { get; set; }
/// <summary>
/// 一楼提升机到位信号 读
/// </summary>
BasePlcpoint? linesignal06 { get; set; }
public FirstFloor(IHost host, Plc.S7.Plc plc, string siteNo)
{
this._host = host;
this._plc = plc;
//一楼RFID 读
this.RFID001 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") &&t.plcpointNo.Contains("RFID001"));
//到位信号 读
this.linesignal01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("linesignal01"));
//是否有托盘 读
this.ispallet01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("ispallet01"));
//去向 写
this.wcsrun01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("wcsrun01"));
//流水号 读
this.serialno01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("serialno01"));
//反馈流水号 写
this.feedserialno01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("feedserialno01"));
//一楼提升机流水号 读
this.serialno06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("serialno06"));
//一楼提升机状态 读
this.equipstate06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("equipstate06"));
//一楼提升机任务状态 读
this.taskstate06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("taskstate06"));
//一楼提升机当前楼层 写
this.currentfloor06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("currentfloor06"));
//一楼提升机目的楼层 写
this.targetfloor06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("targetfloor06"));
//一楼提升机到位信号 读
this.linesignal06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("linesignal06"));
}
/// <summary>
/// 启动线程
/// </summary>
public void StartPoint()
{
Thread firstFloorLine = new Thread(FirstFloorLine);
firstFloorLine.IsBackground = true;
firstFloorLine.Start();
Console.WriteLine("启动一楼接驳位线程");
Thread firstFloorHoister = new Thread(FirstFloorHoister);
firstFloorHoister.IsBackground = true;
firstFloorHoister.Start();
Console.WriteLine("启动一楼提升机线程");
}
/// <summary>
/// 启动一楼接驳位线程
/// </summary>
private void FirstFloorLine()
{
while (true)
{
try
{
var RFID001Value = this._plc.Read(this.RFID001.plcpointAddress); //一楼RFID 读
var linesignal01Value = this._plc.Read(this.linesignal01.plcpointAddress); //到位信号 读
var ispallet01Value = this._plc.Read(this.ispallet01.plcpointAddress); //是否有托盘 读
var wcsrun01Value = this._plc.Read(this.wcsrun01.plcpointAddress); //去向 写
var serialno01Value = this._plc.Read(this.serialno01.plcpointAddress); //流水号 读
var feedserialno01Value = this._plc.Read(this.feedserialno01.plcpointAddress); //反馈流水号 写
using (var scope = _host.Services.CreateScope())
{
using (var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>())
{
//正常读到plc值
if (linesignal01Value != null && RFID001Value != null || ispallet01Value != null || serialno01Value != null)
{
//正常托盘到位
if (Convert.ToInt32(linesignal01Value) != 0 && Convert.ToInt32(serialno01Value) != 0 && Convert.ToInt32(ispallet01Value) == 1 && Convert.ToInt32(ispallet01Value) != 0)
{
//根据托盘号获取物料码
//下发去向
}
}
}
}
}
catch (Exception ex)
{
LogManager.Error(ex);
}
Thread.Sleep(2000);
}
}
/// <summary>
/// 启动一楼提升机线程
/// </summary>
private void FirstFloorHoister()
{
while (true)
{
try
{
var serialno06Value = this._plc.Read(this.serialno06.plcpointAddress); //一楼提升机流水号 读
var equipstate06Value = this._plc.Read(this.equipstate06.plcpointAddress); //一楼提升机状态 读
var taskstate06Value = this._plc.Read(this.taskstate06.plcpointAddress); //一楼提升机任务状态 读
var currentfloor06Value = this._plc.Read(this.currentfloor06.plcpointAddress); //一楼提升机当前楼层 写
var targetfloor06Value = this._plc.Read(this.targetfloor06.plcpointAddress); //一楼提升机目的楼层 写
var linesignal06Value = this._plc.Read(this.linesignal06.plcpointAddress); //一楼提升机到位信号 读
using (var scope = _host.Services.CreateScope())
{
using (var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>())
{
//正常读到plc值
if (serialno06Value != null && equipstate06Value != null || taskstate06Value != null || linesignal06Value != null)
{
//正常托盘到位
if (Convert.ToInt32(serialno06Value) != 0 && Convert.ToInt32(equipstate06Value) != 1 && Convert.ToInt32(linesignal06Value) == 1)
{
//根据流水号查询任务 分配去向
}
}
}
}
}
catch (Exception ex)
{
LogManager.Error(ex);
}
Thread.Sleep(2000);
}
}
}
}

@ -3,7 +3,7 @@
//
//"DefaultConnection": "server=192.168.0.81;port=3306;database=khd_suspension_chain;uid=root;pwd=123456;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True"
//mysql
"DefaultConnection": "server=localhost;port=3306;database=khd_suspension_chain;uid=root;pwd=root;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True"
"DefaultConnection": "server=localhost;port=3306;database=khd_jyhb;uid=root;pwd=root;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True"
//khd
//"DefaultConnection": "server=106.12.13.113;port=3336;database=khd_suspension_chain;uid=khd;pwd=khd@123;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True"
},

Loading…
Cancel
Save