using Admin.Core.IService; 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) { melsecPlc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC")); do { if (melsecPlc.plc.IsConnected) { byte[] info = melsecPlc.plc.Read("D6030", 100); if (info == null) { Thread.Sleep(1000); continue; } //读取 string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim(); //int complateAmount = short.Parse(bytesToHexStr(info.Skip(40).Take(1).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); } } while (true); } } } }