using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.Model;
using Aucma.Core.HwPLc;
using Microsoft.Extensions.DependencyInjection;
using NetTaste;
using System;
using System.Linq;
using System.Text;
using System.Threading;
namespace Aucma.Core.SheetMetal.Business
{
///
/// 同步PLC处理
///
public class SyncModelHandle
{
protected readonly ISmSyncModelServices? _smSyncModelServices;
public HwPLc.PlcModel melsecPlc = null;
public SyncModelHandle() {
_smSyncModelServices = App.ServiceProvider.GetService();
}
public void SyncModelTask()
{
if (PlcHelper.melsecList!=null)
{
do
{
melsecPlc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC"));
if (melsecPlc.plc.IsConnected)
{
byte[] info = melsecPlc.plc.Read("D6030", 100);
if (info == null)
{
Thread.Sleep(1000);
continue;
}
//读取
//string model = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim();
//string productId = Encoding.ASCII.GetString(info.Skip(20).Take(20).ToArray()).Replace("\0", "").Trim();
//int complateAmount = short.Parse(bytesToHexStr(info.Skip(40).Take(1).ToArray(), 1), System.Globalization.NumberStyles.HexNumber);
//SmSyncModel syncModel = new SmSyncModel();
//SmSyncModel smSyncModel = _smSyncModelServices.FirstAsync(d => d.SmProductId == productId).Result;
//if (smSyncModel.IsNotEmptyOrNull())
//{
// _smSyncModelServices.AddAsync(model);
//}
//_smSyncModelServices.AddAsync(model);
}
} while (true);
}
}
}
}