You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 同步PLC处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SyncModelHandle
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected readonly ISmSyncModelServices? _smSyncModelServices;
|
|
|
|
|
public HwPLc.PlcModel melsecPlc = null;
|
|
|
|
|
|
|
|
|
|
public SyncModelHandle() {
|
|
|
|
|
_smSyncModelServices = App.ServiceProvider.GetService<ISmSyncModelServices>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|