diff --git a/SlnMesnac.Business/PalletStowBusiness.cs b/SlnMesnac.Business/PalletStowBusiness.cs index 3510d3c..8b5432c 100644 --- a/SlnMesnac.Business/PalletStowBusiness.cs +++ b/SlnMesnac.Business/PalletStowBusiness.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; +using System.Threading.Tasks; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -57,7 +58,9 @@ namespace SlnMesnac.Business _msInstockService = msInstockService; _realPalletTaskService = realPalletTaskService; _palletTasks = palletTasks; + } + /// /// 刷新托盘队列 @@ -69,6 +72,7 @@ namespace SlnMesnac.Business public void Init() { EmptyPalletHandle(); + } /// @@ -90,7 +94,7 @@ namespace SlnMesnac.Business continue; } - if (plc.readInt16ByAddress(GetPlcAddressByConfigKey("空托到位")) != 1) + if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("空托到位"))) { _logger.LogInformation("等待空托盘到位信号触发......"); Thread.Sleep(5000); diff --git a/SlnMesnac.Business/ProdCompletionBusiness.cs b/SlnMesnac.Business/ProdCompletionBusiness.cs index 10a1d55..b4c5b87 100644 --- a/SlnMesnac.Business/ProdCompletionBusiness.cs +++ b/SlnMesnac.Business/ProdCompletionBusiness.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using SlnMesnac.Business.@base; +using SlnMesnac.Common; using SlnMesnac.Config; using SlnMesnac.Model.domain; using SlnMesnac.Model.dto; @@ -12,6 +13,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading; +using System.Threading.Tasks; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -45,7 +47,7 @@ namespace SlnMesnac.Business private readonly IMesProductPlanService _mesProductPlanService; private readonly IRealBarCodeTaskService _barCodeTaskService; - + private readonly GunHelper gunHelper = GunHelper.Instance; private List _barCodeTasks; public ProdCompletionBusiness(ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IRealBarCodeTaskService barCodeTaskService, List barCodeTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) @@ -53,6 +55,7 @@ namespace SlnMesnac.Business _mesProductPlanService = mesProductPlanService; _barCodeTaskService = barCodeTaskService; _barCodeTasks = barCodeTasks; + } /// @@ -114,6 +117,8 @@ namespace SlnMesnac.Business } } + + RealBarCodeTask barCodeTask = new RealBarCodeTask() { BarCode = barCode, @@ -158,5 +163,17 @@ namespace SlnMesnac.Business _barCodeTaskService.RemoveBarCodeTask(barCode); 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')}"; + + //} } } diff --git a/SlnMesnac.Business/ProdMgmtBusiness.cs b/SlnMesnac.Business/ProdMgmtBusiness.cs index 981e49f..c5955ca 100644 --- a/SlnMesnac.Business/ProdMgmtBusiness.cs +++ b/SlnMesnac.Business/ProdMgmtBusiness.cs @@ -42,21 +42,25 @@ using TouchSocket.Core; namespace SlnMesnac.Business { /// - /// 设备生产管理业务类 + /// 设备生产管理业务类 -3F /// public class ProdMgmtBusiness: BaseBusiness { public readonly IMesProductPlanService _mesProductPlanService; public readonly IBasePalletInfoService _basePalletInfoService; + + public readonly IBaseRealTaskService _baseRealTaskService; private List _palletTasks; + private DebugConfig debugConfig = DebugConfig.Instance; - public ProdMgmtBusiness(ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, List palletTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) + public ProdMgmtBusiness(ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, List palletTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) { _mesProductPlanService = mesProductPlanService; _basePalletInfoService = basePalletInfoService; + _baseRealTaskService = baseRealTaskService; _palletTasks = palletTasks; } @@ -107,7 +111,7 @@ namespace SlnMesnac.Business } /// - /// 计划执行逻辑处理 + /// 计划执行,叫料逻辑处理 /// private void ProdPlanExecHandle() { @@ -120,26 +124,39 @@ namespace SlnMesnac.Business if (plc == null) { - throw new ArgumentException($"PLC连接信息为空"); + //throw new ArgumentException($"PLC连接信息为空"); + RefreshMessage($"PLC连接信息为空"); } MesProductPlan prodPlan = _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto); 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); + continue; + } + + RefreshMessage("设备要料信号触发成功"); RefreshProdPlanExecEvent?.Invoke(prodPlan); - string palletCode = GetPalletInfoByTask(); + // string palletCode = GetPalletInfoByTask(); 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())) { RefreshMessage("根据计划自动申请叫料成功"); - - plc.writeInt16ByAddress(GetPlcAddressByConfigKey("设备叫料"), 0); + #region 本地创建一个叫料任务 + 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 { @@ -158,7 +185,7 @@ namespace SlnMesnac.Business } catch (Exception e) { - _logger.LogInformation($"计划执行逻辑处理异常:{e.Message}"); + _logger.LogError($"计划执行逻辑处理异常:{e.Message}"); } Thread.Sleep(5000); } @@ -173,73 +200,111 @@ namespace SlnMesnac.Business bool result = false; while (true) { - //获取当前计划 - var prodPlan = _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto); - + //mes计划 + MesProductPlan prodPlan = null; + //本地叫料任务 + BaseRealTask localPlan = null; try { var plc = base.GetPlcByKey("plc"); - if(plc == null) + if (plc == null) { _logger.LogInformation("读取物料到位信号,PLC连接信息为空......"); Thread.Sleep(3000); continue; } - if (plc.readInt16ByAddress(GetPlcAddressByConfigKey("物料到位")) != 1) + if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("物料到位"))) { _logger.LogInformation("等待物料到位信号触发......"); Thread.Sleep(3000); continue; } - if (productPlanDto == null || prodPlan == null) + // TODO 时间校验 + bool timeCheck = JudgeProductTime(); + if (!timeCheck) { - RefreshMessage($"收到物料到位信号,未获取到正在执行的生产计划,请开始执行计划"); - plc.writeInt16ByAddress(GetPlcAddressByConfigKey("物料到位"), 0); - Thread.Sleep(3000); + RefreshMessage($"收到物料到位信号,但是距离上次投料不满20min,禁止投料"); + Thread.Sleep(1000 * 15); 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); - //获取物料托盘上的物料信息 - BasePalletInfo palletInfo = _basePalletInfoService.GetPalletInfoByPalletCode(epcStr); - if (palletInfo == null) - { - result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, "投料校验失败,未获取到托盘信息,是否继续投料"); - } - else + if (productPlanDto == null || prodPlan == null) { - if (palletInfo.MaterialId != prodPlan.MaterialId) - { - result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, "投料校验失败,物料信息不匹配,是否继续投料"); - } - else - { - result = true; - } + RefreshMessage($"收到物料到位信号,未获取到正在执行的生产计划,请开始执行计划"); + + Thread.Sleep(5000); + continue; } - 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) { _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); } @@ -291,7 +356,7 @@ namespace SlnMesnac.Business } /// - /// 申请叫料 + /// 申请叫料,TODO等待调度接口 /// /// /// @@ -310,8 +375,11 @@ namespace SlnMesnac.Business 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; } @@ -358,5 +426,45 @@ namespace SlnMesnac.Business throw new InvalidOperationException($"生产计划更新异常:{e.Message}"); } } + + + /// + /// IntervalMin) + { + return true; + } + else + { + return false; + } + + } + else + { + return true; + } + } + catch (Exception ex) + { + _logger.LogError($"距离上次投料时间合格判断异常JudgeProductTime:{ex.Message}"); + return false; + + } + } } } diff --git a/SlnMesnac.Common/GunHelper.cs b/SlnMesnac.Common/GunHelper.cs new file mode 100644 index 0000000..c7f478b --- /dev/null +++ b/SlnMesnac.Common/GunHelper.cs @@ -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 + + /// + /// 喷码设备推送 + /// + /// + /// + 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()); + } + } + + + + /// + /// 接收数据 + /// + /// + /// + 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); + } + + /// + /// 发送数据方法 + /// OK-校验成功关闭灯光,NG-校验失败闪烁红灯 + /// + /// + 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}"); + //} + + } + + /// + /// 条码根据通信协议转换 + /// + /// + /// + 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 dataList = new List(); + 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 encodedBytes = new List(); + + 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; + } + + + + + } + + +} diff --git a/SlnMesnac.Common/SlnMesnac.Common.csproj b/SlnMesnac.Common/SlnMesnac.Common.csproj index d031ec1..40b010f 100644 --- a/SlnMesnac.Common/SlnMesnac.Common.csproj +++ b/SlnMesnac.Common/SlnMesnac.Common.csproj @@ -8,6 +8,7 @@ + diff --git a/SlnMesnac.Config/DebugConfig.cs b/SlnMesnac.Config/DebugConfig.cs new file mode 100644 index 0000000..fe100b0 --- /dev/null +++ b/SlnMesnac.Config/DebugConfig.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; + +namespace SlnMesnac.Config +{ + /// + /// 系统配置 + /// + public sealed class DebugConfig + { + private static IniHelper iniHelper = new IniHelper(System.Environment.CurrentDirectory + "/config/App.InI"); + + + private static readonly Lazy lazy = new Lazy(() => new DebugConfig()); + public static DebugConfig Instance + { + get + { + return lazy.Value; + } + } + + public DebugConfig() + { + + } + + /// + ///上次投料时间 + /// + public string LastTime + { + get { return iniHelper.IniReadValue("system", "LastTime"); } + set { iniHelper.IniWriteValue("system", "LastTime", value); } + } + + + } +} diff --git a/SlnMesnac.Config/IniHelper.cs b/SlnMesnac.Config/IniHelper.cs new file mode 100644 index 0000000..489319c --- /dev/null +++ b/SlnMesnac.Config/IniHelper.cs @@ -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); + + /// + /// 写INI文件 + /// + /// + /// + /// + public void IniWriteValue(string Section, string Key, string Value) + { + + WritePrivateProfileString(Section, Key, Value, this.path); + } + + /// + /// 读取INI文件 + /// + /// + /// + /// + 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; + + } + + + /// + /// 删除ini文件下所有段落 + /// + public void ClearAllSection() + { + IniWriteValue(null, null, null); + } + /// + /// 删除ini文件下personal段落下的所有键 + /// + /// + public void ClearSection(string Section) + { + IniWriteValue(Section, null, null); + } + + public List ReadKeys(String SectionName) + { + return ReadKeys(SectionName, this.path); + } + + public List ReadKeys(string SectionName, string iniFilename) + { + List result = new List(); + 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; + } + } +} diff --git a/SlnMesnac.Model/domain/BaseRealTask.cs b/SlnMesnac.Model/domain/BaseRealTask.cs new file mode 100644 index 0000000..9184ddb --- /dev/null +++ b/SlnMesnac.Model/domain/BaseRealTask.cs @@ -0,0 +1,65 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + + + +namespace SlnMesnac.Model.domain +{ + /// + /// 当前已经下发的叫料任务 + /// + [SugarTable("base_real_task"), TenantAttribute("local")] + public class BaseRealTask + { + /// + /// 任务ID + /// + [SugarColumn(ColumnName = "task_id", IsPrimaryKey = true, IsIdentity = true)] + public int TaskId { get; set; } + + /// + /// 关联的MES执行的计划编号 + /// + [SugarColumn(ColumnName = "plan_code")] + public string PlanCode { get; set; } + + /// + /// mes计划数量 + /// + [SugarColumn(ColumnName = "plan_amount")] + public decimal PlanAmount { get; set; } + + /// + /// mes已完成数量 + /// + [SugarColumn(ColumnName = "plan_complete")] + public decimal PlanComplete { get; set; } + + + /// + /// 物料型号 + /// + [SugarColumn(ColumnName = "material_id")] + public decimal MaterialId { get; set; } + + /// + /// 任务状态:默认1执行中, 2:已完成 + /// + [SugarColumn(ColumnName = "status")] + public int Status { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "create_time")] + public DateTime CreateTime { get; set; } + + /// + /// 修改时间 + /// + [SugarColumn(ColumnName = "update_time")] + public DateTime UpdateTime { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/RealBarCodeTask.cs b/SlnMesnac.Model/domain/RealBarCodeTask.cs index 37114be..a8f48e8 100644 --- a/SlnMesnac.Model/domain/RealBarCodeTask.cs +++ b/SlnMesnac.Model/domain/RealBarCodeTask.cs @@ -27,7 +27,7 @@ using System.Text; #endregion << 版 本 注 释 >> namespace SlnMesnac.Model.domain { - [SugarTable("real_barCode_task"), TenantAttribute("scada")] + [SugarTable("real_barcode_task"), TenantAttribute("mes")] public class RealBarCodeTask { /// diff --git a/SlnMesnac.Model/domain/RealPalletTask.cs b/SlnMesnac.Model/domain/RealPalletTask.cs index ccfb03a..670b498 100644 --- a/SlnMesnac.Model/domain/RealPalletTask.cs +++ b/SlnMesnac.Model/domain/RealPalletTask.cs @@ -27,7 +27,7 @@ using System.Text; #endregion << 版 本 注 释 >> namespace SlnMesnac.Model.domain { - [SugarTable("real_pallet_task"), TenantAttribute("scada")] + [SugarTable("real_pallet_task"), TenantAttribute("mes")] public class RealPalletTask { /// diff --git a/SlnMesnac.Repository/service/IBaseRealTaskService.cs b/SlnMesnac.Repository/service/IBaseRealTaskService.cs new file mode 100644 index 0000000..c3fa9b1 --- /dev/null +++ b/SlnMesnac.Repository/service/IBaseRealTaskService.cs @@ -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 + { + void InsertTask(BaseRealTask realTask); + + void UpdateTask(BaseRealTask realTask); + + void DeleteTask(int TaskId); + + BaseRealTask GetExeTask(); + } +} diff --git a/SlnMesnac.Repository/service/Impl/BaseRealTaskServiceImpl.cs b/SlnMesnac.Repository/service/Impl/BaseRealTaskServiceImpl.cs new file mode 100644 index 0000000..98c8828 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/BaseRealTaskServiceImpl.cs @@ -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 保留所有权利。 +* CLR版本:4.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, IBaseRealTaskService + { + + public BaseRealTaskServiceImpl(Repository 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; + } + + } +} diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index b41a915..133fa30 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -8,29 +8,30 @@ }, "AllowedHosts": "*", "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, "SqlConfig": [ { "configId": "mes", "dbType": 0, - "connStr": "Data Source=175.27.215.92;Port=3306;Initial Catalog=hwry-cloud;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" + "connStr": "Data Source=172.16.12.100;Port=3306;Initial Catalog=hwjy-cloud;uid=root;pwd=JyhbRk@123456;Charset=utf8mb4;SslMode=none" }, { "configId": "local", "dbType": 2, - "connStr": "DataSource=E:\\桌面\\京源MES项目\\程序设计\\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" + "connStr": "DataSource=E:\\c#\\京源环保\\程序设计\\生产控制\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\data\\data.db" } + //{ + // "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": [ { @@ -39,7 +40,7 @@ "plcIp": "127.0.0.1", "plcPort": 102, "plcKey": "plc", - "isFlage": false + "isFlage": true }, { "configId": 2, //MES信号处理 @@ -58,7 +59,7 @@ "equipKey": "test", "isFlage": false } - ], + ] //"redisConfig": "175.27.215.92:6379,password=redis@2023" } }