可以测试

master
我叫锄头 10 months ago
parent 2e90dd3d1c
commit 87552afef2

@ -0,0 +1,61 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
[Table(Name = "Manual_Log")]
public class LjLogEntity
{
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int id { get; set; }
/// <summary>
/// 0无 1水称 2螺旋
/// </summary>
public int? devicekind { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int? deviceno { get; set; }
/// <summary>
/// 日志内容
/// </summary>
public string logtext { get; set; } = string.Empty;
/// <summary>
/// 记录时间
/// </summary>
public DateTime? logtime { get; set; }
/// <summary>
/// 操作用户名
/// </summary>
public string userid { get; set; } = string.Empty;
/// <summary>
/// 日志值
/// </summary>
public int? value { get; set; }
/// <summary>
/// 0无 1水称设定值 2水称称量值 3螺旋设定值 4螺旋称量值
/// </summary>
public int? valuekind { get; set; }
/// <summary>
/// 当前日期
/// </summary>
public string createdate { get; set; }
}

@ -0,0 +1,44 @@
using NewLife.Log;
using NewLife.Threading;
using WorkerSynReport.Plc;
namespace WorkerSynReport;
public class PclWorker:BackgroundService
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ILogger<PclWorker> _logger;
TimerX? _timer;
public PclWorker(ILogger<PclWorker> logger, IServiceScopeFactory scopeFactory)
{
_logger = logger;
this._scopeFactory = scopeFactory;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_timer ??= new TimerX(DoPlc, "", 100, 1000);
_timer.Async = true;
// while (!stoppingToken.IsCancellationRequested)
// {
//
// await Task.Delay(1000, stoppingToken);
// }
}
private void DoPlc(Object state)
{
_logger.LogInformation("{Data}",DateTime.Now.ToFullString());
//todo 备份数据库
// using var scope = _scopeFactory.CreateScope();
// var services = scope.ServiceProvider;
// ReportReadDb? readDb = services.GetService<ReportReadDb>();
//
// readDb?.ReadReport();
// readDb?.ReadFeededDry();
}
}

@ -0,0 +1,37 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class ControlSignEntity
{
public ControlSignEntity(byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107.10.0", 2);
var content = bytes.Skip(10).Take(2).ToArray();
byte byt = content[0];
AutoMode = byt.GetBit(0);
LocMode = byt.GetBit(1);
TestMode = byt.GetBit(2);
Start = byt.GetBit(3);
Pause = byt.GetBit(4);
Stop = byt.GetBit(5);
Reset = byt.GetBit(6);
AlarmAck = byt.GetBit(7);
byt = content[1];
LampTest = byt.GetBit(0);
}
public bool AutoMode { get; private set; }
public bool LocMode { get; private set; }
public bool TestMode { get; private set; }
public bool Start { get; private set; }
public bool Pause { get; private set; }
public bool Stop { get; private set; }
public bool Reset { get; private set; }
public bool AlarmAck { get; private set; }
public bool LampTest { get; private set; }
}

@ -0,0 +1,12 @@
namespace WorkerSynReport.Plc;
public class DB2106Helper : DBHelper
{
public DB2106Helper()
{
this.bytes = PlcConnect.Instance.Read("DB2106.0.0", 6440).Content;
}
public DryerReportEntity DryReport => new DryerReportEntity(bytes);
public GelReportEntity GelReport => new GelReportEntity(1864, bytes);
public WetMixingEntity WetReport => new WetMixingEntity(4360, bytes);
}

@ -0,0 +1,82 @@
namespace WorkerSynReport.Plc;
public class Db2107Helper : DBHelper
{
public Db2107Helper()
{
bytes = PlcConnect.Instance.Read("DB2107.0.0", 2064).Content;
}
// public OperateResult<byte[]> GetAll=>PlcConnect.Instance.Read("DB2107.0.0", 2057);
public NormalStatusEntity NormalStatus => NormalS(bytes);
private NormalStatusEntity NormalS(byte[] bytes)
{
return new NormalStatusEntity(bytes);
}
public ControlSignEntity ControlSign => ControlS(bytes);
private ControlSignEntity ControlS(byte[] bytes)
{
return new ControlSignEntity(bytes);
}
public PressureEntity Pressure => Press(bytes);
private PressureEntity Press(byte[] bytes)
{
return new PressureEntity(bytes);
}
public PIDEntity PID => Pid(bytes);
private PIDEntity Pid(byte[] bytes)
{
return new PIDEntity(bytes);
}
public WeightEntity Weight => Weigh(bytes);
private WeightEntity Weigh(byte[] bytes)
{
return new WeightEntity(bytes);
}
public WeightPraEntity WeightPra => WeightP(bytes);
private WeightPraEntity WeightP(byte[] bytes)
{
return new WeightPraEntity(bytes);
}
public SpeedEntity Speed => Spee(bytes);
private SpeedEntity Spee(byte[] bytes)
{
return new SpeedEntity(bytes);
}
public List<UntiStatusHMIArrayEntity> Dryer => new UntiStatusHMIArrayManager(4, 1408, 32, bytes).GetList();
public List<UntiStatusHMIArrayEntity> Gelater => new UntiStatusHMIArrayManager(8, 1536, 32, bytes).GetList();
public List<UntiStatusHMIArrayEntity> Weter => new UntiStatusHMIArrayManager(8, 1792, 32, bytes).GetList();
public ValveEntity Valve => Val(bytes);
private ValveEntity Val(byte[] bytes)
{
return new ValveEntity(bytes);
}
public LevelEntity Level => Lev(bytes);
private LevelEntity Lev(byte[] bytes)
{
return new LevelEntity(bytes);
}
}

@ -0,0 +1,48 @@
namespace WorkerSynReport.Plc;
public class DB2107WriteHelper
{
static string DbName = "DB2107";
public static void CleanSpare(int no)
{
int dian = no + 1;
var siemensS7Net = PlcConnect.Instance;
siemensS7Net.Write($"{DbName}.8.{dian}", false);
}
public static void CleanWater(int no)
{
int dian = no + 1;
var siemensS7Net = PlcConnect.Instance;
siemensS7Net.Write($"{DbName}.5.{dian}", false);
}
public static void Spare1(bool b)
{
var siemensS7Net = PlcConnect.Instance;
siemensS7Net.Write($"{DbName}.4.5", b);
}
public static void Spare2(bool b)
{
var siemensS7Net = PlcConnect.Instance;
siemensS7Net.Write($"{DbName}.4.6", b);
}
public static void Spare3(bool b)
{
var siemensS7Net = PlcConnect.Instance;
siemensS7Net.Write($"{DbName}.4.7", b);
}
public static void Spare4(bool b)
{
var siemensS7Net = PlcConnect.Instance;
siemensS7Net.Write($"{DbName}.5.0", b);
}
}

@ -0,0 +1,19 @@
namespace WorkerSynReport.Plc;
public class DB2111Helper : DBHelper
{
public DB2111Helper()
{
bytes = PlcConnect.Instance.Read("DB2111.0.0", 1682).Content;
}
public ReportDosEntity hwReport_A => new ReportDosEntity(bytes, 1506);
public ReportDosEntity hwReport_B => new ReportDosEntity(bytes, 1528);
public ReportDosEntity cwReport_A => new ReportDosEntity(bytes, 1550);
public ReportDosEntity cwReport_B => new ReportDosEntity(bytes, 1572);
public ReportDosEntity DryDosing_A => new ReportDosEntity(bytes, 1594);
public ReportDosEntity DryDosing_B => new ReportDosEntity(bytes, 1616);
public ReportDosEntity DryDosing_C => new ReportDosEntity(bytes, 1638);
public ReportDosEntity DryDosing_D => new ReportDosEntity(bytes, 1660);
}

@ -0,0 +1,20 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class DBHelper
{
public byte[] bytes;
public DBHelper(byte[] bytes)
{
this.bytes = bytes;
}
public DBHelper() { }
public bool ReadBitBySet(int word, int bit)
{
return bytes[word].GetBit(bit);
}
}

@ -0,0 +1,169 @@
namespace WorkerSynReport.Plc;
public class DryerReportEntity
{
byte[] Bytes;
public DryerReportEntity( byte[] bytes)
{
this.Bytes = bytes;
}
public Dryer_ Dryer_A => new Dryer_(0, Bytes);
public Dryer_ Dryer_B => new Dryer_(466, Bytes);
public Dryer_ Dryer_C => new Dryer_(932, Bytes);
public Dryer_ Dryer_D => new Dryer_(1398, Bytes);
}
public class Dryer_
{
private byte[] Bytes;
int start;
int mixStart;
public Dryer_(int start, byte[] bytes)
{
this.start = start;
mixStart = start + 286;
this.Bytes = bytes;
}
public List<Report_DosE> Dos
{
get
{
List<Report_DosE> ListE = new List<Report_DosE>();
var content = Bytes.Skip(start).Take(286).ToArray();
for (int i = 0; i < 13; i++)
{
var singleBlock = content.Skip(i*22).Take(22).ToArray();
ListE.Add(new Report_DosE(singleBlock));
}
return ListE;
}
}
public List<Report_MixE> Mix
{
get
{
List<Report_MixE> ListE = new List<Report_MixE>();
var content = Bytes.Skip(mixStart).Take(180).ToArray();
for (int i = 0; i < 10; i++)
{
var singleBlock = content.Skip(i * 18).Take(18).ToArray();
ListE.Add(new Report_MixE(singleBlock));
}
return ListE;
}
}
}
public class Report_DosE
{
public Report_DosE(byte[] content)
{
EqNo = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
Batch = PlcConnect.Instance.ByteTransform.TransInt16(content, 2);
MatCode = PlcConnect.Instance.ByteTransform.TransInt16(content, 4);
SetValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 6);
SetToler = PlcConnect.Instance.ByteTransform.TransSingle(content, 10);
ActValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 14);
ActToler = PlcConnect.Instance.ByteTransform.TransSingle(content, 18);
}
public Report_DosE(ushort startSet, byte[] bytes)
{
//var read = PlcConnect.Instance.Read("DB2107." + startSet + ".0", 22);
var content = bytes.Skip(startSet).Take(22).ToArray();
EqNo = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
Batch = PlcConnect.Instance.ByteTransform.TransInt16(content, 2);
MatCode = PlcConnect.Instance.ByteTransform.TransInt16(content, 4);
SetValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 6);
SetToler = PlcConnect.Instance.ByteTransform.TransSingle(content, 10);
ActValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 14);
ActToler = PlcConnect.Instance.ByteTransform.TransSingle(content, 18);
}
public short EqNo { get; private set; }
public short Batch { get; private set; }
public short MatCode { get; private set; }
public float SetValue { get; private set; }
public float SetToler { get; private set; }
public float ActValue { get; private set; }
public float ActToler { get; private set; }
}
public class Report_MixE
{
public Report_MixE(byte[] content)
{
EqNo = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
MixBatch = PlcConnect.Instance.ByteTransform.TransInt16(content, 2);
MixStep = PlcConnect.Instance.ByteTransform.TransInt16(content, 4);
ActCode = PlcConnect.Instance.ByteTransform.TransInt16(content, 6);
MixTime = PlcConnect.Instance.ByteTransform.TransInt16(content, 8);
MixTemp = PlcConnect.Instance.ByteTransform.TransSingle(content, 10);
MixSpeed = PlcConnect.Instance.ByteTransform.TransSingle(content, 14);
}
public short EqNo { get; private set; }
public short MixBatch { get; private set; }
public short MixStep { get; private set; }
public short ActCode { get; private set; }
public short MixTime { get; private set; }
public float MixTemp { get; private set; }
public float MixSpeed { get; private set; }
}
public class ReportArrayManager
{
private int Length;
private int StartSet;
private int SLength;
private byte[] Bytes;
public ReportArrayManager(ushort length, int startSet, int sLength, byte[] bytes)
{
Length = length;
StartSet = startSet;
SLength = sLength;
Bytes = bytes;
}
public List<Report_MixE> GetReport_MixEList()
{
List<Report_MixE> ListE = new List<Report_MixE>();
//var getListE = PlcConnect.Instance.Read("DB2106." + StartSet + ".0", Convert.ToUInt16(Length * SLength));
var content = Bytes.Skip(StartSet).Take(Length * SLength).ToArray();
for (int i = 0; i < Length; i++)
{
var singleBlock = content.Skip(SLength * i).Take(SLength).ToArray();
ListE.Add(new Report_MixE(singleBlock));
}
return ListE;
}
public List<Report_DosE> GetReport_DosEList()
{
List<Report_DosE> ListE = new List<Report_DosE>(Length);
//var getListE = PlcConnect.Instance.Read("DB2106." + StartSet + ".0", Convert.ToUInt16(Length * SLength));
var content = Bytes.Skip(StartSet).Take(Length * SLength).ToArray();
for (int i = 0; i < Length; i++)
{
var singleBlock = content.Skip(SLength * i).Take(SLength).ToArray();
ListE.Add(new Report_DosE(singleBlock));
}
return ListE;
}
}

@ -0,0 +1,36 @@
namespace WorkerSynReport.Plc;
public class GelReportEntity
{
private int StartSet;
private byte[] bytes;
public GelReportEntity(int startSet, byte[] bytes)
{
this.StartSet = startSet;
this.bytes = bytes;
}
public Gel_ Gel_A => new Gel_(StartSet, bytes);
public Gel_ Gel_B => new Gel_(StartSet + 312, bytes);
public Gel_ Gel_C => new Gel_(StartSet + 624, bytes);
public Gel_ Gel_D => new Gel_(StartSet + 936, bytes);
public Gel_ Gel_E => new Gel_(StartSet + 1248, bytes);
public Gel_ Gel_F => new Gel_(StartSet + 1560, bytes);
public Gel_ Gel_G => new Gel_(StartSet + 1872, bytes);
public Gel_ Gel_H => new Gel_(StartSet + 2184, bytes);
}
public class Gel_
{
private int StartSet;
private byte[] bytes;
public Gel_(int startSet, byte[] bytes)
{
this.StartSet = startSet;
this.bytes = bytes;
}
public List<Report_DosE> GelDosing => new ReportArrayManager(4, StartSet, 22, bytes).GetReport_DosEList();
public Report_DosE HotWater => new Report_DosE(Convert.ToUInt16(StartSet + 88), bytes);
public Report_DosE CoolWater => new Report_DosE(Convert.ToUInt16(StartSet + 110), bytes);
public List<Report_MixE> GelMixing => new ReportArrayManager(10, StartSet + 132, 18, bytes).GetReport_MixEList();
}

@ -0,0 +1,73 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class LevelEntity
{
public LevelEntity(byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107.2060.0", 3);
var content = bytes.Skip(2060).Take(3).ToArray();
byte byt = content[0];
LowLevel_D1 = byt.GetBit(0);
HighLevel_D1 = byt.GetBit(1);
LowLevel_D2 = byt.GetBit(2);
HighLevel_D2 = byt.GetBit(3);
LowLevel_D3 = byt.GetBit(4);
HighLevel_D3 = byt.GetBit(5);
LowLevel_D4 = byt.GetBit(6);
HighLevel_D4 = byt.GetBit(7);
byt = content[1];
LowLevel_D5 = byt.GetBit(0);
HighLevel_D5 = byt.GetBit(1);
LowLevel_D6 = byt.GetBit(2);
HighLevel_D6 = byt.GetBit(3);
LowLevel_D7 = byt.GetBit(4);
HighLevel_D7 = byt.GetBit(5);
LowLevel_D8 = byt.GetBit(6);
HighLevel_D8 = byt.GetBit(7);
byt = content[2];
LowLevel_D9 = byt.GetBit(0);
HighLevel_D9 = byt.GetBit(1);
LowLevel_D10 = byt.GetBit(2);
HighLevel_D10 = byt.GetBit(3);
LowLevel_D11 = byt.GetBit(4);
HighLevel_D11 = byt.GetBit(5);
LowLevel_D12 = byt.GetBit(6);
HighLevel_D12 = byt.GetBit(7);
}
public bool LowLevel_D1 { get; private set; }
public bool HighLevel_D1 { get; private set; }
public bool LowLevel_D2 { get; private set; }
public bool HighLevel_D2 { get; private set; }
public bool LowLevel_D3 { get; private set; }
public bool HighLevel_D3 { get; private set; }
public bool LowLevel_D4 { get; private set; }
public bool HighLevel_D4 { get; private set; }
public bool LowLevel_D5 { get; private set; }
public bool HighLevel_D5 { get; private set; }
public bool LowLevel_D6 { get; private set; }
public bool HighLevel_D6 { get; private set; }
public bool LowLevel_D7 { get; private set; }
public bool HighLevel_D7 { get; private set; }
public bool LowLevel_D8 { get; private set; }
public bool HighLevel_D8 { get; private set; }
public bool LowLevel_D9 { get; private set; }
public bool HighLevel_D9 { get; private set; }
public bool LowLevel_D10 { get; private set; }
public bool HighLevel_D10 { get; private set; }
public bool LowLevel_D11 { get; private set; }
public bool HighLevel_D11 { get; private set; }
public bool LowLevel_D12 { get; private set; }
public bool HighLevel_D12 { get; private set; }
}

@ -0,0 +1,147 @@
using System.Data;
using Chloe;
using WorkerSynReport.Data;
namespace WorkerSynReport.Plc;
/// <summary>
/// 配料日志
/// </summary>
public class LjLogControl
{
private IDbContextLocal _dbContext;
public LjLogControl(IDbContextLocal dbContext)
{
_dbContext = dbContext;
}
/// <summary>
/// 通过内容查询日志
/// </summary>
/// <param name="txt">查询关键字</param>
public DataTable ManualLogSelect(string txt)
{
string sql;
if (!string.IsNullOrEmpty(txt))
{
sql = BaseSelect($"where logtext like '%{txt}%'");
}
else
{
sql = BaseSelect("");
}
return _dbContext.Session.ExecuteDataTable(sql);
}
/// <summary>
/// 通过内容和机台号查询日志
/// </summary>
/// <param name="txt">查询关键字</param>
public DataTable ManualLogSelect(string txt, int deviceNo)
{
string sql;
if (deviceNo == 0)
{
return ManualLogSelect(txt);
}
else
{
sql = BaseSelect($"where deviceNo = {deviceNo} and logtext like '%{txt}%'");
return _dbContext.Session.ExecuteDataTable(sql);
}
}
/// <summary>
/// 通过时间查询日志
/// </summary>
/// <param name="txt">查询关键字</param>
public DataTable ManualLogSelect(string startTime, string endTime)
{
string sql = BaseSelect($"where logtime BETWEEN '{startTime}' AND '{endTime}'");
return _dbContext.Session.ExecuteDataTable(sql);
}
private static string BaseSelect(string sql)
{
string s = "select top 500 id, logtext, logtime, value, deviceno from Manual_Log " + sql +
" order by id desc";
return s;
}
/// <summary>
/// 完整手动日志插入
/// </summary>
/// <param name="logName">日志内容</param>
/// <param name="value">值</param>
/// <param name="valuekind">值类型 0无 1水称设定值 2水称称量值 3螺旋设定值 4螺旋称量值</param>
/// <param name="deviceno">设备编号</param>
/// <param name="devicekind">设备类型 0无 1水称 2螺旋湿混 3糊化 4干混</param>
public void ManualLogControl(string logName, int value, int valuekind, int deviceno, int devicekind)
{
var Log = new LjLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = "Admin",
value = value,
deviceno = deviceno,
devicekind = devicekind,
valuekind = valuekind,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
_dbContext.Save(Log);
}
/// <summary>
/// 无数值 有设备 日志记录
/// </summary>
/// <param name="logName">日志内容</param>
/// <param name="deviceno">设备编号</param>
/// <param name="devicekind">设备类型</param>
public void ManualLogControl(string logName, int deviceno, int devicekind)
{
var Log = new LjLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = "Admin",
value = 0,
deviceno = deviceno,
devicekind = devicekind,
valuekind = 0,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
_dbContext.Save(Log);
}
/// <summary>
/// 无数值 无设备 日志记录
/// </summary>
/// <param name="logName"></param>
public void ManualLogControl(string logName)
{
var Log = new LjLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = "Admin",
value = 0,
deviceno = 0,
devicekind = 0,
valuekind = 0,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
_dbContext.Save(Log);
}
}

@ -0,0 +1,112 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class NormalStatusEntity
{
public NormalStatusEntity(byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107.2.0", 7);
var content = bytes.Skip(2).Take(7).ToArray();
WatchDog = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
byte byt = content[2];
RecipeRun = byt.GetBit(0);
RecipePause = byt.GetBit(1);
Ready = byt.GetBit(2);
Alarm = byt.GetBit(3);
EMStop = byt.GetBit(4);
RdyRpt_V1 = byt.GetBit(5);
RdyRpt_V2 = byt.GetBit(6);
RdyRpt_V3 = byt.GetBit(7);
byt = content[3];
RdyRpt_V4 = byt.GetBit(0);
RdyRpt_V5 = byt.GetBit(1);
RdyRpt_W1 = byt.GetBit(2);
RdyRpt_W2 = byt.GetBit(3);
RdyRpt_W3 = byt.GetBit(4);
RdyRpt_W4 = byt.GetBit(5);
RdyRpt_D1 = byt.GetBit(6);
RdyRpt_D2 = byt.GetBit(7);
byt = content[4];
RdyRpt_D3 = byt.GetBit(0);
RdyRpt_D4 = byt.GetBit(1);
RdyRpt_G1 = byt.GetBit(2);
RdyRpt_G2 = byt.GetBit(3);
RdyRpt_G3 = byt.GetBit(4);
RdyRpt_G4 = byt.GetBit(5);
RdyRpt_G5 = byt.GetBit(6);
RdyRpt_G6 = byt.GetBit(7);
byt = content[5];
RdyRpt_G7 = byt.GetBit(0);
RdyRpt_G8 = byt.GetBit(1);
RdyRpt_M1 = byt.GetBit(2);
RdyRpt_M2 = byt.GetBit(3);
RdyRpt_M3 = byt.GetBit(4);
RdyRpt_M4 = byt.GetBit(5);
RdyRpt_M5 = byt.GetBit(6);
RdyRpt_M6 = byt.GetBit(7);
byt = content[6];
RdyRpt_M7 = byt.GetBit(0);
RdyRpt_M8 = byt.GetBit(1);
spare1= byt.GetBit(2);
spare2 = byt.GetBit(3);
spare3 = byt.GetBit(4);
spare4 = byt.GetBit(5);
}
public int WatchDog { get; private set; }
public bool RecipeRun { get; private set; }
public bool RecipePause { get; private set; }
public bool Ready { get; private set; }
public bool Alarm { get; private set; }
public bool EMStop { get; private set; }
public bool RdyRpt_V1 { get; private set; }
public bool RdyRpt_V2 { get; private set; }
public bool RdyRpt_V3 { get; private set; }
public bool RdyRpt_V4 { get; private set; }
public bool RdyRpt_V5 { get; private set; }
public bool RdyRpt_W1 { get; private set; }
public bool RdyRpt_W2 { get; private set; }
public bool RdyRpt_W3 { get; private set; }
public bool RdyRpt_W4 { get; private set; }
public bool RdyRpt_D1 { get; private set; }
public bool RdyRpt_D2 { get; private set; }
public bool RdyRpt_D3 { get; private set; }
public bool RdyRpt_D4 { get; private set; }
public bool RdyRpt_G1 { get; private set; }
public bool RdyRpt_G2 { get; private set; }
public bool RdyRpt_G3 { get; private set; }
public bool RdyRpt_G4 { get; private set; }
public bool RdyRpt_G5 { get; private set; }
public bool RdyRpt_G6 { get; private set; }
public bool RdyRpt_G7 { get; private set; }
public bool RdyRpt_G8 { get; private set; }
public bool RdyRpt_M1 { get; private set; }
public bool RdyRpt_M2 { get; private set; }
public bool RdyRpt_M3 { get; private set; }
public bool RdyRpt_M4 { get; private set; }
public bool RdyRpt_M5 { get; private set; }
public bool RdyRpt_M6 { get; private set; }
public bool RdyRpt_M7 { get; private set; }
public bool RdyRpt_M8 { get; private set; }
public bool spare1 { get; private set; }
public bool spare2 { get; private set; }
public bool spare3 { get; private set; }
public bool spare4 { get; private set; }
}

@ -0,0 +1,39 @@
namespace WorkerSynReport.Plc;
public class PIDEntity
{
byte[] bytes;
public PIDEntity(byte[] bytes)
{
this.bytes = bytes;
}
public PID_HMI Convey_V1 => new PID_HMI(614, bytes);
public PID_HMI Purge_V1 => new PID_HMI(622, bytes);
public PID_HMI Convey_V2 => new PID_HMI(630, bytes);
public PID_HMI Purge_V2 => new PID_HMI(638, bytes);
public PID_HMI Convey_V3 => new PID_HMI(646, bytes);
public PID_HMI Purge_V3 => new PID_HMI(654, bytes);
public PID_HMI Convey_V4 => new PID_HMI(662, bytes);
public PID_HMI Purge_V4 => new PID_HMI(670, bytes);
public PID_HMI Convey_V5 => new PID_HMI(678, bytes);
public PID_HMI Purge_V5 => new PID_HMI(686, bytes);
}
public class PID_HMI
{
public PID_HMI(ushort startSet, byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107." + startSet + ".0", 8);
var content = bytes.Skip(startSet).Take(8).ToArray();
PV = PlcConnect.Instance.ByteTransform.TransSingle(content, 0);
SV = PlcConnect.Instance.ByteTransform.TransSingle(content, 4);
}
public float PV { get; private set; }
public float SV { get; private set; }
}

@ -0,0 +1,73 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class PressureEntity
{
byte[] bytes;
public PressureEntity(byte[] bytes)
{
this.bytes = bytes;
}
public Pressure_HMI MainPress_V1 => new Pressure_HMI(12, bytes);
public Pressure_HMI TopPressure_V1 => new Pressure_HMI(26, bytes);
public Pressure_HMI LinePressure_V1 => new Pressure_HMI(40, bytes);
public Pressure_HMI MainPress_V2 => new Pressure_HMI(54, bytes);
public Pressure_HMI TopPressure_V2 => new Pressure_HMI(68, bytes);
public Pressure_HMI LinePressure_V2 => new Pressure_HMI(82, bytes);
public Pressure_HMI MainPress_V3 => new Pressure_HMI(96, bytes);
public Pressure_HMI TopPressure_V3 => new Pressure_HMI(110, bytes);
public Pressure_HMI LinePressure_V3 => new Pressure_HMI(124, bytes);
public Pressure_HMI MainPress_V4 => new Pressure_HMI(138, bytes);
public Pressure_HMI TopPressure_V4 => new Pressure_HMI(152, bytes);
public Pressure_HMI LinePressure_V4 => new Pressure_HMI(166, bytes);
public Pressure_HMI MainPress_V5 => new Pressure_HMI(180, bytes);
public Pressure_HMI TopPressure_V5 => new Pressure_HMI(194, bytes);
public Pressure_HMI LinePressure_V5 => new Pressure_HMI(208, bytes);
public Pressure_HMI PressDaybin_B1 => new Pressure_HMI(222, bytes);
public Pressure_HMI PressDaybin_B2 => new Pressure_HMI(236, bytes);
public Pressure_HMI PressDaybin_B3 => new Pressure_HMI(250, bytes);
public Pressure_HMI PressDaybin_B4 => new Pressure_HMI(264, bytes);
public Pressure_HMI PressDaybin_B5 => new Pressure_HMI(278, bytes);
public Pressure_HMI PressDaybin_B6 => new Pressure_HMI(292, bytes);
public Pressure_HMI PressDaybin_B7 => new Pressure_HMI(306, bytes);
public Pressure_HMI PressDaybin_B8 => new Pressure_HMI(320, bytes);
public Pressure_HMI PressDaybin_B9 => new Pressure_HMI(334, bytes);
public Pressure_HMI PressDaybin_B10 => new Pressure_HMI(348, bytes);
public Pressure_HMI PressDaybin_B11 => new Pressure_HMI(362, bytes);
public Pressure_HMI PressDaybin_B12 => new Pressure_HMI(376, bytes);
public Pressure_HMI PR2PCP01 => new Pressure_HMI(390, bytes);
public Pressure_HMI PR2PCP02 => new Pressure_HMI(404, bytes);
public Pressure_HMI PR2PCP03 => new Pressure_HMI(418, bytes);
}
public class Pressure_HMI
{
public Pressure_HMI(ushort startSet, byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107." + startSet + ".0", 14);
var content = bytes.Skip(startSet).Take(14).ToArray();
ActualValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 0);
LowLimit = PlcConnect.Instance.ByteTransform.TransSingle(content, 4);
HighLimit = PlcConnect.Instance.ByteTransform.TransSingle(content, 8);
var operateResult = PlcConnect.Instance.ReadFloat("Db2107.20.0");
byte byt = content[12];
Alarm = byt.GetBit(0);
}
public float ActualValue { get; private set; }
public float LowLimit { get; private set; }
public float HighLimit { get; private set; }
public bool Alarm { get; private set; }
}

@ -0,0 +1,28 @@
namespace WorkerSynReport.Plc;
public class ReportDosEntity
{
public ReportDosEntity(byte[] bytes, int StartSet)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107.10.0", 2);
var content = bytes.Skip(StartSet).Take(22).ToArray();
eqNo = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
batch = PlcConnect.Instance.ByteTransform.TransInt16(content, 2);
matCode = PlcConnect.Instance.ByteTransform.TransInt16(content, 4);
setValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 6);
setToler = PlcConnect.Instance.ByteTransform.TransSingle(content, 10);
actValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 14);
actToler = PlcConnect.Instance.ByteTransform.TransSingle(content, 18);
}
public short eqNo { get; private set; }
public short batch { get; private set; }
public short matCode { get; private set; }
public float setValue { get; private set; }
public float setToler { get; private set; }
public float actValue { get; private set; }
public float actToler { get; private set; }
}

@ -0,0 +1,598 @@
using WorkerSynReport.Data;
namespace WorkerSynReport.Plc;
public class ReportReadDb
{
private IDbContextLocal _dbContext;
private LjLogControl _logControl;
public ReportReadDb(IDbContextLocal dbContext)
{
_dbContext = dbContext;
_logControl = new LjLogControl(_dbContext);
}
/// <summary>
/// 干混料插入日志
/// </summary>
public void ReadFeededDry()
{
Db2107Helper dB2107Helper = new Db2107Helper();
var nornalStatus = dB2107Helper.NormalStatus;
DB2111Helper dB2111Helper = new DB2111Helper();
//黑粉准备好信号
if (nornalStatus.spare1)
{
FeededDry(1, dB2111Helper.DryDosing_A);
DB2107WriteHelper.CleanSpare(1);
}
if (nornalStatus.spare2)
{
FeededDry(2, dB2111Helper.DryDosing_B);
DB2107WriteHelper.CleanSpare(2);
}
if (nornalStatus.spare3)
{
FeededDry(3, dB2111Helper.DryDosing_C);
DB2107WriteHelper.CleanSpare(3);
}
if (nornalStatus.spare4)
{
FeededDry(4, dB2111Helper.DryDosing_D);
DB2107WriteHelper.CleanSpare(4);
}
///热水秤A
if (nornalStatus.RdyRpt_W1)
{
FeededWaterHA(dB2111Helper.hwReport_A);
}
///冷水秤A
if (nornalStatus.RdyRpt_W2)
{
FeededWaterCA(dB2111Helper.cwReport_A);
}
//热水B
if (nornalStatus.RdyRpt_W3)
{
FeededWaterHB(dB2111Helper.hwReport_B);
}
///冷水秤B
if (nornalStatus.RdyRpt_W4)
{
FeededWaterCB(dB2111Helper.cwReport_B);
}
}
//热水A
private void FeededWaterHA(ReportDosEntity entity)
{
var actValue = Convert.ToInt32(entity.actValue);
string logName = $"热水秤A向 [{entity.eqNo}] 加水 {actValue}";
_logControl.ManualLogControl(logName, actValue, 2, entity.eqNo, 1);
DB2107WriteHelper.CleanWater(1);
}
private void FeededWaterCA(ReportDosEntity entity)
{
var actValue = Convert.ToInt32(entity.actValue);
string logName = $"冷水秤A向 [{entity.eqNo}] 加水 {actValue}";
_logControl.ManualLogControl(logName, actValue, 2, entity.eqNo, 1);
DB2107WriteHelper.CleanWater(2);
}
private void FeededWaterHB(ReportDosEntity entity)
{
var actValue = Convert.ToInt32(entity.actValue);
string logName = $"热水秤B向 [{entity.eqNo+4}] 加水 {actValue}";
_logControl.ManualLogControl(logName, actValue, 2, entity.eqNo+4, 1);
DB2107WriteHelper.CleanWater(3);
}
private void FeededWaterCB(ReportDosEntity entity)
{
var actValue = Convert.ToInt32(entity.actValue);
string logName = $"冷水秤B向 [{entity.eqNo + 4}] 加水 {actValue}";
_logControl.ManualLogControl(logName, actValue, 2, entity.eqNo + 4, 1);
DB2107WriteHelper.CleanWater(4);
}
/// <summary>
/// 解决算法有问题
/// </summary>
/// <param name="deviceno"></param>
/// <param name="entity"></param>
private void FeededDry(int deviceno, ReportDosEntity entity)
{
int no = deviceno * 2;
if (entity.eqNo == 1)
{
no = no - 1;
}
var actValue = Convert.ToInt32(entity.actValue);
string logName = $"用户[Admin] 螺旋{deviceno}向湿混机 [{no}] 投料 {actValue}";
_logControl.ManualLogControl(logName, actValue, 4, no, 2);
}
public void ReadReport()
{
Db2107Helper dB2107Helper = new Db2107Helper();
NormalStatusEntity normal = dB2107Helper.NormalStatus;
if (normal.RdyRpt_D1)
{
InsertD(1);
PlcConnect.Instance.Write("DB2107.5.6", false);
}
if (normal.RdyRpt_D2)
{
InsertD(2);
PlcConnect.Instance.Write("DB2107.5.7", false);
}
if (normal.RdyRpt_D3)
{
InsertD(3);
PlcConnect.Instance.Write("DB2107.6.0", false);
}
if (normal.RdyRpt_D4)
{
InsertD(4);
PlcConnect.Instance.Write("DB2107.6.1", false);
}
if (normal.RdyRpt_G1)
{
InsertG(1);
PlcConnect.Instance.Write("DB2107.6.2", false);
}
if (normal.RdyRpt_G2)
{
InsertG(2);
PlcConnect.Instance.Write("DB2107.6.3", false);
}
if (normal.RdyRpt_G3)
{
InsertG(3);
PlcConnect.Instance.Write("DB2107.6.4", false);
}
if (normal.RdyRpt_G4)
{
InsertG(4);
PlcConnect.Instance.Write("DB2107.6.5", false);
}
if (normal.RdyRpt_G5)
{
InsertG(5);
PlcConnect.Instance.Write("DB2107.6.6", false);
}
if (normal.RdyRpt_G6)
{
InsertG(6);
PlcConnect.Instance.Write("DB2107.6.7", false);
}
if (normal.RdyRpt_G7)
{
InsertG(7);
PlcConnect.Instance.Write("DB2107.7.0", false);
}
if (normal.RdyRpt_G8)
{
InsertG(8);
PlcConnect.Instance.Write("DB2107.7.1", false);
}
if (normal.RdyRpt_M1)
{
InsertM(1);
PlcConnect.Instance.Write("DB2107.7.2", false);
}
if (normal.RdyRpt_M2)
{
InsertM(2);
PlcConnect.Instance.Write("DB2107.7.3", false);
}
if (normal.RdyRpt_M3)
{
InsertM(3);
PlcConnect.Instance.Write("DB2107.7.4", false);
}
if (normal.RdyRpt_M4)
{
InsertM(4);
PlcConnect.Instance.Write("DB2107.7.5", false);
}
if (normal.RdyRpt_M5)
{
InsertM(5);
PlcConnect.Instance.Write("DB2107.7.6", false);
}
if (normal.RdyRpt_M6)
{
InsertM(6);
PlcConnect.Instance.Write("DB2107.7.7", false);
}
if (normal.RdyRpt_M7)
{
InsertM(7);
PlcConnect.Instance.Write("DB2107.8.0", false);
}
if (normal.RdyRpt_M8)
{
InsertM(8);
PlcConnect.Instance.Write("DB2107.8.1", false);
}
}
private void InsertD(int no)
{
DB2106Helper dB2106 = new DB2106Helper();
Dryer_ dryer = null;
switch (no)
{
case 1:
dryer = dB2106.DryReport.Dryer_A;
break;
case 2:
dryer = dB2106.DryReport.Dryer_B;
break;
case 3:
dryer = dB2106.DryReport.Dryer_C;
break;
case 4:
dryer = dB2106.DryReport.Dryer_D;
break;
}
Report_Dry dry = new Report_Dry();
List<Report_DryDos_Detail> lsDos = new List<Report_DryDos_Detail>();
List<Report_DryMixer_Detail> lsMix = new List<Report_DryMixer_Detail>();
dry.reportId = Guid.NewGuid().ToString("N");
dry.recipeCode = 0;
dry.recipeName = "";
dry.planCode = 0;
dry.planName = "";
dry.recordTime = DateTime.Now;
dry.dryNo = no;
dry.Batch = 0;
foreach (var item in dryer.Dos)
{
if (item.EqNo != 0)
{
lsDos.Add(new Report_DryDos_Detail()
{
reportId = dry.reportId,
eqNo = item.EqNo,
batch = item.Batch,
matCode = item.MatCode,
setToler = item.SetToler,
setValue = item.SetValue,
actToler = item.ActToler,
actValue = item.ActValue,
recordTime = DateTime.Now
});
}
}
foreach (var item in dryer.Mix)
{
if (item.EqNo != 0)
{
lsMix.Add(new Report_DryMixer_Detail()
{
reportId = dry.reportId,
actCode = item.ActCode,
eqNo = item.EqNo,
mixBatch = item.MixBatch,
mixStep = item.MixStep,
mixSpeed = item.MixSpeed,
mixTemp = item.MixTemp,
mixTime = item.MixTime,
recordTime = DateTime.Now
}) ;
}
}
if (lsDos.Any())
{
dry.Batch=lsDos.Where(x=>x.batch>0).Select(x=>x.batch).First();
_dbContext.Insert(dry);
_dbContext.InsertRange(lsDos);
_dbContext.InsertRange(lsMix);
// FreeSqlUnit.Instance.Insert(dry).ExecuteAffrows();
// FreeSqlUnit.Instance.Insert(lsDos).ExecuteAffrows();
// FreeSqlUnit.Instance.Insert(lsMix).ExecuteAffrows();
}
}
private void InsertG(int no)
{
DB2106Helper dB2106 = new DB2106Helper();
Gel_ gel = null;
switch (no)
{
case 1:
gel = dB2106.GelReport.Gel_A;
break;
case 2:
gel = dB2106.GelReport.Gel_B;
break;
case 3:
gel = dB2106.GelReport.Gel_C;
break;
case 4:
gel = dB2106.GelReport.Gel_D;
break;
case 5:
gel = dB2106.GelReport.Gel_E;
break;
case 6:
gel = dB2106.GelReport.Gel_F;
break;
case 7:
gel = dB2106.GelReport.Gel_G;
break;
case 8:
gel = dB2106.GelReport.Gel_H;
break;
}
Report_Gel gelDb = new Report_Gel();
gelDb.reportId = Guid.NewGuid().ToString("N");
gelDb.recipeCode = 0;
gelDb.recipeName = "";
gelDb.planCode = 0;
gelDb.planName = "";
gelDb.recordTime = DateTime.Now;
gelDb.gelNo = no;
gelDb.Batch = 0;
List<Report_GelDoser_Detail> lsdetail = new List<Report_GelDoser_Detail>();
List<Report_GelMixing_Detail> lsMixing = new List<Report_GelMixing_Detail>();
var dosList = gel.GelDosing;
foreach (var dos in dosList)
{
if (dos.EqNo != 0)
{
lsdetail.Add(new Report_GelDoser_Detail()
{
eqNo = dos.EqNo,
batch = dos.Batch,
matCode = dos.MatCode,
setValue = dos.SetValue,
setToler = dos.SetToler,
actToLer = dos.ActToler,
actValue = dos.ActValue,
reportId = gelDb.reportId,
recordTime = DateTime.Now,
kinds = 1
});
}
else
{
break;
}
}
var mixList = gel.GelMixing;
foreach (var mix in mixList)
{
if (mix.EqNo != 0)
{
lsMixing.Add(new Report_GelMixing_Detail()
{
eqNo = mix.EqNo,
mixBatch = mix.MixBatch,
mixStep = mix.MixStep,
actCode = mix.ActCode,
mixTime = mix.MixTime,
mixSpeed = mix.MixSpeed,
mixTemp = mix.MixTemp,
reportId = gelDb.reportId,
recordTime = DateTime.Now,
});
}
}
var hotWater = gel.HotWater;
if (hotWater != null)
{
lsdetail.Add(new Report_GelDoser_Detail()
{
eqNo = hotWater.EqNo,
batch = hotWater.Batch,
matCode = hotWater.MatCode,
setValue = hotWater.SetValue,
setToler = hotWater.SetToler,
actToLer = hotWater.ActToler,
actValue = hotWater.ActValue,
reportId = gelDb.reportId,
recordTime = DateTime.Now,
kinds = 2
});
}
var coolWater = gel.CoolWater;
if (coolWater != null)
{
lsdetail.Add(new Report_GelDoser_Detail()
{
eqNo = coolWater.EqNo,
batch = coolWater.Batch,
matCode = coolWater.MatCode,
setValue = coolWater.SetValue,
setToler = coolWater.SetToler,
actToLer = coolWater.ActToler,
actValue = coolWater.ActValue,
reportId = gelDb.reportId,
recordTime = DateTime.Now,
kinds = 3
});
}
if(null!= lsdetail && lsdetail.Any())
{
gelDb.Batch = lsdetail.Select(x => x.batch).FirstOrDefault();
_dbContext.Insert(gelDb);
_dbContext.InsertRange(lsdetail);
_dbContext.InsertRange(lsMixing);
}
}
private void InsertM(int no)
{
DB2106Helper dB2106 = new DB2106Helper();
List<Report_WMixE> ls = null;
switch (no)
{
case 1:
ls = dB2106.WetReport.WetMixing_A;
break;
case 2:
ls = dB2106.WetReport.WetMixing_B;
break;
case 3:
ls = dB2106.WetReport.WetMixing_C;
break;
case 4:
ls = dB2106.WetReport.WetMixing_D;
break;
case 5:
ls = dB2106.WetReport.WetMixing_E;
break;
case 6:
ls = dB2106.WetReport.WetMixing_F;
break;
case 7:
ls = dB2106.WetReport.WetMixing_G;
break;
case 8:
ls = dB2106.WetReport.WetMixing_H;
break;
}
Report_WetMixer report = new Report_WetMixer();
report.reportId = Guid.NewGuid().ToString("N");
report.recipeCode = 0;
report.recipeName = "";
report.planCode = 0;
report.planName = "";
report.recordTime = DateTime.Now;
report.reportTime = DateTime.Now;
report.WetNo = no;
report.Batch = report.Batch;
List<Report_WetMixer_Detail> lde = new List<Report_WetMixer_Detail>();
foreach (var item in ls)
{
if (item.EqNo != 0)
{
lde.Add(new Report_WetMixer_Detail()
{
recordTime = DateTime.Now,
reportId = report.reportId,
eqNo = item.EqNo,
mixBatch = item.MixBatch,
mixSpeed = item.MixSpeed,
actCode = item.ActCode,
mixTemp = item.MixTemp,
mixStep = item.MixStep,
mixTime = item.MixTime,
actTolerence = item.ActTolerence,
actWeight = item.ActWeight,
});
}
else
{
break;
}
}
if(lde.Count > 0)
{
report.Batch=lde.Select(x=>x.mixBatch).First();
this._dbContext.Insert(report);
this._dbContext.InsertRange(lde);
}
}
}

@ -0,0 +1,55 @@
namespace WorkerSynReport.Plc;
public class SpeedEntity
{
public SpeedEntity(byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107.1324.0", 84);
var content = bytes.Skip(1324).Take(84).ToArray();
ManSpeed_D1 = PlcConnect.Instance.ByteTransform.TransSingle(content, 0);
ManSpeed_D2 = PlcConnect.Instance.ByteTransform.TransSingle(content, 4);
ManSpeed_D3 = PlcConnect.Instance.ByteTransform.TransSingle(content, 8);
ManSpeed_D4 = PlcConnect.Instance.ByteTransform.TransSingle(content, 12);
ManSpeed_G1 = PlcConnect.Instance.ByteTransform.TransSingle(content, 16);
ManSpeed_G2 = PlcConnect.Instance.ByteTransform.TransSingle(content, 20);
ManSpeed_G3 = PlcConnect.Instance.ByteTransform.TransSingle(content, 24);
ManSpeed_G4 = PlcConnect.Instance.ByteTransform.TransSingle(content, 28);
ManSpeed_G5 = PlcConnect.Instance.ByteTransform.TransSingle(content, 32);
ManSpeed_G6 = PlcConnect.Instance.ByteTransform.TransSingle(content, 36);
ManSpeed_G7 = PlcConnect.Instance.ByteTransform.TransSingle(content, 40);
ManSpeed_G8 = PlcConnect.Instance.ByteTransform.TransSingle(content, 44);
ManSpeed_H1 = PlcConnect.Instance.ByteTransform.TransSingle(content, 48);
ManSpeed_H2 = PlcConnect.Instance.ByteTransform.TransSingle(content, 52);
ManSpeed_H3 = PlcConnect.Instance.ByteTransform.TransSingle(content, 56);
ManSpeed_H4 = PlcConnect.Instance.ByteTransform.TransSingle(content, 60);
ManSpeed_S1 = PlcConnect.Instance.ByteTransform.TransSingle(content, 64);
ManSpeed_S5 = PlcConnect.Instance.ByteTransform.TransSingle(content, 68);
ManSpeed_S7 = PlcConnect.Instance.ByteTransform.TransSingle(content, 72);
ManSpeed_S11 = PlcConnect.Instance.ByteTransform.TransSingle(content, 76);
ManSpeed_S15 = PlcConnect.Instance.ByteTransform.TransSingle(content, 80);
}
public float ManSpeed_D1 { get; private set; }
public float ManSpeed_D2 { get; private set; }
public float ManSpeed_D3 { get; private set; }
public float ManSpeed_D4 { get; private set; }
public float ManSpeed_G1 { get; private set; }
public float ManSpeed_G2 { get; private set; }
public float ManSpeed_G3 { get; private set; }
public float ManSpeed_G4 { get; private set; }
public float ManSpeed_G5 { get; private set; }
public float ManSpeed_G6 { get; private set; }
public float ManSpeed_G7 { get; private set; }
public float ManSpeed_G8 { get; private set; }
public float ManSpeed_H1 { get; private set; }
public float ManSpeed_H2 { get; private set; }
public float ManSpeed_H3 { get; private set; }
public float ManSpeed_H4 { get; private set; }
public float ManSpeed_S1 { get; private set; }
public float ManSpeed_S5 { get; private set; }
public float ManSpeed_S7 { get; private set; }
public float ManSpeed_S11 { get; private set; }
public float ManSpeed_S15 { get; private set; }
}

@ -0,0 +1,79 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class UntiStatusHMIArrayEntity
{
public UntiStatusHMIArrayEntity(byte[] content)
{
byte byt = content[0];
Mode = byt.GetBit(0);
Status = byt.GetBit(1);
Batch = PlcConnect.Instance.ByteTransform.TransUInt16(content, 2);
Step = PlcConnect.Instance.ByteTransform.TransUInt16(content, 4);
StepCode = PlcConnect.Instance.ByteTransform.TransUInt16(content, 6);
TotalTime = PlcConnect.Instance.ByteTransform.TransInt32(content, 8);
StepTime = PlcConnect.Instance.ByteTransform.TransInt32(content, 12);
Temperature = PlcConnect.Instance.ByteTransform.TransSingle(content, 16);
Speed = PlcConnect.Instance.ByteTransform.TransSingle(content, 20);
FeedValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 24);
ActTolerance = PlcConnect.Instance.ByteTransform.TransSingle(content, 28);
}
public bool Mode { get; private set; }
public bool Status { get; private set; }
public ushort Batch { get; private set; }
public ushort Step { get; private set; }
public ushort StepCode { get; private set; }
public int TotalTime { get; private set; }
public int StepTime { get; private set; }
public float Temperature { get; private set; }
public float Speed { get; private set; }
public float FeedValue { get; private set; }
public float ActTolerance { get; private set; }
}
public class UntiStatusHMIArrayManager
{
private int Length;
private int StartSet;
private int SLength;
private byte[] Bytes;
/// <summary>
/// 数组处理
/// </summary>
/// <param name="length">数组长度</param>
/// <param name="startSet">数组起始偏移量</param>
/// <param name="sLength">数组单个元素长度</param>
public UntiStatusHMIArrayManager(ushort length, int startSet, int sLength, byte[] bytes)
{
Length = length;
StartSet = startSet;
SLength = sLength;
Bytes = bytes;
}
public List<UntiStatusHMIArrayEntity> GetList()
{
List<UntiStatusHMIArrayEntity> ListE = new List<UntiStatusHMIArrayEntity>(Length);
//var getListE = PlcConnect.Instance.Read("DB2107." + StartSet + ".0", Convert.ToUInt16(Length * SLength));
//if (!getListE.IsSuccess)
//{
// throw new Exception(getListE.Message);
//}
var content = Bytes.Skip(StartSet).Take(Length * SLength).ToArray();
for (int i = 0; i < Length; i++)
{
var singleBlock = content.Skip(SLength * i).Take(SLength).ToArray();
ListE.Add(new UntiStatusHMIArrayEntity(singleBlock));
}
return ListE;
}
}

@ -0,0 +1,219 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class ValveEntity
{
public ValveEntity(byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107.2048.0", 11);
var content = bytes.Skip(2048).Take(11).ToArray();
byte byt = content[0];
AS1BLT01 = byt.GetBit(0);
AS1BLT02 = byt.GetBit(1);
AS1BLT03 = byt.GetBit(2);
AS1BLT04 = byt.GetBit(3);
AS1BLT05 = byt.GetBit(4);
AS2BLT01 = byt.GetBit(5);
AS2BLT02 = byt.GetBit(6);
AS2BLT03 = byt.GetBit(7);
byt = content[1];
AS2BLT04 = byt.GetBit(0);
AS2BLT05 = byt.GetBit(1);
AS3BLT01 = byt.GetBit(2);
AS3BLT02 = byt.GetBit(3);
AS3BLT03 = byt.GetBit(4);
AS3BLT04 = byt.GetBit(5);
AS3BLT05 = byt.GetBit(6);
AS4BLT01 = byt.GetBit(7);
byt = content[2];
AS4BLT02 = byt.GetBit(0);
AS4BLT03 = byt.GetBit(1);
AS4BLT04 = byt.GetBit(2);
AS4BLT05 = byt.GetBit(3);
AS5BLT01 = byt.GetBit(4);
AS5BLT02 = byt.GetBit(5);
AS5BLT03 = byt.GetBit(6);
AS5BLT04 = byt.GetBit(7);
byt = content[3];
AS5BLT05 = byt.GetBit(0);
AS1OIS01 = byt.GetBit(1);
AS1OIS02 = byt.GetBit(2);
AS1OIS03 = byt.GetBit(3);
AS2OIS01 = byt.GetBit(4);
AS2OIS02 = byt.GetBit(5);
AS2OIS03 = byt.GetBit(6);
AS3OIS01 = byt.GetBit(7);
byt = content[4];
AS3OIS02 = byt.GetBit(0);
AS3OIS03 = byt.GetBit(1);
AS4OIS01 = byt.GetBit(2);
AS4OIS02 = byt.GetBit(3);
AS4OIS03 = byt.GetBit(4);
AS2PCP01 = byt.GetBit(5);
AS2PCP02 = byt.GetBit(6);
AS2PCP03 = byt.GetBit(7);
byt = content[5];
PV1ADB01 = byt.GetBit(0);
PV1BDB01 = byt.GetBit(1);
PV1CDB01 = byt.GetBit(2);
PV1DDB01 = byt.GetBit(3);
PV1EDB01 = byt.GetBit(4);
PV1FDB01 = byt.GetBit(5);
PV1GDB01 = byt.GetBit(6);
PV1HDB01 = byt.GetBit(7);
byt = content[6];
PV1IDB01 = byt.GetBit(0);
PV1JDB01 = byt.GetBit(1);
PV1KDB01 = byt.GetBit(2);
PV1LDB01 = byt.GetBit(3);
PM1ADF01 = byt.GetBit(4);
PM1BDF01 = byt.GetBit(5);
PM1CDF01 = byt.GetBit(6);
PM1DDF01 = byt.GetBit(7);
byt = content[7];
PM1EDF01 = byt.GetBit(0);
PM1FDF01 = byt.GetBit(1);
PM1GDF01 = byt.GetBit(2);
PM1HDF01 = byt.GetBit(3);
PM1IDF01 = byt.GetBit(4);
PM1JDF01 = byt.GetBit(5);
PM1KDF01 = byt.GetBit(6);
PM1LDF01 = byt.GetBit(7);
byt = content[8];
PV2ADB01 = byt.GetBit(0);
PV2BDB01 = byt.GetBit(1);
PV2CDB01 = byt.GetBit(2);
PV2DDB01 = byt.GetBit(3);
AS1GET01 = byt.GetBit(4);
AS1GET02 = byt.GetBit(5);
AS2GET01 = byt.GetBit(6);
AS2GET02 = byt.GetBit(7);
byt = content[9];
AS3GET01 = byt.GetBit(0);
AS3GET02 = byt.GetBit(1);
AS4GET01 = byt.GetBit(2);
AS4GET02 = byt.GetBit(3);
AS5GET01 = byt.GetBit(4);
AS5GET02 = byt.GetBit(5);
AS6GET01 = byt.GetBit(6);
AS6GET02 = byt.GetBit(7);
byt = content[10];
AS7GET01 = byt.GetBit(0);
AS7GET02 = byt.GetBit(1);
AS8GET01 = byt.GetBit(2);
AS8GET02 = byt.GetBit(3);
}
public bool AS1BLT01 { get; private set; }
public bool AS1BLT02 { get; private set; }
public bool AS1BLT03 { get; private set; }
public bool AS1BLT04 { get; private set; }
public bool AS1BLT05 { get; private set; }
public bool AS2BLT01 { get; private set; }
public bool AS2BLT02 { get; private set; }
public bool AS2BLT03 { get; private set; }
public bool AS2BLT04 { get; private set; }
public bool AS2BLT05 { get; private set; }
public bool AS3BLT01 { get; private set; }
public bool AS3BLT02 { get; private set; }
public bool AS3BLT03 { get; private set; }
public bool AS3BLT04 { get; private set; }
public bool AS3BLT05 { get; private set; }
public bool AS4BLT01 { get; private set; }
public bool AS4BLT02 { get; private set; }
public bool AS4BLT03 { get; private set; }
public bool AS4BLT04 { get; private set; }
public bool AS4BLT05 { get; private set; }
public bool AS5BLT01 { get; private set; }
public bool AS5BLT02 { get; private set; }
public bool AS5BLT03 { get; private set; }
public bool AS5BLT04 { get; private set; }
public bool AS5BLT05 { get; private set; }
public bool AS1OIS01 { get; private set; }
public bool AS1OIS02 { get; private set; }
public bool AS1OIS03 { get; private set; }
public bool AS2OIS01 { get; private set; }
public bool AS2OIS02 { get; private set; }
public bool AS2OIS03 { get; private set; }
public bool AS3OIS01 { get; private set; }
public bool AS3OIS02 { get; private set; }
public bool AS3OIS03 { get; private set; }
public bool AS4OIS01 { get; private set; }
public bool AS4OIS02 { get; private set; }
public bool AS4OIS03 { get; private set; }
public bool AS2PCP01 { get; private set; }
public bool AS2PCP02 { get; private set; }
public bool AS2PCP03 { get; private set; }
public bool PV1ADB01 { get; private set; }
public bool PV1BDB01 { get; private set; }
public bool PV1CDB01 { get; private set; }
public bool PV1DDB01 { get; private set; }
public bool PV1EDB01 { get; private set; }
public bool PV1FDB01 { get; private set; }
public bool PV1GDB01 { get; private set; }
public bool PV1HDB01 { get; private set; }
public bool PV1IDB01 { get; private set; }
public bool PV1JDB01 { get; private set; }
public bool PV1KDB01 { get; private set; }
public bool PV1LDB01 { get; private set; }
public bool PM1ADF01 { get; private set; }
public bool PM1BDF01 { get; private set; }
public bool PM1CDF01 { get; private set; }
public bool PM1DDF01 { get; private set; }
public bool PM1EDF01 { get; private set; }
public bool PM1FDF01 { get; private set; }
public bool PM1GDF01 { get; private set; }
public bool PM1HDF01 { get; private set; }
public bool PM1IDF01 { get; private set; }
public bool PM1JDF01 { get; private set; }
public bool PM1KDF01 { get; private set; }
public bool PM1LDF01 { get; private set; }
public bool PV2ADB01 { get; private set; }
public bool PV2BDB01 { get; private set; }
public bool PV2CDB01 { get; private set; }
public bool PV2DDB01 { get; private set; }
public bool AS1GET01 { get; private set; }
public bool AS1GET02 { get; private set; }
public bool AS2GET01 { get; private set; }
public bool AS2GET02 { get; private set; }
public bool AS3GET01 { get; private set; }
public bool AS3GET02 { get; private set; }
public bool AS4GET01 { get; private set; }
public bool AS4GET02 { get; private set; }
public bool AS5GET01 { get; private set; }
public bool AS5GET02 { get; private set; }
public bool AS6GET01 { get; private set; }
public bool AS6GET02 { get; private set; }
public bool AS7GET01 { get; private set; }
public bool AS7GET02 { get; private set; }
public bool AS8GET01 { get; private set; }
public bool AS8GET02 { get; private set; }
}

@ -0,0 +1,55 @@
using NewLife;
namespace WorkerSynReport.Plc;
public class WeightEntity
{
byte[] bytes;
public WeightEntity(byte[] bytes)
{
this.bytes = bytes;
}
public Silo_HMI Hopper_1 => new Silo_HMI(432, bytes);
public Silo_HMI Hopper_2 => new Silo_HMI(446, bytes);
public Silo_HMI Hopper_3 => new Silo_HMI(460, bytes);
public Silo_HMI Hopper_4 => new Silo_HMI(474, bytes);
public Silo_HMI Vessel_1 => new Silo_HMI(488, bytes);
public Silo_HMI Vessel_2 => new Silo_HMI(502, bytes);
public Silo_HMI Vessel_3 => new Silo_HMI(516, bytes);
public Silo_HMI Vessel_4 => new Silo_HMI(530, bytes);
public Silo_HMI Vessel_5 => new Silo_HMI(544, bytes);
public Silo_HMI WScale_1 => new Silo_HMI(558, bytes);
public Silo_HMI WScale_2 => new Silo_HMI(572, bytes);
public Silo_HMI WScale_3 => new Silo_HMI(586, bytes);
public Silo_HMI WScale_4 => new Silo_HMI(600, bytes);
}
public class Silo_HMI
{
public Silo_HMI(ushort startSet, byte[] bytes)
{
//OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107." + startSet + ".0", 14);
var content = bytes.Skip(startSet).Take(14).ToArray();
ActWeight = PlcConnect.Instance.ByteTransform.TransSingle(content, 0);
HighWeight = PlcConnect.Instance.ByteTransform.TransSingle(content, 4);
LowWeight = PlcConnect.Instance.ByteTransform.TransSingle(content, 8);
byte byt = content[12];
HighLevel = byt.GetBit(0);
Lowlevel = byt.GetBit(1);
}
public float ActWeight { get; private set; }
public float HighWeight { get; private set; }
public float LowWeight { get; private set; }
public bool HighLevel { get; private set; }
public bool Lowlevel { get; private set; }
}

@ -0,0 +1,68 @@
namespace WorkerSynReport.Plc;
public class WeightPraEntity
{
byte[] bytes;
public WeightPraEntity(byte[] bytes)
{
this.bytes = bytes;
}
public List<WeightParaE> Silo => new WeightParaArrayManager(15, 694, 18, bytes).GetList();
public List<WeightParaE> Daybin => new WeightParaArrayManager(12, 964, 18, bytes).GetList();
public List<WeightParaE> Hoper => new WeightParaArrayManager(4, 1180, 18, bytes).GetList();
public List<WeightParaE> Water => new WeightParaArrayManager(4, 1252, 18, bytes).GetList();
}
public class WeightParaE
{
public WeightParaE(byte[] content)
{
HighSpeed = PlcConnect.Instance.ByteTransform.TransSingle(content, 0);
LowSpeed = PlcConnect.Instance.ByteTransform.TransSingle(content, 4);
WeightSlow = PlcConnect.Instance.ByteTransform.TransSingle(content, 8);
Precut = PlcConnect.Instance.ByteTransform.TransSingle(content, 12);
JogTime = PlcConnect.Instance.ByteTransform.TransInt16(content, 16);
}
public float HighSpeed { get; private set; }
public float LowSpeed { get; private set; }
public float WeightSlow { get; private set; }
public float Precut { get; private set; }
public int JogTime { get; private set; }
}
public class WeightParaArrayManager
{
private int Length;
private int StartSet;
private int SLength;
byte[] bytes;
public WeightParaArrayManager(ushort length, int startSet, int sLength, byte[] bytes)
{
Length = length;
StartSet = startSet;
SLength = sLength;
this.bytes = bytes;
}
public List<WeightParaE> GetList()
{
List<WeightParaE> ListE = new List<WeightParaE>(Length);
//var getListE = PlcConnect.Instance.Read("DB2107." + StartSet + ".0", Convert.ToUInt16(Length * SLength));
var content = bytes.Skip(StartSet).Take(Length * SLength).ToArray();
for (int i = 0; i < Length; i++)
{
var singleBlock = content.Skip(SLength * i).Take(SLength).ToArray();
ListE.Add(new WeightParaE(singleBlock));
}
return ListE;
}
}

@ -0,0 +1,83 @@
namespace WorkerSynReport.Plc;
public class WetMixingEntity
{
private int StartSet;
private byte[] bytes;
public WetMixingEntity(int startSet, byte[] bytes)
{
this.StartSet = startSet;
this.bytes = bytes;
}
public List<Report_WMixE> WetMixing_A => new WetReportArrayManager(10, StartSet, 26, bytes).GetList();
public List<Report_WMixE> WetMixing_B => new WetReportArrayManager(10, StartSet + 260, 26, bytes).GetList();
public List<Report_WMixE> WetMixing_C => new WetReportArrayManager(10, StartSet + 520, 26, bytes).GetList();
public List<Report_WMixE> WetMixing_D => new WetReportArrayManager(10, StartSet + 780, 26, bytes).GetList();
public List<Report_WMixE> WetMixing_E => new WetReportArrayManager(10, StartSet + 1040, 26, bytes).GetList();
public List<Report_WMixE> WetMixing_F => new WetReportArrayManager(10, StartSet + 1300, 26, bytes).GetList();
public List<Report_WMixE> WetMixing_G => new WetReportArrayManager(10, StartSet + 1560, 26, bytes).GetList();
public List<Report_WMixE> WetMixing_H => new WetReportArrayManager(10, StartSet + 1820, 26, bytes).GetList();
}
public class Report_WMixE
{
public Report_WMixE(byte[] content)
{
EqNo = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
MixBatch = PlcConnect.Instance.ByteTransform.TransInt16(content, 2);
MixStep = PlcConnect.Instance.ByteTransform.TransInt16(content, 4);
ActCode = PlcConnect.Instance.ByteTransform.TransInt16(content, 6);
MixTime = PlcConnect.Instance.ByteTransform.TransInt16(content, 8);
MixTemp = PlcConnect.Instance.ByteTransform.TransSingle(content, 10);
MixSpeed = PlcConnect.Instance.ByteTransform.TransSingle(content, 14);
ActWeight = PlcConnect.Instance.ByteTransform.TransSingle(content, 18);
ActTolerence = PlcConnect.Instance.ByteTransform.TransSingle(content, 22);
}
public short EqNo { get; private set; }
public short MixBatch { get; private set; }
public short MixStep { get; private set; }
public short ActCode { get; private set; }
public short MixTime { get; private set; }
public float MixTemp { get; private set; }
public float MixSpeed { get; private set; }
public float ActWeight { get; private set; }
public float ActTolerence { get; private set; }
}
public class WetReportArrayManager
{
private int Length;
private int StartSet;
private int SLength;
private byte[] Bytes;
public WetReportArrayManager(ushort length, int startSet, int sLength, byte[] bytes)
{
Length = length;
StartSet = startSet;
SLength = sLength;
Bytes = bytes;
}
public List<Report_WMixE> GetList()
{
List<Report_WMixE> ListE = new List<Report_WMixE>(Length);
//var getListE = PlcConnect.Instance.Read("DB2106." + StartSet + ".0", Convert.ToUInt16(Length * SLength));
var content = Bytes.Skip(StartSet).Take(Length * SLength).ToArray();
for (int i = 0; i < Length; i++)
{
var singleBlock = content.Skip(SLength * i).Take(SLength).ToArray();
ListE.Add(new Report_WMixE(singleBlock));
}
return ListE;
}
}

@ -1,19 +1,20 @@
using NewLife.Extensions.Hosting.AgentService; using NewLife.Extensions.Hosting.AgentService;
using NewLife.Log; using NewLife.Log;
using WorkerSynReport; using WorkerSynReport;
using WorkerSynReport.Plc;
XTrace.UseConsole(); XTrace.UseConsole();
IHost host = Host.CreateDefaultBuilder(args) IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services => .ConfigureServices(services =>
{ {
services.AddScoped<IDbContextLocal>(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;")); services.AddScoped<IDbContextLocal>(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;"));
services.AddScoped<IDbContextHttp>(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;")); services.AddScoped<IDbContextHttp>(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;"));
// services.AddHostedService<Worker>();
services.AddScoped<ReportReadDb>();
services.AddHostedService<PclWorker>();
services.AddHostedService<Worker>();
}) })
.UseAgentService(options => .UseAgentService(options =>
{ {

@ -44,7 +44,7 @@ namespace WorkerSynReport
.OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync(); .OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync();
var objId=await dbContextLocal.Query<Report_WetMixer>().Where(x => x.reportId == reportId) var objId=await dbContextLocal!.Query<Report_WetMixer>().Where(x => x.reportId == reportId)
.Select(x => x.objId).FirstOrDefaultAsync(); .Select(x => x.objId).FirstOrDefaultAsync();
if (objId>0) if (objId>0)
{ {
@ -79,7 +79,7 @@ namespace WorkerSynReport
var reportId=await dbContextHttp!.Query<Report_Dry>() var reportId=await dbContextHttp!.Query<Report_Dry>()
.OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync(); .OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync();
var objId=await dbContextLocal.Query<Report_Dry>().Where(x => x.reportId == reportId) var objId=await dbContextLocal!.Query<Report_Dry>().Where(x => x.reportId == reportId)
.Select(x => x.objId).FirstOrDefaultAsync(); .Select(x => x.objId).FirstOrDefaultAsync();
if (objId > 0) if (objId > 0)
@ -122,7 +122,7 @@ namespace WorkerSynReport
var reportId=await dbContextHttp!.Query<Report_Gel>() var reportId=await dbContextHttp!.Query<Report_Gel>()
.OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync(); .OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync();
var objId=await dbContextLocal.Query<Report_Gel>().Where(x => x.reportId == reportId) var objId=await dbContextLocal!.Query<Report_Gel>().Where(x => x.reportId == reportId)
.Select(x => x.objId).FirstOrDefaultAsync(); .Select(x => x.objId).FirstOrDefaultAsync();
if (objId > 0) if (objId > 0)

Loading…
Cancel
Save