change-最后一枪数据采集

dev
liuwf 1 year ago
parent 3630effe43
commit e6067a3805

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.Common.Helper
{
public class StringChange
{
public static string bytesToHexStr(byte[] bytes, int iLen)//e.g. { 0x01, 0x01} ---> " 01 01"
{
string returnStr = "";
if (bytes != null)
{
for (int i = 0; i < iLen; i++)
{
returnStr += bytes[i].ToString("X2");
}
}
return returnStr;
}
}
}

@ -12,8 +12,8 @@ namespace Admin.Core.Model
/// 获取发泡机最后一枪记录
/// </summary>
[SugarTable("BOX_LASTSHOTRECORD", "AUCMA_SCADA")]
public class BoxLastShotRecord
{
public class BoxLastShotRecord
{
/// <summary>
/// 主键
/// </summary>
@ -148,7 +148,7 @@ namespace Admin.Core.Model
/// 注料状态
/// </summary>
[SugarColumn(ColumnName = "INJECTIONSTATUS")]
public DateTime InjectionStatus { get; set; }
public string InjectionStatus { get; set; }
/// <summary>
/// 最后一次时间
/// </summary>
@ -159,5 +159,11 @@ namespace Admin.Core.Model
/// </summary>
[SugarColumn(ColumnName = "CREATETIME")]
public DateTime Createtime { get; set; }
/// <summary>
/// 产线
/// </summary>
[SugarColumn(ColumnName = "PRODUCT_LINE_CODE")]
public string ProductLineCode { get; set; }
}
}

@ -16,4 +16,10 @@
<ProjectReference Include="..\Aucma.Core.Scanner\Aucma.Core.Scanner.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="HwCommunication">
<HintPath>..\dll\HwCommunication.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

@ -8,6 +8,10 @@ using Admin.Core.Model;
using System.Linq;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using HwCommunication.Core;
using Admin.Core.Common.Helper;
using System.Collections;
using System.Text;
/// <summary>
/// 发泡数据采集
@ -22,27 +26,30 @@ namespace Admin.Core.Tasks
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(Job_BoxFoamData_Quartz));
private readonly IBoxFoamDataServices _boxFoamDataServices;
private readonly IOldBoxFoamDataServices _oldBoxFoamDataServices;
public Job_BoxFoamData_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,
IBoxFoamDataServices boxFoamDataServices, IOldBoxFoamDataServices oldBoxFoamDataServices)
{
_SysTasksQzService = SysTasksQzService;
_boxFoamDataServices = boxFoamDataServices;
_oldBoxFoamDataServices = oldBoxFoamDataServices;
}
public async Task Execute(IJobExecutionContext context)
{
// await ExecuteJob(context, async () => await Run(context));
// await ExecuteJob(context, async () => await BoxFoamDataRun(context));
await ExecuteJob(context, async () => await BoxFoamDataRun(context));
// await ExecuteJob(context, async () => await Run(context));
// await ExecuteJob(context, async () => await BoxFoamDataRun(context));
}
public async Task Run(IJobExecutionContext context)
{
await SaveData();
}
public async Task BoxFoamDataRun(IJobExecutionContext context)
{
await SaveOldBoxFoamData();

@ -8,6 +8,11 @@ using Admin.Core.Model;
using System.Linq;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using Admin.Core.Common.Helper;
using HwCommunication.Core;
using System.Text;
using Admin.Core.Service;
using Admin.Core.Common;
/// <summary>
/// 箱体发泡 最后一枪数据采集
@ -18,22 +23,100 @@ namespace Admin.Core.Tasks
{
public delegate Task RefreshBoxFoamDataDelegate();
public static event RefreshBoxFoamDataDelegate RefreshBoxFoamDataDelegateEvent;
/// <summary>
/// 刷新最后一枪数据
/// </summary>
public delegate void RefreshLastShotDataDelegate(BoxLastShotRecord record);
public static event RefreshLastShotDataDelegate RefreshLastShotDataDelegateEvent;
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(Job_BoxFoamData_Quartz));
private readonly IBoxFoamDataServices _boxFoamDataServices;
private readonly IOldBoxFoamDataServices _oldBoxFoamDataServices;
private readonly IBoxLastShotRecordServices _lastShotRecordServices;
private static BoxLastShotRecord tempLastRecord = null;
public Job_BoxFoamLastData_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,
IBoxFoamDataServices boxFoamDataServices, IOldBoxFoamDataServices oldBoxFoamDataServices)
IBoxFoamDataServices boxFoamDataServices, IOldBoxFoamDataServices oldBoxFoamDataServices, IBoxLastShotRecordServices boxLastShotRecordServices)
{
_SysTasksQzService = SysTasksQzService;
_boxFoamDataServices = boxFoamDataServices;
_oldBoxFoamDataServices = oldBoxFoamDataServices;
_lastShotRecordServices = boxLastShotRecordServices;
}
public async Task Execute(IJobExecutionContext context)
{
await ExecuteJob(context, async () => await Run(context));
await ExecuteJob(context, async () => await BoxFoamDataRun(context));
// await ExecuteJob(context, async () => await Run(context));
// await ExecuteJob(context, async () => await BoxFoamDataRun(context));
await ExecuteJob(context, async () => await Collect(context));
}
/// <summary>
/// 采集注料记录最近一枪
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public async Task Collect(IJobExecutionContext context)
{
await CollectLast();
}
public async Task CollectLast()
{
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("Plc1"));
if (obj != null && obj.plc.IsConnected)
{
BoxLastShotRecord lastShotRecord = new BoxLastShotRecord();
byte[] info = obj.plc.ReadBytes("DB50.900", (ushort)87);
IByteTransform byteTransform = new RegularByteTransform();
lastShotRecord.System = "1";
lastShotRecord.BoxFixtureType = "test";
lastShotRecord.GunHead = Encoding.ASCII.GetString(info.Skip(0).Take(4).ToArray());
lastShotRecord.StationNumber = StringChange.bytesToHexStr(info.Skip(4).Take(2).ToArray(), 2);
lastShotRecord.MediumPressureCycleTime = StringChange.bytesToHexStr(info.Skip(6).Take(4).ToArray(), 4);
lastShotRecord.HighPressureCycleTime = StringChange.bytesToHexStr(info.Skip(10).Take(4).ToArray(), 4);
lastShotRecord.SetInjectionWeight = StringChange.bytesToHexStr(info.Skip(14).Take(4).ToArray(), 4);
lastShotRecord.InjectionMaterialRatio = StringChange.bytesToHexStr(info.Skip(18).Take(4).ToArray(), 4);
lastShotRecord.ActualInjectionWeight = StringChange.bytesToHexStr(info.Skip(22).Take(4).ToArray(), 4);
lastShotRecord.ActualInjectionMaterialRatio = StringChange.bytesToHexStr(info.Skip(26).Take(4).ToArray(), 4);
lastShotRecord.PolInjectionpressure = StringChange.bytesToHexStr(info.Skip(30).Take(4).ToArray(), 4);
lastShotRecord.IsoInjectionpressure = StringChange.bytesToHexStr(info.Skip(34).Take(4).ToArray(), 4);
lastShotRecord.PolInjectiontemperature = StringChange.bytesToHexStr(info.Skip(38).Take(4).ToArray(), 4);
lastShotRecord.IsoInjectiontemperature = StringChange.bytesToHexStr(info.Skip(42).Take(4).ToArray(), 4);
lastShotRecord.InjecPressureOfPOLGunHead = StringChange.bytesToHexStr(info.Skip(46).Take(4).ToArray(), 4);
lastShotRecord.InjecPressureOfISOGunHead = StringChange.bytesToHexStr(info.Skip(50).Take(4).ToArray(), 4);
lastShotRecord.POLInjecTemperatureOfGunHead = StringChange.bytesToHexStr(info.Skip(54).Take(4).ToArray(), 4);
lastShotRecord.ISOInjecTemperatureOfGunHead = StringChange.bytesToHexStr(info.Skip(58).Take(4).ToArray(), 4);
lastShotRecord.POLInjecFlowRate = StringChange.bytesToHexStr(info.Skip(62).Take(4).ToArray(), 4);
lastShotRecord.ISOInjecFlowRate = StringChange.bytesToHexStr(info.Skip(66).Take(4).ToArray(), 4);
lastShotRecord.HydraulicPressure = StringChange.bytesToHexStr(info.Skip(70).Take(4).ToArray(), 4);
lastShotRecord.HydraulicTemperature = StringChange.bytesToHexStr(info.Skip(74).Take(4).ToArray(), 4);
lastShotRecord.SmallPistonFiringTime = StringChange.bytesToHexStr(info.Skip(78).Take(4).ToArray(), 4);
lastShotRecord.SmallPistonGunShutdownTime = StringChange.bytesToHexStr(info.Skip(82).Take(4).ToArray(), 4);
lastShotRecord.InjectionStatus = StringChange.bytesToHexStr(info.Skip(86).Take(1).ToArray(), 1);
lastShotRecord.LastTime = DateTime.Now;
lastShotRecord.Createtime = DateTime.Now;
lastShotRecord.ProductLineCode = "111";
if (tempLastRecord == null)
{
//数据库查
tempLastRecord = _lastShotRecordServices.Query(x=>x.System == lastShotRecord.System).OrderByDescending(x=>x.Createtime).FirstOrDefault();
}
if (!tempLastRecord.SmallPistonGunShutdownTime.Equals(lastShotRecord.SmallPistonGunShutdownTime))
{
// 刷新页面
RefreshLastShotDataDelegateEvent?.Invoke(lastShotRecord);
//保存
_lastShotRecordServices.AddAsync(lastShotRecord);
tempLastRecord = lastShotRecord;
}
}
}
public async Task Run(IJobExecutionContext context)

@ -108,7 +108,8 @@ namespace Aucma.Core.BoxFoam.Business
private static int AAA = 1;
public void init()
{
{
allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode);
foreach (var space in allSpaces)
{
@ -117,13 +118,13 @@ namespace Aucma.Core.BoxFoam.Business
Task.Run(() =>
{
Thread.Sleep(5000);
// test();
// test();
// 获取任务下发plc
StartPassDown();
// InStore("B23600083025024860011");
InStore("B23600083025024860011");
});
startTimer();
// startTimer();
}
public async void test()
@ -146,7 +147,7 @@ namespace Aucma.Core.BoxFoam.Business
/// <returns></returns>
public void RealInstoreFinish(object? sender, ElapsedEventArgs e)
{
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("泡Plc"));
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("前库Plc"));
if (obj != null && obj.plc.IsConnected)
{
foreach (SpaceAddress spaceAddress in spaceAddresses)
@ -168,13 +169,17 @@ namespace Aucma.Core.BoxFoam.Business
}
public void StartPassDown()
public async void StartPassDown()
{
while (true)
{
PassDown();
Thread.Sleep(1000);
}
Task.Run(() =>
{
while (true)
{
PassDown();
Thread.Sleep(200000);
}
});
}
@ -405,7 +410,7 @@ namespace Aucma.Core.BoxFoam.Business
public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo)
{
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("泡Plc"));
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("前库Plc"));
if (obj != null && obj.plc.IsConnected)
{
SpaceAddress spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.StoreCode, spaceInfo.SpaceCode);
@ -440,15 +445,16 @@ namespace Aucma.Core.BoxFoam.Business
try
{
SpaceAddress spaceAddress = spaceConfig.GetSpaceAddress(storeCode, taskInfo.SpaceCode);
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("泡Plc"));
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("前库Plc"));
if (obj != null && obj.plc.IsConnected)
{
//写入货道号
obj.plc.WriteInt16("DB200.0", taskInfo.SpaceCode.Substring(7,1));
//写入应答字
obj.plc.WriteInt16("DB200.2", "1");
//写入货道物料类型
obj.plc.WriteString(spaceAddress.materialType, taskInfo.MaterialType);
//写入货道号
obj.plc.WriteInt16("DB200.0", taskInfo.SpaceCode.Substring(7,1));
//写入完成后读取反馈号进行复位
ReadShellAnswer_InStore(taskInfo);
result = true;
@ -466,14 +472,14 @@ namespace Aucma.Core.BoxFoam.Business
}
/// <summary>
/// 读取泡入库应答
/// 读取泡入库应答
/// </summary>
private void ReadShellAnswer_InStore(RealTaskInfo taskInfo)
{
lock (string.Empty)
{
bool isFlag = true;
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("泡Plc"));
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("前库Plc"));
try
{
Task.Run(() =>
@ -483,17 +489,18 @@ namespace Aucma.Core.BoxFoam.Business
do
{
//读取PLC反馈号上位机清空写入的入库内容
if (obj.plc.ReadInt16("DB200.86") == 1)
if (obj.plc.ReadInt16("DB200.86") == 2)
{
obj.plc.WriteInt16("DB200.86", "0");
//-------------plc清
//写入货道号
// obj.plc.WriteString("D110", string.Empty);
//写入应答字
// obj.plc.WriteInt16("D112", "0");
obj.plc.WriteInt16("DB200.0", "0");
// 写入应答字
obj.plc.WriteInt16("DB200.2", "0");
//写入货道物料类型
// obj.plc.WriteInt16(spaceAddress.materialType, taskInfo.MaterialType);
//----------------------
obj.plc.WriteInt16("DB200.86", "0");
isFlag = false;
InStoreAnswer(taskInfo.TaskCode);
// TaskInfos.Add(taskInfo);
@ -579,7 +586,7 @@ namespace Aucma.Core.BoxFoam.Business
// lock (string.Empty)
// {
// bool isFlag = true;
// var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("泡Plc"));
// var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("前库Plc"));
// try
// {

@ -1,7 +1,9 @@
using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.ViewModels;
using Admin.Core.Service;
using Admin.Core.Tasks;
using Aucma.Core.BoxFoam.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
@ -20,9 +22,48 @@ namespace Aucma.Core.BoxFoam.ViewModels
public FoamMachinesPageViewModel()
{
Job_BoxFoamLastData_Quartz.RefreshLastShotDataDelegateEvent += RefreshData;
_boxLastShotRecordServices = App.ServiceProvider.GetService<IBoxLastShotRecordServices>();
//Task.WaitAll(LoadData());
}
public void RefreshData(BoxLastShotRecord record)
{
System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () =>
{
string system = string.Empty;
if (record.System == "1") {
system = "1系统";
PolFlow1 = record.POLInjecFlowRate;
IsoFlow1 = record.ISOInjecFlowRate;
PoleTmperature1 = record.POLInjecTemperatureOfGunHead;
IsoTemperature1 = record.ISOInjecTemperatureOfGunHead;
}
if (record.System == "2") { system = "2系统"; }
LastShotRecordDataGrid.Add(new LastShotRecordModel()
{
No = LastShotRecordDataGrid.Count+1,
System = system,
GunHead = record.GunHead,
StationNumber = record.StationNumber,
PolInjectionpressure = record.PolInjectionpressure,
IsoInjectionpressure = record.IsoInjectionpressure,
PolInjectiontemperature = record.PolInjectiontemperature,
IsoInjectiontemperature = record.IsoInjectiontemperature,
LastTime = record.LastTime,
Createtime = record.Createtime
});
}));
}
#region 加载DataGrid数据
private async Task LoadData()
{

@ -100,15 +100,15 @@
"JobGroup": "DEFAULT",
"Cron": "*/1 * * * * ?",
"AssemblyName": "Admin.Core.Tasks",
"ClassName": "Job_BoxFoamInStoreTask_Quartz",
"Remark": "入库任务监控",
"ClassName": "Job_BoxFoamLastData_Quartz",
"Remark": "最后一枪数据采集",
"RunTimes": 3881,
"BeginTime": "2023-04-23 11:08:50.000",
"EndTime": "2180-12-01 16:45:30.000",
"TriggerType": 1,
"IntervalSecond": 5,
"CycleRunTimes": 1,
"IsStart": false,
"IsStart": true,
"JobParams": null,
"DelFlag": false,
"CreateBy": "admin",
@ -186,7 +186,7 @@
"Enabled": true
},
"QuartzNetJob": {
"Enabled": false
"Enabled": true
},
"Scanner": { //
"Enabled": true
@ -197,9 +197,16 @@
}
},
"PLCServer": [
{
"Id": 1,
"EquipName": "泡前库Plc",
"PlcType": "Siemens",
"Enabled": true,
"IP": "10.10.93.41",
"Port": 102
},
{
"Id": 2,
"EquipName": "Plc1",
"PlcType": "Siemens",
"Enabled": true,

@ -119,18 +119,19 @@ namespace Aucma.Core.HwPLc
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public byte[] ReadBytes(string address)
public byte[] ReadBytes(string address,ushort len)
{
byte[] bytes = null;
try
{
OperateResult<byte[]> read = siemensS7Net.Read(address, 26);
OperateResult<byte[]> read = siemensS7Net.Read(address, len);
if (read.IsSuccess)
{
byte[] code = new byte[read.Content.Length - 2];
Array.Copy(read.Content, 2, code, 0, 24);
string scode = Encoding.ASCII.GetString(code, 0, code.Length);
bytes = code;
//Array.Copy(read.Content, 2, code, 0, 24);
//string scode = Encoding.ASCII.GetString(code, 0, code.Length);
//bytes = code;
bytes = read.Content;
}
}
catch (Exception ex)
@ -499,10 +500,6 @@ namespace Aucma.Core.HwPLc
return false;
}
public byte[] ReadBytes(string address, ushort len)
{
throw new NotImplementedException();
}
#endregion
}
}

Loading…
Cancel
Save