You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.3 KiB
57 lines
2.3 KiB
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using HybirdFrameworkDriver.ModbusTcpMaster;
|
|
using Repository.Station;
|
|
using Service.Plc.Msg;
|
|
|
|
namespace Service.Plc.Client;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Scope]
|
|
public class PlcClient : ModbusTcpMaster
|
|
{
|
|
private BinInfoRepository _binInfoRepository;
|
|
|
|
public PlcClient(BinInfoRepository binInfoRepository)
|
|
{
|
|
ReadAction = BatchRead;
|
|
Ip = "172.0.20.66";
|
|
Port = 502;
|
|
Duration = 2000;
|
|
AutoReConnect = true;
|
|
_binInfoRepository = binInfoRepository;
|
|
}
|
|
|
|
private void BatchRead(ModbusTcpMaster master)
|
|
{
|
|
var bytes01 = master.BatchReadHolderRegister(1, 115);
|
|
if (bytes01 != null)
|
|
{
|
|
PlcMgr.DataValidityTime = DateTime.Now;
|
|
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData);
|
|
}
|
|
|
|
var bytes02 = master.BatchReadHolderRegister(201, 222);
|
|
if (bytes02 != null)
|
|
{
|
|
PlcMgr.DataValidityTime = DateTime.Now;
|
|
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData);
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value, it => it.No == "1");
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec02.Value, it => it.No == "2");
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec03.Value, it => it.No == "3");
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec04.Value, it => it.No == "4");
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec05.Value, it => it.No == "5");
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec06.Value, it => it.No == "6");
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec07.Value, it => it.No == "7");
|
|
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec08.Value, it => it.No == "8");
|
|
}
|
|
|
|
var bytes03 = master.BatchReadHolderRegister(701, 10);
|
|
if (bytes03 != null)
|
|
{
|
|
PlcMgr.DataValidityTime = DateTime.Now;
|
|
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData);
|
|
}
|
|
}
|
|
} |