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.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPlanning/LjPlanningPlcHelp.cs

808 lines
25 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using DataBlockHelper;
using Mesnac.Action.ChemicalWeighing.LjMixManager;
namespace Mesnac.Action.ChemicalWeighing.LjPlanning
1 year ago
{
public class LjPlanningPlcHelp
{
1 year ago
public static DryerView GetDryerD1 => GetDryerView(58);
public static DryerView GetDryerD2 => GetDryerView(298);
public static DryerView GetDryerD3 => GetDryerView(538);
public static DryerView GetDryerD4 => GetDryerView(778);
public static DryerView GetGelatG1 => GetGelatView(1018);
public static DryerView GetGelatG2 => GetGelatView(1158);
public static DryerView GetGelatG3 => GetGelatView(1298);
public static DryerView GetGelatG4 => GetGelatView(1438);
public static DryerView GetGelatG5 => GetGelatView(1578);
public static DryerView GetGelatG6 => GetGelatView(1718);
public static DryerView GetGelatG7 => GetGelatView(1858);
public static DryerView GetGelatG8 => GetGelatView(1998);
1 year ago
public static List<MixStep> GetWeterM1 => GetWeterView(2138);
public static List<MixStep> GetWeterM2 => GetWeterView(2338);
public static List<MixStep> GetWeterM3 => GetWeterView(2538);
public static List<MixStep> GetWeterM4 => GetWeterView(2738);
public static List<MixStep> GetWeterM5 => GetWeterView(2938);
public static List<MixStep> GetWeterM6 => GetWeterView(3138);
public static List<MixStep> GetWeterM7 => GetWeterView(3338);
public static List<MixStep> GetWeterM8 => GetWeterView(3538);
1 year ago
/// <summary>
/// 干混机1
/// </summary>
/// <param name="recipePlcViews"></param>
/// <param name="recipeSteps"></param>
public static void DownD1Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
1 year ago
{
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
6 months ago
int begin = 128;
1 year ago
DownCleanD1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
Dowd(begin, view);
begin += 10;
}
6 months ago
begin = 278;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowSteps(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.53.6",true);
}
1 year ago
public static void DownD2Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
6 months ago
int begin = 398;
1 year ago
DownCleanD1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
Dowd(begin, view);
begin += 10;
}
6 months ago
begin = 548;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowSteps(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.53.7", true);
}
public static void DownD3Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
6 months ago
int begin = 668;
1 year ago
DownCleanD1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
Dowd(begin, view);
begin += 10;
}
6 months ago
begin = 818;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowSteps(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.54.0", true);
}
public static void DownD4Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
6 months ago
int begin = 938;
1 year ago
DownCleanD1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
Dowd(begin, view);
begin += 10;
}
6 months ago
begin = 1088;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowSteps(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.54.1", true);
}
1 year ago
public static void DownG1Recipe(List<RecipePlcView> recipePlcViews,List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin = 1018;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
begin = 1038;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.53.6",true);
}
public static void DownG2Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin = 1158;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
1 year ago
begin = 1178;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.54.2", true);
}
public static void DownG3Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin = 1298;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
1 year ago
begin = 1318;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.53.7", true);
}
public static void DownG4Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin = 1438;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
begin = 1458;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.54.4", true);
}
1 year ago
public static void DownG5Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin = 1578;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
begin = 1598;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.54.6", true);
}
public static void DownG6Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin =1718;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
1 year ago
begin = 1738;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.54.7", true);
}
public static void DownG7Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin =1858;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
1 year ago
begin = 1878;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.0", true);
}
public static void DownG8Recipe(List<RecipePlcView> recipePlcViews, List<Step> recipeSteps)
{
1 year ago
1 year ago
recipePlcViews = recipePlcViews.Where(x => x.Bin != -1).ToList();
1 year ago
int begin =1998;
1 year ago
DownCleanG1Recipe(begin);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
begin += 10;
}
1 year ago
begin = 2018;
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
begin += 12;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.1", true);
}
public static void DownM1Recipe(List<MixStep> recipeSteps)
{
1 year ago
int begin = 2138;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.2", true);
}
public static void DownM2Recipe(List<MixStep> recipeSteps)
{
1 year ago
int begin = 2338;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.3", true);
}
public static void DownM3Recipe(List<MixStep> recipeSteps)
{
1 year ago
int begin = 2538;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.4", true);
}
public static void DownM4Recipe(List<MixStep> recipeSteps)
{
1 year ago
int begin = 2738;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.5", true);
}
public static void DownM5Recipe(List<MixStep> recipeSteps)
{
1 year ago
int begin = 2938;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.6", true);
}
public static void DownM6Recipe(List<MixStep> recipeSteps)
{
int begin = 3138;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.55.7", true);
}
public static void DownM7Recipe(List<MixStep> recipeSteps)
{
int begin = 3338;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.56.0", true);
}
public static void DownM8Recipe(List<MixStep> recipeSteps)
{
int begin = 3538;
1 year ago
DownM1CleanRecipe(begin);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
1 year ago
PlcConnect.Instance.Write($"DB2104.56.1", true);
}
private static DryerView GetDryerView(int start)
{
var byteTransform = PlcConnect.Instance.ByteTransform;
DryerView view = new DryerView();
var operateResult = PlcConnect.Instance.Read($"DB2104.{start}.0", 240);
if (operateResult.IsSuccess)
{
List<RecipePlcView> ls = new List<RecipePlcView>();
var convert = operateResult.Content;
var data = convert.Skip(0).Take(120);
for (int i = 0; i < 12; i++)
{
var bytes = data.Skip(i * 10).Take(10).ToArray();
RecipePlcView plcView = new RecipePlcView
{
Bin = byteTransform.TransInt16(bytes, 0),
Set = byteTransform.TransSingle(bytes, 2),
1 year ago
Tolerance = byteTransform.TransSingle(bytes, 6)
};
ls.Add(plcView);
}
view.RecipePlcViews = ls;
data = convert.Skip(120).Take(120);
List<Step> lsSteps = new List<Step>();
for (int i = 0; i < 10; i++)
{
var bytes = data.Skip(i * 12).Take(12).ToArray();
Step step = new Step()
{
MixCode = byteTransform.TransInt16(bytes, 0),
MixTime = byteTransform.TransInt16(bytes, 2),
MixTemp = byteTransform.TransSingle(bytes, 4),
MixSpeed = byteTransform.TransSingle(bytes, 8)
};
lsSteps.Add(step);
}
view.RecipeSteps = lsSteps;
}
return view;
}
private static DryerView GetGelatView(int start)
{
var byteTransform = PlcConnect.Instance.ByteTransform;
DryerView view = new DryerView();
var operateResult = PlcConnect.Instance.Read($"DB2104.{start}.0", 140);
if (operateResult.IsSuccess)
{
List<RecipePlcView> ls = new List<RecipePlcView>();
var convert = operateResult.Content;
var data = convert.Skip(0).Take(20);
for (int i = 0; i < 2; i++)
{
var bytes = data.Skip(i * 10).Take(10).ToArray();
RecipePlcView plcView = new RecipePlcView
{
Bin = byteTransform.TransInt16(bytes, 0),
Set = byteTransform.TransSingle(bytes, 2),
1 year ago
Tolerance = byteTransform.TransSingle(bytes, 6)
};
ls.Add(plcView);
}
view.RecipePlcViews = ls;
data = convert.Skip(20).Take(120);
List<Step> lsSteps = new List<Step>();
for (int i = 0; i < 10; i++)
{
var bytes = data.Skip(i * 12).Take(12).ToArray();
Step step = new Step()
{
MixCode = byteTransform.TransInt16(bytes, 0),
MixTime = byteTransform.TransInt16(bytes, 2),
MixTemp = byteTransform.TransSingle(bytes, 4),
MixSpeed = byteTransform.TransSingle(bytes, 8)
};
lsSteps.Add(step);
}
view.RecipeSteps = lsSteps;
}
return view;
}
private static List<MixStep> GetWeterView(int start)
{
var byteTransform = PlcConnect.Instance.ByteTransform;
var operateResult = PlcConnect.Instance.Read($"DB2104.{start}.0", 200);
List<MixStep> lsSteps = new List<MixStep>();
if (operateResult.IsSuccess)
{
var data = operateResult.Content;
for (int i = 0; i < 10; i++)
{
var bytes = data.Skip(i * 20).Take(20).ToArray();
MixStep step = new MixStep()
{
MixCode = byteTransform.TransInt16(bytes, 0),
MixTime = byteTransform.TransInt16(bytes, 2),
MixTemp = byteTransform.TransSingle(bytes, 4),
MixSpeed = byteTransform.TransSingle(bytes, 8),
SetValue = byteTransform.TransSingle(bytes, 12),
SetTolerance = byteTransform.TransSingle(bytes, 16)
};
lsSteps.Add(step);
}
}
return lsSteps;
}
1 year ago
private static void DownCleanD1Recipe(int begin)
{
6 months ago
List<RecipePlcView> recipePlcViews = GetClean(15);
1 year ago
List<Step> recipeSteps = GetCleanStep(10);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
Dowd(begin, view);
begin += 10;
}
6 months ago
11 months ago
1 year ago
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowSteps(begin, view);
begin += 12;
}
}
private static void DownCleanG1Recipe(int begin)
{
List<RecipePlcView> recipePlcViews = GetClean(2);
List<Step> recipeSteps = GetCleanStep(10);
for (int i = 0; i < recipePlcViews.Count(); i++)
{
var view = recipePlcViews[i];
6 months ago
Dowd2(begin, view);
1 year ago
begin += 10;
}
12 months ago
1 year ago
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
6 months ago
DowSteps2(begin, view);
1 year ago
begin += 12;
}
}
private static void DownM1CleanRecipe(int begin)
{
List<MixStep> recipeSteps = GetCleanMixStep(10);
for (int i = 0; i < recipeSteps.Count(); i++)
{
var view = recipeSteps[i];
DowMSteps(begin, view);
begin += 20;
}
}
6 months ago
private static void Dowd2(int start, RecipePlcView view)
{
int bin = start;
PlcConnect.Instance.Write($"DB2104.{bin}.0", view.Bin);
int set = start + 2;
PlcConnect.Instance.Write($"DB2104.{set}.0", view.Set);
int tolerance = start + 6;
PlcConnect.Instance.Write($"DB2104.{tolerance}.0", view.Tolerance);
}
private static void DowSteps2(int start, Step step)
{
int mixCode = start;
var info = PlcConnect.Instance.Write($"DB2104.{mixCode}.0", step.MixCode);
int mixTime = start + 2;
PlcConnect.Instance.Write($"DB2104.{mixTime}.0", step.MixTime);
int mixTemp = start + 4;
PlcConnect.Instance.Write($"DB2104.{mixTemp}.0", step.MixTemp);
int mixSpeed = start + 8;
PlcConnect.Instance.Write($"DB2104.{mixSpeed}.0", step.MixSpeed);
}
private static void Dowd(int start, RecipePlcView view)
{
int bin = start;
6 months ago
PlcConnect.Instance.Write($"DB2108.{bin}.0", view.Bin);
int set = start + 2;
6 months ago
PlcConnect.Instance.Write($"DB2108.{set}.0", view.Set);
int tolerance = start + 6;
6 months ago
PlcConnect.Instance.Write($"DB2108.{tolerance}.0", view.Tolerance);
}
private static void DowSteps(int start, Step step)
{
int mixCode = start;
6 months ago
var info= PlcConnect.Instance.Write($"DB2108.{mixCode}.0", step.MixCode);
int mixTime = start + 2;
6 months ago
PlcConnect.Instance.Write($"DB2108.{mixTime}.0", step.MixTime);
int mixTemp = start + 4;
6 months ago
PlcConnect.Instance.Write($"DB2108.{mixTemp}.0", step.MixTemp);
int mixSpeed = start + 8;
6 months ago
PlcConnect.Instance.Write($"DB2108.{mixSpeed}.0", step.MixSpeed);
}
private static void DowMSteps(int start, MixStep step)
{
int mixCode = start;
var s= PlcConnect.Instance.Write($"DB2104.{mixCode}.0", step.MixCode);
int mixTime = start + 2;
PlcConnect.Instance.Write($"DB2104.{mixTime}.0", step.MixTime);
int mixTemp = start + 4;
PlcConnect.Instance.Write($"DB2104.{mixTemp}.0", step.MixTemp);
int mixSpeed = start + 8;
PlcConnect.Instance.Write($"DB2104.{mixSpeed}.0", step.MixSpeed);
int setValue = start + 12;
PlcConnect.Instance.Write($"DB2104.{setValue}.0", step.SetValue);
int tolerance = start + 16;
PlcConnect.Instance.Write($"DB2104.{tolerance}.0", step.SetTolerance);
}
private static List<RecipePlcView> GetClean(int num)
{
List<RecipePlcView> ls = new List<RecipePlcView>(num);
for (int i = 0; i < num; i++)
{
ls.Add(new RecipePlcView()
{
Bin = 0,
1 year ago
Tolerance = 0,
Set = 0
});
}
return ls;
}
private static List<Step> GetCleanStep(int num)
{
List<Step> ls = new List<Step>(num);
for (int i = 0; i < num; i++)
{
ls.Add(new Step()
{
MixCode = 0,
MixSpeed = 0,
MixTemp = 0,
MixTime = 0
});
}
return ls;
}
private static List<MixStep> GetCleanMixStep(int num)
{
List<MixStep> ls = new List<MixStep>(num);
for (int i = 0; i < num; i++)
{
ls.Add(new MixStep()
{
MixCode = 0,
MixSpeed = 0,
MixTemp = 0,
MixTime = 0,
SetTolerance = 0,
SetValue = 0
});
}
return ls;
}
1 year ago
}
}