change-3F业务修改

dev
liuwf 4 months ago
parent 47fb0844d2
commit f6c4a7ae60

@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
#region << 版 本 注 释 >> #region << 版 本 注 释 >>
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@ -57,8 +58,10 @@ namespace SlnMesnac.Business
_msInstockService = msInstockService; _msInstockService = msInstockService;
_realPalletTaskService = realPalletTaskService; _realPalletTaskService = realPalletTaskService;
_palletTasks = palletTasks; _palletTasks = palletTasks;
} }
/// <summary> /// <summary>
/// 刷新托盘队列 /// 刷新托盘队列
/// </summary> /// </summary>
@ -69,6 +72,7 @@ namespace SlnMesnac.Business
public void Init() public void Init()
{ {
EmptyPalletHandle(); EmptyPalletHandle();
} }
/// <summary> /// <summary>
@ -90,7 +94,7 @@ namespace SlnMesnac.Business
continue; continue;
} }
if (plc.readInt16ByAddress(GetPlcAddressByConfigKey("空托到位")) != 1) if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("空托到位")))
{ {
_logger.LogInformation("等待空托盘到位信号触发......"); _logger.LogInformation("等待空托盘到位信号触发......");
Thread.Sleep(5000); Thread.Sleep(5000);

@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SlnMesnac.Business.@base; using SlnMesnac.Business.@base;
using SlnMesnac.Common;
using SlnMesnac.Config; using SlnMesnac.Config;
using SlnMesnac.Model.domain; using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto; using SlnMesnac.Model.dto;
@ -12,6 +13,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
#region << 版 本 注 释 >> #region << 版 本 注 释 >>
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@ -45,7 +47,7 @@ namespace SlnMesnac.Business
private readonly IMesProductPlanService _mesProductPlanService; private readonly IMesProductPlanService _mesProductPlanService;
private readonly IRealBarCodeTaskService _barCodeTaskService; private readonly IRealBarCodeTaskService _barCodeTaskService;
private readonly GunHelper gunHelper = GunHelper.Instance;
private List<RealBarCodeTask> _barCodeTasks; private List<RealBarCodeTask> _barCodeTasks;
public ProdCompletionBusiness(ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IRealBarCodeTaskService barCodeTaskService, List<RealBarCodeTask> barCodeTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) public ProdCompletionBusiness(ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IRealBarCodeTaskService barCodeTaskService, List<RealBarCodeTask> barCodeTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
@ -53,6 +55,7 @@ namespace SlnMesnac.Business
_mesProductPlanService = mesProductPlanService; _mesProductPlanService = mesProductPlanService;
_barCodeTaskService = barCodeTaskService; _barCodeTaskService = barCodeTaskService;
_barCodeTasks = barCodeTasks; _barCodeTasks = barCodeTasks;
} }
/// <summary> /// <summary>
@ -114,6 +117,8 @@ namespace SlnMesnac.Business
} }
} }
RealBarCodeTask barCodeTask = new RealBarCodeTask() RealBarCodeTask barCodeTask = new RealBarCodeTask()
{ {
BarCode = barCode, BarCode = barCode,
@ -158,5 +163,17 @@ namespace SlnMesnac.Business
_barCodeTaskService.RemoveBarCodeTask(barCode); _barCodeTaskService.RemoveBarCodeTask(barCode);
RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks ); RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks );
} }
//public void testPenCode()
//{
// //生成小包条码
// string materialCode = "000000000";
// string barCode = $"JYHB{(string.IsNullOrEmpty(materialCode) ? "000000000" : materialCode)}-000001";
// ExtractNumber(task.BarCode, out int orFlag);
// barCode = $"JYHB{(string.IsNullOrEmpty(productPlanDto.MaterialCode) ? "000000000" : productPlanDto.MaterialCode)}-{orFlag.ToString().PadLeft(6, '0')}";
//}
} }
} }

@ -42,7 +42,7 @@ using TouchSocket.Core;
namespace SlnMesnac.Business namespace SlnMesnac.Business
{ {
/// <summary> /// <summary>
/// 设备生产管理业务类 /// 设备生产管理业务类 -3F
/// </summary> /// </summary>
public class ProdMgmtBusiness: BaseBusiness public class ProdMgmtBusiness: BaseBusiness
{ {
@ -50,13 +50,17 @@ namespace SlnMesnac.Business
public readonly IBasePalletInfoService _basePalletInfoService; public readonly IBasePalletInfoService _basePalletInfoService;
public readonly IBaseRealTaskService _baseRealTaskService;
private List<RealPalletTask> _palletTasks; private List<RealPalletTask> _palletTasks;
private DebugConfig debugConfig = DebugConfig.Instance;
public ProdMgmtBusiness(ILogger<ProdMgmtBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, List<RealPalletTask> palletTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) public ProdMgmtBusiness(ILogger<ProdMgmtBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, List<RealPalletTask> palletTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
{ {
_mesProductPlanService = mesProductPlanService; _mesProductPlanService = mesProductPlanService;
_basePalletInfoService = basePalletInfoService; _basePalletInfoService = basePalletInfoService;
_baseRealTaskService = baseRealTaskService;
_palletTasks = palletTasks; _palletTasks = palletTasks;
} }
@ -107,7 +111,7 @@ namespace SlnMesnac.Business
} }
/// <summary> /// <summary>
/// 计划执行逻辑处理 /// 计划执行,叫料逻辑处理
/// </summary> /// </summary>
private void ProdPlanExecHandle() private void ProdPlanExecHandle()
{ {
@ -120,26 +124,39 @@ namespace SlnMesnac.Business
if (plc == null) if (plc == null)
{ {
throw new ArgumentException($"PLC连接信息为空"); //throw new ArgumentException($"PLC连接信息为空");
RefreshMessage($"PLC连接信息为空");
} }
MesProductPlan prodPlan = _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto); MesProductPlan prodPlan = _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto);
if (prodPlan == null || productPlanDto == null) if (prodPlan == null || productPlanDto == null)
{ {
throw new ArgumentException($"未获取到需要执行的生产计划"); //throw new ArgumentException($"未获取到需要执行的生产计划");
RefreshMessage($"未获取到需要执行的生产计划");
Thread.Sleep(5000);
continue;
} }
if (plc.readInt16ByAddress(GetPlcAddressByConfigKey("设备叫料")) != 1) if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("设备叫料")))
{ {
_logger.LogInformation("等待设备叫料信号触发......"); RefreshMessage("等待设备叫料信号触发......");
Thread.Sleep(5000);
continue;
}
BaseRealTask task = _baseRealTaskService.GetExeTask();
if (task!=null) {
RefreshMessage("已经叫料请等待AGV送料......");
Thread.Sleep(5000); Thread.Sleep(5000);
continue; continue;
} }
RefreshMessage("设备要料信号触发成功"); RefreshMessage("设备要料信号触发成功");
RefreshProdPlanExecEvent?.Invoke(prodPlan); RefreshProdPlanExecEvent?.Invoke(prodPlan);
string palletCode = GetPalletInfoByTask(); // string palletCode = GetPalletInfoByTask();
RefreshMessage($"执行计划:{prodPlan.PlanCode};计划数量:{Math.Round(prodPlan.PlanAmount,2)};完成数量:{Math.Round(prodPlan.CompleteAmount,2)};发起叫料申请等待AGV送料......"); RefreshMessage($"执行计划:{prodPlan.PlanCode};计划数量:{Math.Round(prodPlan.PlanAmount,2)};完成数量:{Math.Round(prodPlan.CompleteAmount,2)};发起叫料申请等待AGV送料......");
@ -147,8 +164,18 @@ namespace SlnMesnac.Business
if (ApplyDeliveryHandle(productPlanDto.MaterialId.ToString())) if (ApplyDeliveryHandle(productPlanDto.MaterialId.ToString()))
{ {
RefreshMessage("根据计划自动申请叫料成功"); RefreshMessage("根据计划自动申请叫料成功");
#region 本地创建一个叫料任务
plc.writeInt16ByAddress(GetPlcAddressByConfigKey("设备叫料"), 0); BaseRealTask realTask = new BaseRealTask();
realTask.PlanCode = prodPlan.PlanCode;
realTask.PlanAmount = prodPlan.PlanAmount;
realTask.PlanComplete = prodPlan.CompleteAmount;
realTask.MaterialId = prodPlan.MaterialId;
realTask.Status = 1;
realTask.CreateTime = DateTime.Now;
realTask.UpdateTime = DateTime.Now;
_baseRealTaskService.InsertTask(realTask);
#endregion
plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备叫料"), false);
} }
else else
{ {
@ -158,7 +185,7 @@ namespace SlnMesnac.Business
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogInformation($"计划执行逻辑处理异常:{e.Message}"); _logger.LogError($"计划执行逻辑处理异常:{e.Message}");
} }
Thread.Sleep(5000); Thread.Sleep(5000);
} }
@ -173,73 +200,111 @@ namespace SlnMesnac.Business
bool result = false; bool result = false;
while (true) while (true)
{ {
//获取当前计划 //mes计划
var prodPlan = _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto); MesProductPlan prodPlan = null;
//本地叫料任务
BaseRealTask localPlan = null;
try try
{ {
var plc = base.GetPlcByKey("plc"); var plc = base.GetPlcByKey("plc");
if(plc == null) if (plc == null)
{ {
_logger.LogInformation("读取物料到位信号,PLC连接信息为空......"); _logger.LogInformation("读取物料到位信号,PLC连接信息为空......");
Thread.Sleep(3000); Thread.Sleep(3000);
continue; continue;
} }
if (plc.readInt16ByAddress(GetPlcAddressByConfigKey("物料到位")) != 1) if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("物料到位")))
{ {
_logger.LogInformation("等待物料到位信号触发......"); _logger.LogInformation("等待物料到位信号触发......");
Thread.Sleep(3000); Thread.Sleep(3000);
continue; continue;
} }
if (productPlanDto == null || prodPlan == null) // TODO 时间校验
bool timeCheck = JudgeProductTime();
if (!timeCheck)
{ {
RefreshMessage($"收到物料到位信号,未获取到正在执行的生产计划,请开始执行计划"); RefreshMessage($"收到物料到位信号,但是距离上次投料不满20min,禁止投料");
plc.writeInt16ByAddress(GetPlcAddressByConfigKey("物料到位"), 0); Thread.Sleep(1000 * 15);
Thread.Sleep(3000);
continue; continue;
} }
plc.writeInt16ByAddress(GetPlcAddressByConfigKey("物料到位"), 0); //TODO 调用调度接口判断AGV小车是否已经离开到位否则不允许投料
RefreshMessage("物料到位信号触发成功,读取托盘RFID信息进行投料校验");
ReadEpcStrByRfidKey("test", out string epcStr);
RefreshMessage($"投料校验RFID标签读取成功标签信息{epcStr}"); //TODO根据本地叫料计划查询对应的mes计划完成
prodPlan = _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto);
//获取物料托盘上的物料信息 if (productPlanDto == null || prodPlan == null)
BasePalletInfo palletInfo = _basePalletInfoService.GetPalletInfoByPalletCode(epcStr);
if (palletInfo == null)
{
result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, "投料校验失败,未获取到托盘信息,是否继续投料");
}
else
{ {
if (palletInfo.MaterialId != prodPlan.MaterialId) RefreshMessage($"收到物料到位信号,未获取到正在执行的生产计划,请开始执行计划");
{
result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, "投料校验失败,物料信息不匹配,是否继续投料"); Thread.Sleep(5000);
} continue;
else
{
result = true;
}
} }
if (result)
// 获取本地执行中的叫料任务,完成本地任务
localPlan = _baseRealTaskService.GetExeTask();
if (localPlan == null)
{ {
bool isRes = _basePalletInfoService.UnBindPalletInfo(palletInfo);
RefreshMessage($"物料校验通过,托盘信息解绑{(isRes ? "" : "")}");
} }
#region 物料校验 -- TODO 如果计划暂停,开启新计划,校验当前滞留物料是与前一条计划判断,还是当前开始的计划判断
//RefreshMessage("物料到位信号触发成功,读取托盘RFID信息进行投料校验");
//ReadEpcStrByRfidKey("test", out string epcStr);
//RefreshMessage($"投料校验RFID标签读取成功标签信息{epcStr}");
////获取物料托盘上的物料信息
//BasePalletInfo palletInfo = _basePalletInfoService.GetPalletInfoByPalletCode(epcStr);
//if (palletInfo == null)
//{
// result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, "投料校验失败,未获取到托盘信息,是否继续投料");
//}
//else
//{
// if (palletInfo.MaterialId != prodPlan.MaterialId)
// {
// result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, "投料校验失败,物料信息不匹配,是否继续投料");
// }
// else
// {
// result = true;
// }
//}
//if (result)
//{
// bool isRes = _basePalletInfoService.UnBindPalletInfo(palletInfo);
// RefreshMessage($"物料校验通过,托盘信息解绑{(isRes ? "成功" : "失败")}");
//}
#endregion
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogInformation($"投料校验异常:{e.Message}"); _logger.LogInformation($"投料校验异常:{e.Message}");
result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, $"投料校验异常:{e.Message},是否继续投料"); // TODO修改成传入本地计划查询出的mes计划
// result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, $"投料校验异常:{e.Message},是否继续投料");
} }
if (prodPlan != null)
{
// TODO修改成传入本地计划查询出的mes计划停止计划导致的滞留物料归属哪个订单计划对应更新
PutInResutlHandle(prodPlan, result);
PutInResutlHandle(prodPlan, result); // 完成本地计划
if(localPlan!= null)
{
localPlan.Status = 2;
localPlan.UpdateTime = DateTime.Now;
_baseRealTaskService.Update(localPlan);
}
}
Thread.Sleep(3000); Thread.Sleep(3000);
} }
@ -291,7 +356,7 @@ namespace SlnMesnac.Business
} }
/// <summary> /// <summary>
/// 申请叫料 /// 申请叫料TODO等待调度接口
/// </summary> /// </summary>
/// <param name="materialCode"></param> /// <param name="materialCode"></param>
/// <param name="result"></param> /// <param name="result"></param>
@ -310,8 +375,11 @@ namespace SlnMesnac.Business
throw new ArgumentException("申请叫料处理异常:物料参数为空"); throw new ArgumentException("申请叫料处理异常:物料参数为空");
} }
plc.writeInt16ByAddress(base.GetPlcAddressByConfigKey("WCS叫料"), 1);
plc.writeStringByAddress(base.GetPlcAddressByConfigKey("物料型号"), materialCode); // TODO -- 修改为调用wcs接口,参数为申请单id,同时本地生成一个叫料任务,任务状态为执行中
// plc.writeInt16ByAddress(base.GetPlcAddressByConfigKey("WCS叫料"), 1);
// plc.writeStringByAddress(base.GetPlcAddressByConfigKey("物料型号"), materialCode);
result = true; result = true;
} }
@ -358,5 +426,45 @@ namespace SlnMesnac.Business
throw new InvalidOperationException($"生产计划更新异常:{e.Message}"); throw new InvalidOperationException($"生产计划更新异常:{e.Message}");
} }
} }
///
/// <summary
/// 距离上次投料时间合格判断
/// </summary
private bool JudgeProductTime()
{
try
{
int IntervalMin = int.Parse(GetPlcAddressByConfigKey("投料时间间隔")); // 单位分钟
if (debugConfig.LastTime != "")
{
DateTime lastTime = DateTime.Parse(debugConfig.LastTime);
TimeSpan timeDifference = DateTime.Now - lastTime;
if (timeDifference.TotalMinutes > IntervalMin)
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
catch (Exception ex)
{
_logger.LogError($"距离上次投料时间合格判断异常JudgeProductTime{ex.Message}");
return false;
}
}
} }
} }

@ -0,0 +1,254 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SlnMesnac.Common
{
public sealed class GunHelper
{
#region 单例实现
private static readonly GunHelper lazy = new GunHelper();
public static GunHelper Instance
{
get
{
return lazy;
}
}
#endregion
#region 变量定义
private static SerialPort serialPort = new SerialPort();
#endregion
/// <summary>
/// 喷码设备推送
/// </summary>
/// <param name="materialCodeStr"></param>
/// <param name="ip"></param>
public delegate void PushCode(string code);
public static event PushCode PushCodeEvent;
//初始化串口并启动接收数据
public void InstanceSerialPort()
{
try
{
//端口名 注:因为使用的是USB转RS232 所以去设备管理器中查看一下虚拟com口的名字
serialPort.PortName = "COM3";// portName;
//波特率 霍尼威尔扫码枪115200,普通9600
serialPort.BaudRate = 9600;
//奇偶校验
serialPort.Parity = Parity.None;
//停止位
serialPort.StopBits = StopBits.One;
//数据位
serialPort.DataBits = 0x8;
//忽略null字节
serialPort.DiscardNull = true;
//接收事件
serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
//开启串口
serialPort.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
/// <summary>
/// 接收数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string result = "";
int bytesToRead = serialPort.BytesToRead;
byte[] buf = new byte[bytesToRead];
serialPort.Read(buf, 0x0, bytesToRead);
for (int i = 0x0; i < buf.Length; i++)
{
int num = (int)buf[i];
result =result+num.ToString("X2");
}
Console.WriteLine(result);
}
/// <summary>
/// 发送数据方法
/// OK-校验成功关闭灯光NG-校验失败闪烁红灯
/// </summary>
/// <param name="data"></param>
public void SendData(string data)
{
//try
//{
// if (serialPort.IsOpen)
// {
// if (data == "NG")
// {
// byte[] buffer = GetBytesByCommand("CloseRed");
// serialPort.Write(buffer, 0x0, 0x4);
// byte[] buffer1 = GetBytesByCommand("OpenRed");
// serialPort.Write(buffer1, 0x0, 0x4);
// }
// else if (data == "OK")
// {
// byte[] buffer = GetBytesByCommand("CloseRed");
// serialPort.Write(buffer, 0x0, 0x4);
// byte[] buffer1 = GetBytesByCommand("OpenGreen");
// serialPort.Write(buffer1, 0x0, 0x4);
// }
// else if (data == "Exit")
// {
// byte[] buffer = GetBytesByCommand("CloseRed");
// serialPort.Write(buffer, 0x0, 0x4);
// }
// }
// else
// {
// Console.WriteLine("串口未打开,请先初始化串口并打开连接。");
// }
//}
//catch (Exception ex)
//{
// Console.WriteLine($"发送数据时发生错误:{ex.Message}");
//}
}
/// <summary>
/// 条码根据通信协议转换
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
private byte[] GetBytesByCommand(string barCode)
{
byte[] buffer = null;
//byte[] SOI = new byte[] { 0x7E };
//byte[] OrderID = new byte[] { 0x02 };
//byte[] MemoID = new byte[] { 0x00 };
//byte[] Info = EncodeInfoData(barCode);
//byte[] Length = GetLength(Info.Length);
//byte CheckSum = GetCheckSum(OrderID,MemoID,Length,Info);
//byte[] EOI = new byte[] { 0x0D };
// 起始结束7E\0D; SOI OrderID MemoID Length Info CheckSum EOI
// buffer = new byte[] { 0x7E, 0x01, 0x00, Length, iNFO, CheckSum, 0x0D };
return buffer ;
}
//private byte[] GetLength(int length)
//{
//}
private byte[] GetCheckSum(byte[] OrderID, byte[] MemoID, byte[] Length, byte[] Info)
{
// 合并所有数据部分,除去 SOI 和 EOI
List<byte> dataList = new List<byte>();
dataList.AddRange(OrderID);
dataList.AddRange(MemoID);
dataList.AddRange(Length);
dataList.AddRange(Info);
// 计算数据的总和
int sum = 0;
foreach (byte b in dataList)
{
sum += b;
}
// 取模 65536
int moduloResult = sum % 65536;
// 求反并加1
ushort lCheckSUM = (ushort)((~moduloResult & 0xFFFF) + 1);
// 转换为字节数组传输时用4个字节
byte[] checkSumBytes = new byte[4];
checkSumBytes[0] = (byte)((lCheckSUM >> 8) & 0xFF); // 高位
checkSumBytes[1] = (byte)(lCheckSUM & 0xFF); // 低位
checkSumBytes[2] = 0; // 额外的两个字节可以填充为0
checkSumBytes[3] = 0;
return checkSumBytes;
}
public byte[] EncodeInfoData(string data)
{
// 分隔符
byte separator = 0x1F;
// 将数据和useFileName转换成字节序列
byte[] dataBytes = EncodeDataForTransmission(data);
// 组合所有字节序列
List<byte> encodedBytes = new List<byte>();
encodedBytes.AddRange(dataBytes);
encodedBytes.Add(separator);
return encodedBytes.ToArray();
}
byte[] EncodeDataForTransmission(string input)
{
byte[] encodedBytes = new byte[input.Length * 2]; // 每个字符转换为两个字节
for (int i = 0; i < input.Length; i++)
{
char c = input[i];
// 将字符转换为ASCII码
byte asciiValue = (byte)c;
// 将ASCII码拆分为高4位和低4位
byte highNibble = (byte)((asciiValue >> 4) & 0xF); // 高4位
byte lowNibble = (byte)(asciiValue & 0xF); // 低4位
// 转换成ASCII码形式
byte highNibbleAscii = (byte)(highNibble + 0x30); // 转成ASCII码
byte lowNibbleAscii = (byte)(lowNibble + 0x30); // 转成ASCII码
// 存储到结果数组中
encodedBytes[2 * i] = highNibbleAscii;
encodedBytes[2 * i + 1] = lowNibbleAscii;
}
return encodedBytes;
}
}
}

@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" /> <PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,40 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
namespace SlnMesnac.Config
{
/// <summary>
/// 系统配置
/// </summary>
public sealed class DebugConfig
{
private static IniHelper iniHelper = new IniHelper(System.Environment.CurrentDirectory + "/config/App.InI");
private static readonly Lazy<DebugConfig> lazy = new Lazy<DebugConfig>(() => new DebugConfig());
public static DebugConfig Instance
{
get
{
return lazy.Value;
}
}
public DebugConfig()
{
}
/// <summary>
///上次投料时间
/// </summary>
public string LastTime
{
get { return iniHelper.IniReadValue("system", "LastTime"); }
set { iniHelper.IniWriteValue("system", "LastTime", value); }
}
}
}

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Config
{
public class IniHelper
{
public string path;
public IniHelper(string INIPath)
{
path = INIPath;
}
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
[DllImport("kernel32", EntryPoint = "GetPrivateProfileString")]
private static extern uint GetPrivateProfileStringA(string section, string key, string def, Byte[] retVal, int size, string filePath);
/// <summary>
/// 写INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <returns></returns>
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
//return temp.ToString();
string str = temp.ToString();
return str;
}
public byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
return temp;
}
/// <summary>
/// 删除ini文件下所有段落
/// </summary>
public void ClearAllSection()
{
IniWriteValue(null, null, null);
}
/// <summary>
/// 删除ini文件下personal段落下的所有键
/// </summary>
/// <param name="Section"></param>
public void ClearSection(string Section)
{
IniWriteValue(Section, null, null);
}
public List<string> ReadKeys(String SectionName)
{
return ReadKeys(SectionName, this.path);
}
public List<string> ReadKeys(string SectionName, string iniFilename)
{
List<string> result = new List<string>();
Byte[] buf = new Byte[65536];
uint len = GetPrivateProfileStringA(SectionName, null, null, buf, buf.Length, iniFilename);
int j = 0;
for (int i = 0; i < len; i++)
if (buf[i] == 0)
{
result.Add(Encoding.Default.GetString(buf, j, i - j));
j = i + 1;
}
return result;
}
}
}

@ -0,0 +1,65 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace SlnMesnac.Model.domain
{
/// <summary>
/// 当前已经下发的叫料任务
/// </summary>
[SugarTable("base_real_task"), TenantAttribute("local")]
public class BaseRealTask
{
/// <summary>
/// 任务ID
/// </summary>
[SugarColumn(ColumnName = "task_id", IsPrimaryKey = true, IsIdentity = true)]
public int TaskId { get; set; }
/// <summary>
/// 关联的MES执行的计划编号
/// </summary>
[SugarColumn(ColumnName = "plan_code")]
public string PlanCode { get; set; }
/// <summary>
/// mes计划数量
/// </summary>
[SugarColumn(ColumnName = "plan_amount")]
public decimal PlanAmount { get; set; }
/// <summary>
/// mes已完成数量
/// </summary>
[SugarColumn(ColumnName = "plan_complete")]
public decimal PlanComplete { get; set; }
/// <summary>
/// 物料型号
/// </summary>
[SugarColumn(ColumnName = "material_id")]
public decimal MaterialId { get; set; }
/// <summary>
/// 任务状态默认1执行中, 2已完成
/// </summary>
[SugarColumn(ColumnName = "status")]
public int Status { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "create_time")]
public DateTime CreateTime { get; set; }
/// <summary>
/// 修改时间
/// </summary>
[SugarColumn(ColumnName = "update_time")]
public DateTime UpdateTime { get; set; }
}
}

@ -27,7 +27,7 @@ using System.Text;
#endregion << 版 本 注 释 >> #endregion << 版 本 注 释 >>
namespace SlnMesnac.Model.domain namespace SlnMesnac.Model.domain
{ {
[SugarTable("real_barCode_task"), TenantAttribute("scada")] [SugarTable("real_barcode_task"), TenantAttribute("mes")]
public class RealBarCodeTask public class RealBarCodeTask
{ {
/// <summary> /// <summary>

@ -27,7 +27,7 @@ using System.Text;
#endregion << 版 本 注 释 >> #endregion << 版 本 注 释 >>
namespace SlnMesnac.Model.domain namespace SlnMesnac.Model.domain
{ {
[SugarTable("real_pallet_task"), TenantAttribute("scada")] [SugarTable("real_pallet_task"), TenantAttribute("mes")]
public class RealPalletTask public class RealPalletTask
{ {
/// <summary> /// <summary>

@ -0,0 +1,19 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;
namespace SlnMesnac.Repository.service
{
public interface IBaseRealTaskService : IBaseService<BaseRealTask>
{
void InsertTask(BaseRealTask realTask);
void UpdateTask(BaseRealTask realTask);
void DeleteTask(int TaskId);
BaseRealTask GetExeTask();
}
}

@ -0,0 +1,69 @@
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Repository.service.Impl
* 50d84911-9088-4fd3-b85a-151411028afc
*
* WenJY
* wenjy@mesnac.com
* 2024-04-08 16:47:57
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Repository.service.Impl
{
public class BaseRealTaskServiceImpl : BaseServiceImpl<BaseRealTask>, IBaseRealTaskService
{
public BaseRealTaskServiceImpl(Repository<BaseRealTask> rep) : base(rep)
{
}
public void InsertTask(BaseRealTask realTask)
{
bool isRes = base._rep.Insert(realTask);
}
public void UpdateTask(BaseRealTask realTask)
{
bool isRes = base._rep.Update(realTask);
}
public void DeleteTask(int taskId)
{
bool isRes = base._rep.DeleteById(taskId);
}
public BaseRealTask GetExeTask()
{
BaseRealTask task = null;
task = base._rep.GetFirst(x=>x.Status ==1);
return task;
}
}
}

@ -8,29 +8,30 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"AppConfig": { "AppConfig": {
"logPath": "E:\\桌面\\京源MES项目\\程序设计\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows", "logPath": "E:\\c#\\京源环保\\程序设计\\生产控制\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows",
"stationId": 11, "stationId": 11,
"SqlConfig": [ "SqlConfig": [
{ {
"configId": "mes", "configId": "mes",
"dbType": 0, "dbType": 0,
"connStr": "Data Source=175.27.215.92;Port=3306;Initial Catalog=hwry-cloud;uid=root;pwd=haiwei@123;Charset=utf8mb4;SslMode=none" "connStr": "Data Source=172.16.12.100;Port=3306;Initial Catalog=hwjy-cloud;uid=root;pwd=JyhbRk@123456;Charset=utf8mb4;SslMode=none"
},
{
"configId": "mesTD",
"dbType": 17,
"connStr": "Host=175.27.215.92;Port=6030;Username=root;Password=taosdata;Database=db_hwmes"
}, },
{ {
"configId": "local", "configId": "local",
"dbType": 2, "dbType": 2,
"connStr": "DataSource=E:\\桌面\\京源MES项目\\程序设计\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\data\\data.db" "connStr": "DataSource=E:\\c#\\京源环保\\程序设计\\生产控制\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\data\\data.db"
},
{
"configId": "scada",
"dbType": 0,
"connStr": "Data Source=175.27.215.92;Port=3306;Initial Catalog=jy-scada;uid=root;pwd=haiwei@123;Charset=utf8mb4;SslMode=none"
} }
//{
// "configId": "mesTD",
// "dbType": 17,
// "connStr": "Host=175.27.215.92;Port=6030;Username=root;Password=taosdata;Database=db_hwmes"
//},
//{
// "configId": "scada",
// "dbType": 0,
// "connStr": "Data Source=175.27.215.92;Port=3306;Initial Catalog=jy-scada;uid=root;pwd=haiwei@123;Charset=utf8mb4;SslMode=none"
//}
], ],
"PlcConfig": [ "PlcConfig": [
{ {
@ -39,7 +40,7 @@
"plcIp": "127.0.0.1", "plcIp": "127.0.0.1",
"plcPort": 102, "plcPort": 102,
"plcKey": "plc", "plcKey": "plc",
"isFlage": false "isFlage": true
}, },
{ {
"configId": 2, //MES "configId": 2, //MES
@ -58,7 +59,7 @@
"equipKey": "test", "equipKey": "test",
"isFlage": false "isFlage": false
} }
], ]
//"redisConfig": "175.27.215.92:6379,password=redis@2023" //"redisConfig": "175.27.215.92:6379,password=redis@2023"
} }
} }

Loading…
Cancel
Save