Commit 39bb3d32 authored by 潘栩锋's avatar 潘栩锋 🚴

自动模头程序 通过 模拟器调试。 应该没问题

parent 8bc081e4
......@@ -10,10 +10,10 @@ namespace FLY.FilmCasting.AutoDie.Common
{
static ERRNOs()
{
ERRNO_PLC_DISCONNECTED = new ERRNO() { Code = 65535, Descrption = "风环 PLC连接断开" };
ERRNO_PLC_DISCONNECTED = new ERRNO() { Code = 65535, Descrption = "PLC连接断开" };
#region 收卷
ERRNO_NO_FAN = new ERRNO() { Code = 0, Descrption = "风机没开,不能加热" };
ERRNO_NO_FAN = new ERRNO() { Code = 0, Descrption = "总开关没打开,不能加热" };
ERRNO_OPEN_CIRCUIT = new ERRNO() { Code = 1, Descrption = "加热棒断路" };
ERRNO_SHORT_CIRCUIT = new ERRNO() { Code = 2, Descrption = "加热控制板短路" };
ERRNO_POWER_OFF = new ERRNO() { Code = 3, Descrption = "电源没开启或电流计损坏" };
......
......@@ -96,12 +96,6 @@ namespace FLY.FilmCasting.AutoDie.IService
/// </summary>
bool CheckEnable { set; get; }
/// <summary>
/// 当前正在检测的加热通道
/// </summary>
int CheckNo { get; }
/// <summary>
/// 烧了的加热棒
/// </summary>
......
......@@ -11,14 +11,10 @@ namespace FLY.FilmCasting.AutoDie.Server
public interface IPLCLink:INotifyPropertyChanged
{
#region 输出
/// <summary>
/// 加热通道数
/// </summary>
UInt16 ChannelCnt { get; set; }
/// <summary>
/// 加热量更新 写
/// </summary>
UInt16 HeatUpdate { get; set; }
void SetChannelCnt(UInt16 channelCnt);
void SetHeatUpdate(UInt16 heatUpdate);
/// <summary>
/// 设置加热量
/// </summary>
......@@ -43,7 +39,7 @@ namespace FLY.FilmCasting.AutoDie.Server
#endregion
#region 状态
int Errno { get; set; }
bool IsConected { get; }
#endregion
}
......
......@@ -121,23 +121,11 @@ namespace FLY.FilmCasting.AutoDie.Server
/// </summary>
public bool HasCheckFilmVelocity { get; set; }
/// <summary>
/// 当前正在检测的加热通道
/// </summary>
public int CheckNo { get; set; } = -2;
/// <summary>
/// 正在检测中
/// </summary>
public bool CheckEnable { get; set; } = false;
/// <summary>
/// 1块加热控制板 接多少路加热
/// </summary>
public int HeatsOfGroup { get; set; } = 12;
#endregion
#endregion
......@@ -178,9 +166,10 @@ namespace FLY.FilmCasting.AutoDie.Server
public FeedbackHeat()
{
Load();
if (!Load())
Save();
plc = new PLCLink(Misc.StringConverter.ToIPEndPoint("192.168.50.60:502"));
}
......@@ -194,16 +183,28 @@ namespace FLY.FilmCasting.AutoDie.Server
)
{
this.boltMapFilmCasting = boltMapFilmCasting;
this.bulkDb = bulkDb;
this.gageService = gageService;
mWarning = warning;
mHistoryDb = historyDb;
plc.PropertyChanged += new PropertyChangedEventHandler(hmi_PropertyChanged);
HasElectricity = plc.HasElectricity;
HasFan = plc.HasFan;
plc = new PLCLink(Misc.StringConverter.ToIPEndPoint(PLCep));
Misc.BindingOperations.SetBinding(plc, nameof(plc.IsConected), this, nameof(IsConnectedWithPLC));
Misc.BindingOperations.SetBinding(plc, nameof(plc.HasElectricity), this, nameof(HasElectricity));
Misc.BindingOperations.SetBinding(plc, nameof(plc.HasFan), this, nameof(HasFan));
Misc.BindingOperations.SetBinding(plc, nameof(plc.IsConected), () => {
if (plc.IsConected == true)
{
//刚成功连接上
//重新复制数据到 PLC
RecoverPLC();
}
});
......@@ -291,12 +292,9 @@ namespace FLY.FilmCasting.AutoDie.Server
Misc.BindingOperations.SetBinding(this, nameof(HasElectricity), mHeatCheck, nameof(mHeatCheck.HasElectricity));
Misc.BindingOperations.SetBinding(this, nameof(HasCheck), mHeatCheck, nameof(mHeatCheck.Has));
Misc.BindingOperations.SetBinding(mHeatCheck, nameof(mHeatCheck.Enable), this, nameof(CheckEnable), Misc.BindingOperations.BindingMode.TwoWay);
Misc.BindingOperations.SetBinding(mHeatCheck, nameof(mHeatCheck.CheckNo), this, nameof(CheckNo));
Misc.BindingOperations.SetBinding(mHeatCheck, nameof(mHeatCheck.Bads), this, nameof(Bads));
Misc.BindingOperations.SetBinding(this, nameof(HeatsOfGroup), mHeatCheck, nameof(mHeatCheck.HeatsOfGroup));
//mHeatCell.Init3(blowingService);
Misc.BindingOperations.SetBinding(boltMapFilmCasting, nameof(boltMapFilmCasting.NBolts), this, nameof(ChannelCnt));
......@@ -465,7 +463,7 @@ namespace FLY.FilmCasting.AutoDie.Server
void InitBuf()
{
plc.ChannelCnt = (UInt16)ChannelCnt;
plc.SetChannelCnt((UInt16)ChannelCnt);
//Currs = new int[ChannelCnt];
mHeatBuf.Init(ChannelCnt);
mHeatCell.Init2(ChannelCnt);
......@@ -476,36 +474,7 @@ namespace FLY.FilmCasting.AutoDie.Server
//复位undo模块
resetUndo();
}
void hmi_PropertyChanged(object s, PropertyChangedEventArgs _e)
{
FObjBase.PollModule.Current.Dispatcher.Invoke(
new PropertyChangedEventHandler(
(sender, e) =>
{
if (e.PropertyName == nameof(plc.Errno))
{
if (plc.Errno == -1)
{
IsConnectedWithPLC = false;
}
else
{
IsConnectedWithPLC = true;
//刚成功连接上
//重新复制数据到 PLC
RecoverPLC();
}
}
else if (e.PropertyName == nameof(plc.HasElectricity))
{
HasElectricity = plc.HasElectricity;
}
else if (e.PropertyName == nameof(plc.HasFan))
{
HasFan = plc.HasFan;
}
}), s, _e);
}
......@@ -660,11 +629,11 @@ namespace FLY.FilmCasting.AutoDie.Server
UInt16 heatupdate = (UInt16)(plc.HeatUpdate_R + 1);
if (heatupdate > 100)
heatupdate = 1;
plc.HeatUpdate = heatupdate;
plc.SetHeatUpdate(heatupdate);
}
void RecoverPLC()
{
plc.ChannelCnt = (UInt16)ChannelCnt;
plc.SetChannelCnt((UInt16)ChannelCnt);
if (lastHeats != null)
{
plc.SetHeat(lastHeats.Select(h => (UInt16)h));
......@@ -675,10 +644,15 @@ namespace FLY.FilmCasting.AutoDie.Server
//设置全部0进去
plc.SetHeat(new UInt16[ChannelCnt]);
}
//这里是在 plc.IsConnected = true, 才会触发。
//只有读取一次PLC后,IsConnected 才会=true,
//所以 HeatUpdate_R 肯定是对的
UInt16 heatupdate = (UInt16)(plc.HeatUpdate_R + 1);
if (heatupdate > 100)
heatupdate = 1;
plc.HeatUpdate = heatupdate;
plc.SetHeatUpdate(heatupdate);
}
......@@ -773,37 +747,11 @@ namespace FLY.FilmCasting.AutoDie.Server
string file_path = "feedback.json";
bool Load()
{
if (File.Exists(file_path))
{
try
{
string json = File.ReadAllText(file_path);
var jsonDb = JsonConvert.DeserializeObject<FeedbackHeatJsonDb>(json);
FeedbackHeatJsonDb.Mapper.Map(jsonDb, this);
return true;
}
catch
{
//异常,没有json 解码失败
}
return false;
}
return false;
return FeedbackHeatJsonDb.Load(this, file_path);
}
void Save()
{
try
{
var jsonDb = FeedbackHeatJsonDb.Mapper.Map<FeedbackHeatJsonDb>(this);
string json = JsonConvert.SerializeObject(jsonDb, Formatting.Indented);
File.WriteAllText(file_path, json);
}
catch
{
//异常,没有json 编码失败
}
FeedbackHeatJsonDb.Save(this, file_path);
}
#region 撤销
......@@ -956,9 +904,45 @@ namespace FLY.FilmCasting.AutoDie.Server
});
}));
public static bool Load(FeedbackHeat src, string file_path)
{
if (!File.Exists(file_path))
return false;
try
{
string json = File.ReadAllText(file_path);
var jsonDb = JsonConvert.DeserializeObject<FeedbackHeatJsonDb>(json);
FeedbackHeatJsonDb.Mapper.Map(jsonDb, src);
return true;
}
catch
{
//异常,没有json 解码失败
return false;
}
}
public static bool Save(FeedbackHeat src, string file_path)
{
try
{
var jsonDb = FeedbackHeatJsonDb.Mapper.Map<FeedbackHeatJsonDb>(src);
string json = JsonConvert.SerializeObject(jsonDb, Formatting.Indented);
File.WriteAllText(file_path, json);
return true;
}
catch
{
//异常,没有json 编码失败
}
return false;
}
#region 参数
public string PLCep;
public string PLCep = "192.168.50.60:502";
/// <summary>
/// 加热后起效延时(s)
......@@ -987,10 +971,6 @@ namespace FLY.FilmCasting.AutoDie.Server
/// </summary>
public bool HasCheckFilmVelocity;
/// <summary>
/// 1块加热控制板 接多少路加热
/// </summary>
public int HeatsOfGroup = 12;
#endregion
}
......
......@@ -15,6 +15,7 @@ namespace FLY.FilmCasting.AutoDie.Server
class HeatCheck : IHeatCheck, INotifyPropertyChanged
{
const int HEAT_WAIT = 3;//3s
const int HeatsOfGroup = 12;//1块加热板 12路
HeatCell mHeatCell;
enum CHECK_MODE
......@@ -39,7 +40,7 @@ namespace FLY.FilmCasting.AutoDie.Server
CHECK_MODE checkMode = CHECK_MODE.IDLE;
int counter = 0;
#region IHeatCheck
public int HeatsOfGroup { get; set; } = 12;
/// <summary>
/// 有这个功能
/// </summary>
......
......@@ -40,17 +40,6 @@ namespace FLY.FilmCasting.AutoDie.Server
/// </summary>
public TimeSpan ActUpdateInterval { get; private set; }
/// <summary>
/// 加热通道数
/// </summary>
[DoNotCheckEquality]
public UInt16 ChannelCnt { get; set; }
/// <summary>
/// 加热量更新
/// </summary>
[DoNotCheckEquality]
public UInt16 HeatUpdate { get; set; }
/// <summary>
/// 当前电流 有没?
......@@ -65,8 +54,7 @@ namespace FLY.FilmCasting.AutoDie.Server
/// </summary>
public UInt16 HeatUpdate_R { get; private set; }
public int Errno { get; set; } = -1;
public bool IsConected { get; private set; }
public event PropertyChangedEventHandler PropertyChanged;
......@@ -84,7 +72,6 @@ namespace FLY.FilmCasting.AutoDie.Server
public PLCLink(IPEndPoint ep)
{
mclient = new Modbus.WithThread.ClientTCP(ep);
this.PropertyChanged += PLCLink_PropertyChanged;
}
class RegWrite
......@@ -102,30 +89,31 @@ namespace FLY.FilmCasting.AutoDie.Server
}
List<RegWrite> rws = new List<RegWrite>();
private void PLCLink_PropertyChanged(object sender, PropertyChangedEventArgs e)
public void SetChannelCnt(UInt16 channelCnt)
{
if (e.PropertyName == nameof(ChannelCnt))
if (!IsConected)
return;
//D200 4x201 通道数量
RegWrite regWrite = new RegWrite(PLCAddressArea.Register, 200, new UInt16[] { channelCnt });
lock (rws)
{
//D200 4x201 通道数量
RegWrite regWrite = new RegWrite(PLCAddressArea.Register, 200, new UInt16[] { ChannelCnt });
lock (rws)
{
rws.Add(regWrite);
}
rws.Add(regWrite);
}
else if (e.PropertyName == nameof(HeatUpdate))
}
public void SetHeatUpdate(UInt16 heatUpdate)
{
if (!IsConected)
return;
//D201 4x202 设置值 更新
RegWrite regWrite = new RegWrite(PLCAddressArea.Register, 201, new UInt16[] { heatUpdate });
lock (rws)
{
//D201 4x202 设置值 更新
RegWrite regWrite = new RegWrite(PLCAddressArea.Register, 201, new UInt16[] { HeatUpdate });
lock (rws)
{
rws.Add(regWrite);
}
rws.Add(regWrite);
}
}
public void Start()
{
lock (this)
......@@ -196,7 +184,7 @@ namespace FLY.FilmCasting.AutoDie.Server
goto _error;//连接断开,终止更新线程
}
Errno = 0;
IsConected = true;
}
//输出写入数据
......@@ -212,13 +200,13 @@ namespace FLY.FilmCasting.AutoDie.Server
}
_error:
Errno = -1;
IsConected = false;
ErrorCnt++;
goto _connect;
_end:
mclient.Close();
Errno = -1;
IsConected = true;
IsRunning = false;
}
......@@ -270,6 +258,9 @@ namespace FLY.FilmCasting.AutoDie.Server
/// <param name="values"></param>
public void SetHeat(IEnumerable<UInt16> values)
{
if (!IsConected)
return;
UInt16[] buf = values.ToArray();
List<RegWrite> writes = new List<RegWrite>();
//D400 4x401 设置值 160个
......
......@@ -57,7 +57,7 @@ namespace FLY.Thick.FilmCasting.Client
/// <summary>
/// 收缩率 Uniform(均匀区)Shrink(收缩)Percent(比例)
/// </summary>
public double UniformShrinkPercent { get; set; }
public double UniformShrinkPercent { get; set; } = 0.03;
/// <summary>
/// 膜中心位置偏移 mm
......@@ -67,12 +67,12 @@ namespace FLY.Thick.FilmCasting.Client
/// <summary>
/// 总分区数
/// </summary>
public int NBolts { get; set; }
public int NBolts { get; set; } = 100;
/// <summary>
/// 第1个分区号
/// </summary>
public int FirstBoltNo { get; set; }
public int FirstBoltNo { get; set; } = 1;
#endregion
......
......@@ -59,7 +59,7 @@ namespace FLY.Thick.FilmCasting.IService
/// 膜中心位置偏移 mm
/// </summary>
int MidOffset { get; }
/// <summary>
/// 总分区数
/// </summary>
......
Subproject commit f445c84c07690898037a1034fd1f1320c7907920
Subproject commit e1da25832b00c4020934eaa83041354b7d545cff
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment