Commit 064c0c51 authored by 潘栩锋's avatar 潘栩锋 🚴

1. 实际测试PLC,上料全部寄存读取,只需要0.07s

parent 52095453
...@@ -9,7 +9,7 @@ using System.Collections.ObjectModel; ...@@ -9,7 +9,7 @@ using System.Collections.ObjectModel;
using FLY.FeedbackRenZiJia.Common; using FLY.FeedbackRenZiJia.Common;
using FLY.Thick.Base.IService; using FLY.Thick.Base.IService;
using FLY.FeedbackRenZiJia.IService; using FLY.FeedbackRenZiJia.IService;
using System.Net;
namespace FLY.FeedbackRenZiJia.Client namespace FLY.FeedbackRenZiJia.Client
{ {
...@@ -24,6 +24,11 @@ namespace FLY.FeedbackRenZiJia.Client ...@@ -24,6 +24,11 @@ namespace FLY.FeedbackRenZiJia.Client
#region IFeedbackHeat 成员 #region IFeedbackHeat 成员
#region 参数 #region 参数
/// <summary>
/// 作为客户端模式
/// </summary>
public bool IsClient { get; set; }
public IPEndPoint PLCep { get; set; }
/// <summary> /// <summary>
/// 自动控制使能 /// 自动控制使能
......
...@@ -9,13 +9,19 @@ using FLY.Thick.Base.IService; ...@@ -9,13 +9,19 @@ using FLY.Thick.Base.IService;
using FObjBase; using FObjBase;
using FLY.Thick.RemoteHistory; using FLY.Thick.RemoteHistory;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Net;
namespace FLY.FeedbackRenZiJia.IService namespace FLY.FeedbackRenZiJia.IService
{ {
public interface IFeedbackHeat : INotifyPropertyChanged public interface IFeedbackHeat : INotifyPropertyChanged
{ {
#region 参数 #region 参数
/// <summary>
/// 作为客户端模式
/// </summary>
bool IsClient { get; set; }
IPEndPoint PLCep { get; set; }
/// <summary> /// <summary>
/// 自控使能, 不保存!!! /// 自控使能, 不保存!!!
/// </summary> /// </summary>
......
...@@ -14,6 +14,7 @@ using FLY.Thick.Base.IService; ...@@ -14,6 +14,7 @@ using FLY.Thick.Base.IService;
using FLY.FeedbackRenZiJia.IService; using FLY.FeedbackRenZiJia.IService;
using FLY.OBJComponents.Server; using FLY.OBJComponents.Server;
using FLY.OBJComponents.Common; using FLY.OBJComponents.Common;
using System.Net;
namespace FLY.FeedbackRenZiJia.Server namespace FLY.FeedbackRenZiJia.Server
{ {
...@@ -29,7 +30,11 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -29,7 +30,11 @@ namespace FLY.FeedbackRenZiJia.Server
#region IFeedbackHeat 成员 #region IFeedbackHeat 成员
#region 参数 #region 参数
/// <summary>
/// 作为客户端模式
/// </summary>
public bool IsClient { get; set; }
public IPEndPoint PLCep { get; set; }
/// <summary> /// <summary>
/// 自动控制使能 /// 自动控制使能
/// </summary> /// </summary>
...@@ -79,7 +84,7 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -79,7 +84,7 @@ namespace FLY.FeedbackRenZiJia.Server
/// <summary> /// <summary>
/// 当前 /// 当前
/// </summary> /// </summary>
public int[] Currs { get; set; } //public int[] Currs { get; set; }
#endregion #endregion
...@@ -130,9 +135,9 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -130,9 +135,9 @@ namespace FLY.FeedbackRenZiJia.Server
#endregion #endregion
#endregion #endregion
private IPLCLink plc;
private IPLCLink hmi;
private FLY.Thick.Blowing.IService.IBlowing renzijia; private FLY.Thick.Blowing.IService.IBlowing renzijia;
private FLY.Thick.Blowing.IService.IBlowingDetect mBDetect; private FLY.Thick.Blowing.IService.IBlowingDetect mBDetect;
private UInt16 CurrsUpdate=0; private UInt16 CurrsUpdate=0;
...@@ -156,14 +161,17 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -156,14 +161,17 @@ namespace FLY.FeedbackRenZiJia.Server
public FeedbackHeat() public FeedbackHeat()
{ {
hmi = new HMI(); PLCep = Misc.StringConverter.ToIPEndPoint("192.168.251.9:502");
hmi.PropertyChanged += new PropertyChangedEventHandler(hmi_PropertyChanged);
Misc.BindingOperations.SetBinding(hmi, "HasElectricity", this, "HasElectricity");
Misc.BindingOperations.SetBinding(hmi, "HasFan", this, "HasFan");
Load(); Load();
if (IsClient)
plc = new PLCLink(PLCep);
else
plc = new HMI();
plc.PropertyChanged += new PropertyChangedEventHandler(hmi_PropertyChanged);
Misc.BindingOperations.SetBinding(plc, "HasElectricity", this, "HasElectricity");
Misc.BindingOperations.SetBinding(plc, "HasFan", this, "HasFan");
InitBuf(); InitBuf();
...@@ -230,7 +238,7 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -230,7 +238,7 @@ namespace FLY.FeedbackRenZiJia.Server
mHeatCheck.Init(mHeatCell); mHeatCheck.Init(mHeatCell);
mHeatCheck.PropertyChanged += new PropertyChangedEventHandler(mHeatCheck_PropertyChanged); mHeatCheck.PropertyChanged += new PropertyChangedEventHandler(mHeatCheck_PropertyChanged);
Misc.BindingOperations.SetBinding(hmi, "HasElectricity", mHeatCheck, "HasElectricity"); Misc.BindingOperations.SetBinding(plc, "HasElectricity", mHeatCheck, "HasElectricity");
Misc.BindingOperations.SetBinding(this, "HasCheck", mHeatCheck, "Has"); Misc.BindingOperations.SetBinding(this, "HasCheck", mHeatCheck, "Has");
Misc.BindingOperations.SetBinding(mHeatCheck, "Enable", this, "CheckEnable", Misc.BindingOperations.BindingMode.TwoWay); Misc.BindingOperations.SetBinding(mHeatCheck, "Enable", this, "CheckEnable", Misc.BindingOperations.BindingMode.TwoWay);
Misc.BindingOperations.SetBinding(mHeatCheck, "CheckNo", this, "CheckNo"); Misc.BindingOperations.SetBinding(mHeatCheck, "CheckNo", this, "CheckNo");
...@@ -374,8 +382,8 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -374,8 +382,8 @@ namespace FLY.FeedbackRenZiJia.Server
void InitBuf() void InitBuf()
{ {
hmi.ChannelCnt = (UInt16)ChannelCnt; plc.ChannelCnt = (UInt16)ChannelCnt;
Currs = new int[ChannelCnt]; //Currs = new int[ChannelCnt];
mHeatChanged.Init(ChannelCnt); mHeatChanged.Init(ChannelCnt);
mHeatBuf.Init(NBolts, ChannelCnt); mHeatBuf.Init(NBolts, ChannelCnt);
mHeatCell.Init2(NBolts, ChannelCnt); mHeatCell.Init2(NBolts, ChannelCnt);
...@@ -386,44 +394,20 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -386,44 +394,20 @@ namespace FLY.FeedbackRenZiJia.Server
} }
void hmi_PropertyChanged(object sender, PropertyChangedEventArgs e) void hmi_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "CurrUpdate") if (e.PropertyName == "Errno")
{ {
if (hmi.CurrUpdate != CurrsUpdate) if (plc.Errno == -1)
{ {
CurrsUpdate = hmi.CurrUpdate;
bool isupdate = false;
IEnumerable<UInt16> list = hmi.GetCurr();
//更新了
for (int i = 0; i < ChannelCnt && i< list.Count(); i++)
{
if (Currs[i] != list.ElementAt(i))
{
Currs[i] = list.ElementAt(i);
isupdate = true;
}
}
if (isupdate)
{
NotifyPropertyChanged("Currs");
//把Currs 复制到 HeatCell.Heats
mHeatCell.ModifyHeats(Currs);
}
}
}
else if (e.PropertyName == "Errno")
{
if (hmi.Errno == -1)
IsConnectedWithPLC = false; IsConnectedWithPLC = false;
}
else else
{ {
IsConnectedWithPLC = true; IsConnectedWithPLC = true;
//刚成功连接上 //刚成功连接上
//把Currs 复制到 HeatCell.Heats //重新复制数据到 PLC
//mHeatCell.ModifyHeats(Currs); RecoverPLC();
} }
} }
} }
...@@ -643,10 +627,11 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -643,10 +627,11 @@ namespace FLY.FeedbackRenZiJia.Server
} }
UInt16[] last_heat;
UInt16 last_heatupdate;
void Output(int[] heats) void Output(int[] heats)
{ {
List<UInt16> list = new List<UInt16>(); List<UInt16> list = new List<UInt16>();
for (int i = 0; i < ChannelCnt; i++) for (int i = 0; i < ChannelCnt; i++)
{ {
UInt16 heat = (UInt16)heats[i]; UInt16 heat = (UInt16)heats[i];
...@@ -656,13 +641,33 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -656,13 +641,33 @@ namespace FLY.FeedbackRenZiJia.Server
heat = 100; heat = 100;
list.Add(heat); list.Add(heat);
} }
hmi.SetHeat(list); plc.SetHeat(list);
UInt16 heatupdate = (UInt16)(hmi.HeatUpdate + 1); last_heat = list.ToArray();
UInt16 heatupdate = (UInt16)(plc.HeatUpdate + 1);
if (heatupdate == 0) if (heatupdate == 0)
heatupdate = 1; heatupdate = 1;
hmi.HeatUpdate = heatupdate; plc.HeatUpdate = heatupdate;
last_heatupdate = heatupdate;
}
void RecoverPLC()
{
plc.ChannelCnt = (UInt16)ChannelCnt;
if (last_heat != null)
{
plc.SetHeat(last_heat);
plc.HeatUpdate = last_heatupdate;
}
else
{
//设置全部0进去
plc.SetHeat(new UInt16[ChannelCnt]);
plc.HeatUpdate = plc.HeatUpdate;
}
} }
void Add(DateTime time, DateTime endtime, Misc.DIRECTION direction, TimeSpan period, int rotateCnt, void Add(DateTime time, DateTime endtime, Misc.DIRECTION direction, TimeSpan period, int rotateCnt,
int orgboltno, double rAngle, double filmLength, int orgboltno, double rAngle, double filmLength,
int[] frame) int[] frame)
......
...@@ -79,10 +79,11 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -79,10 +79,11 @@ namespace FLY.FeedbackRenZiJia.Server
#endregion #endregion
#region 状态 #region 状态
public int Errno { get; set; } public int Errno { get; set; } = -1;
#endregion #endregion
bool IsRunning; bool IsRunning;
public PLCLink(IPEndPoint ep) public PLCLink(IPEndPoint ep)
{ {
mclient = new Modbus.WithThread.ClientTCP(ep); mclient = new Modbus.WithThread.ClientTCP(ep);
...@@ -106,6 +107,8 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -106,6 +107,8 @@ namespace FLY.FeedbackRenZiJia.Server
List<RegWrite> rws = new List<RegWrite>(); List<RegWrite> rws = new List<RegWrite>();
private ushort _channelCnt; private ushort _channelCnt;
private ushort _heatUpdate; private ushort _heatUpdate;
private UInt16[] heats=null;
private void PLCLink_PropertyChanged(object sender, PropertyChangedEventArgs e) private void PLCLink_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
...@@ -163,13 +166,16 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -163,13 +166,16 @@ namespace FLY.FeedbackRenZiJia.Server
stopwatch.Restart(); stopwatch.Restart();
if (!UpdateReadData()) if (!UpdateReadData())
return;//连接断开,终止更新线程 break;//连接断开,终止更新线程
Errno = 0;
} }
//输出写入数据 //输出写入数据
if (!UpdateWriteData()) if (!UpdateWriteData())
return;//连接断开,终止更新线程 break;//连接断开,终止更新线程
Thread.Sleep(100); Thread.Sleep(100);
} }
Errno = -1;
IsRunning = false; IsRunning = false;
} }
...@@ -220,7 +226,7 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -220,7 +226,7 @@ namespace FLY.FeedbackRenZiJia.Server
{ {
rws.Add(regWrite); rws.Add(regWrite);
} }
heats = buf;
} }
/// <summary> /// <summary>
...@@ -229,7 +235,12 @@ namespace FLY.FeedbackRenZiJia.Server ...@@ -229,7 +235,12 @@ namespace FLY.FeedbackRenZiJia.Server
/// <returns></returns> /// <returns></returns>
public IEnumerable<UInt16> GetCurr() public IEnumerable<UInt16> GetCurr()
{ {
return null; UInt16[] curr = new UInt16[ChannelCnt];
if (ChannelCnt != 0 && heats!=null)
{
Array.Copy(heats, curr, Math.Min(ChannelCnt, heats.Count()));
}
return curr;
} }
} }
} }
...@@ -10,8 +10,8 @@ namespace FLY.Modbus ...@@ -10,8 +10,8 @@ namespace FLY.Modbus
/// <summary> /// <summary>
/// 现在工作中的读取计划任务 /// 现在工作中的读取计划任务
/// </summary> /// </summary>
protected List<Plan> plan = new List<Plan>(); public List<Plan> plan = new List<Plan>();
/// <summary> /// <summary>
/// 当true, plan_buffer -> plan /// 当true, plan_buffer -> plan
/// </summary> /// </summary>
......
...@@ -118,7 +118,7 @@ namespace FLY.Modbus ...@@ -118,7 +118,7 @@ namespace FLY.Modbus
{ {
Pack_Proto p = new Pack_Proto(); Pack_Proto p = new Pack_Proto();
int rlen; int rlen;
if (!p.TryParse(inBuf, startIndex, out rlen)) if (!p.TryParse(inBuf, startIndex, inBuf.Length, out rlen))
{ {
//处理失败 //处理失败
return startIndex; return startIndex;
......
...@@ -15,7 +15,7 @@ namespace FLY.Modbus ...@@ -15,7 +15,7 @@ namespace FLY.Modbus
/// 一次读取的数据量 /// 一次读取的数据量
/// </summary> /// </summary>
const int MaxRegsOfOneRead = 100; const int MaxRegsOfOneRead = 100;
const int MaxCoilsOfOneRead = 9000; const int MaxCoilsOfOneRead = 900;
#region 数据变化通知 #region 数据变化通知
/// <summary> /// <summary>
......
...@@ -65,7 +65,7 @@ namespace FLY.Modbus ...@@ -65,7 +65,7 @@ namespace FLY.Modbus
return buf.ToArray(); return buf.ToArray();
} }
public bool TryParse(byte[] value, int startIndex, out int rlen) public bool TryParse(byte[] value, int startIndex, int value_len, out int rlen)
{ {
//格式—————————————— //格式——————————————
//MBAP //MBAP
...@@ -82,7 +82,7 @@ namespace FLY.Modbus ...@@ -82,7 +82,7 @@ namespace FLY.Modbus
rlen = 0; rlen = 0;
int cnt = 7 + 1; int cnt = 7 + 1;
if (value.Count() < cnt) if (value_len < cnt)
return false; return false;
int index = startIndex; int index = startIndex;
tranid = COMMON.ToUInt16_Big_endian(value, index); tranid = COMMON.ToUInt16_Big_endian(value, index);
...@@ -94,7 +94,7 @@ namespace FLY.Modbus ...@@ -94,7 +94,7 @@ namespace FLY.Modbus
index += 2; index += 2;
cnt += len - 2; cnt += len - 2;
if (value.Count() < cnt) if (value_len < cnt)
return false; return false;
unitid = value[index]; unitid = value[index];
......
...@@ -19,7 +19,7 @@ namespace FLY.Modbus.WithThread ...@@ -19,7 +19,7 @@ namespace FLY.Modbus.WithThread
/// <summary> /// <summary>
/// 通信超时, 默认是 1s /// 通信超时, 默认是 1s
/// </summary> /// </summary>
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(1); public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(2);
/// <summary> /// <summary>
/// socket 错误信息,带时间 /// socket 错误信息,带时间
/// </summary> /// </summary>
...@@ -61,47 +61,60 @@ namespace FLY.Modbus.WithThread ...@@ -61,47 +61,60 @@ namespace FLY.Modbus.WithThread
public ClientTCP(IPEndPoint ep) public ClientTCP(IPEndPoint ep)
{ {
RemoteEP = ep; RemoteEP = ep;
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Connect(true);
} }
bool isconnecting = false; /// <summary>
void Connect(bool isImmediately) /// 工作中
/// </summary>
public bool IsRunning { get; private set; }
/// <summary>
/// 用于停止Task
/// </summary>
CancellationTokenSource cts;
/// <summary>
/// 建立连接
/// </summary>
public void Connect()
{ {
if (isconnecting) if (IsRunning)
return; return;
IsRunning = true;
isconnecting = true; IsConnected = false;
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Task task = new Task((state) => cts = new CancellationTokenSource();
Task.Factory.StartNew(() =>
{ {
bool isImme = (bool)state; while (true)
if (!isImme)//不需要立刻连接,等待3秒后重试
Thread.Sleep(3000);
while (!IsConnected)
{ {
lock (this) if (cts.IsCancellationRequested)//被主动申请断开
break;
try
{ {
try sock.Connect(RemoteEP);
{ IsConnected = true;
sock.Connect(RemoteEP); break;
IsConnected = true;
}
catch(Exception e)
{
ErrMsg = e.Message;
}
} }
if (!IsConnected) catch(Exception e)
Thread.Sleep(3000); {
ErrMsg = e.Message;
}
//连接失败,等待再尝试
Thread.Sleep(1000);
} }
isconnecting = false; });
}, isImmediately); }
/// <summary>
task.Start(); /// 停止
/// </summary>
public void Stop()
{
if (!IsRunning)
return;
IsRunning = false;
sock.Close();
IsConnected = false;
cts.Cancel();
} }
bool TranExecute(Pack_Proto request, out Pack_Proto reponse) bool TranExecute(Pack_Proto request, out Pack_Proto reponse)
{ {
...@@ -126,36 +139,27 @@ namespace FLY.Modbus.WithThread ...@@ -126,36 +139,27 @@ namespace FLY.Modbus.WithThread
goto _end; goto _end;
} }
byte[] recvBytes = new byte[sock.ReceiveBufferSize];//回复的指令不可能大于2K
sock.ReceiveTimeout = (int)Timeout.TotalMilliseconds;
int offset = 0;
//读取数据 //读取数据
while (true) while (true)
{ {
byte[] recvBytes = new byte[2048];//回复的指令不可能大于2K
sock.ReceiveTimeout = (int)Timeout.TotalMilliseconds; int size = recvBytes.Length - offset;
int offset = 0;
if (size <= 0)
{
//异常
ErrMsg = "TimeOut";
IsConnected = false;
goto _end;
}
int bytes=0;
try try
{ {
int size = recvBytes.Length - offset; bytes = sock.Receive(recvBytes, offset, size, SocketFlags.None);//从客户端接受信息,可能会分了多次接收
if (size <= 0)
{
//异常
ErrMsg = "TimeOut";
IsConnected = false;
goto _end;
}
int bytes = sock.Receive(recvBytes, offset, recvBytes.Length, 0);//从客户端接受信息
//可能会分了多次接收
if (!reponse.TryParse(recvBytes, 0, out int rlen))
{
//处理失败,数据不够,继续接收
offset = bytes;
}
else
{
break;
}
} }
catch (SocketException e) catch (SocketException e)
{ {
...@@ -164,12 +168,34 @@ namespace FLY.Modbus.WithThread ...@@ -164,12 +168,34 @@ namespace FLY.Modbus.WithThread
IsConnected = false; IsConnected = false;
goto _end; goto _end;
} }
if (bytes == 0)
{
//超时,或已经断开连接
ErrMsg = "TimeOut";
IsConnected = false;
goto _end;
}
if (!reponse.TryParse(recvBytes, 0, bytes, out int rlen))
{
//处理失败,数据不够,继续接收
offset = bytes;
}
else
{
break;
}
} }
} }
_end: _end:
if (!IsConnected) if (!IsConnected)
{ {
Connect(false); sock.Close();
if (IsRunning)
{
IsRunning = false;
Connect();
}
return false; return false;
} }
else else
......
...@@ -28,8 +28,11 @@ namespace FLY.Modbus.WithThread ...@@ -28,8 +28,11 @@ namespace FLY.Modbus.WithThread
/// 工作中 /// 工作中
/// </summary> /// </summary>
public bool IsRunning { get; private set; } public bool IsRunning { get; private set; }
/// <summary>
/// 异常次数
/// </summary>
public int ErrorCnt { get; private set; }
class RegWrite class RegWrite
{ {
public PLCAddressArea dataArea; public PLCAddressArea dataArea;
...@@ -58,8 +61,6 @@ namespace FLY.Modbus.WithThread ...@@ -58,8 +61,6 @@ namespace FLY.Modbus.WithThread
{ {
mclient = clienttcp; mclient = clienttcp;
mclient.PropertyChanged += Mclient_PropertyChanged; mclient.PropertyChanged += Mclient_PropertyChanged;
Start();
} }
...@@ -90,35 +91,55 @@ namespace FLY.Modbus.WithThread ...@@ -90,35 +91,55 @@ namespace FLY.Modbus.WithThread
} }
} }
} }
void Start() public void Start()
{
if (!mclient.IsRunning)
{
mclient.Connect();
}
else
{
if (IsRunning)
return;
IsRunning = true;
Task.Factory.StartNew(OnPoll_update);
}
}
/// <summary>
/// 停止
/// </summary>
public void Stop()
{ {
if (IsRunning) if (!IsRunning)
return; return;
Task.Factory.StartNew(OnPoll_update); mclient.Stop();
} }
void OnPoll_update() void OnPoll_update()
{ {
IsRunning = true;
Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (mclient.IsConnected) while (mclient.IsConnected)
{ {
if (stopwatch.ElapsedMilliseconds >= UpdateInterval) if (stopwatch.ElapsedMilliseconds >= UpdateInterval)
{ {
//检查上次更新周期是否完成 //检查上次更新周期是否完成
ActUpdateInterval = stopwatch.Elapsed; TimeSpan elapsed = stopwatch.Elapsed;
ActUpdateInterval = elapsed;
stopwatch.Restart(); stopwatch.Restart();
if (!UpdateReadData()) if (!UpdateReadData())
return;//连接断开,终止更新线程 break;//连接断开,终止更新线程
} }
//输出写入数据 //输出写入数据
if (!UpdateWriteData()) if (!UpdateWriteData())
return;//连接断开,终止更新线程 break;//连接断开,终止更新线程
Thread.Sleep(0); Thread.Sleep(10);
} }
IsRunning = false; IsRunning = false;
ErrorCnt++;
} }
/// <summary> /// <summary>
...@@ -132,11 +153,10 @@ namespace FLY.Modbus.WithThread ...@@ -132,11 +153,10 @@ namespace FLY.Modbus.WithThread
areaManager.MakePlanReal(); areaManager.MakePlanReal();
} }
int curr_area_idx = 0; //int curr_area_idx = 0;
while (true) foreach (var areaManager in mAreaManager)
{ {
Plan p_doing = mAreaManager[curr_area_idx].GetNextPlan(); foreach(Plan p_doing in areaManager.plan)
if (p_doing != null)
{ {
switch (p_doing.area) switch (p_doing.area)
{ {
...@@ -156,17 +176,42 @@ namespace FLY.Modbus.WithThread ...@@ -156,17 +176,42 @@ namespace FLY.Modbus.WithThread
break; break;
} }
} }
else
{
//读完
curr_area_idx++;
if (curr_area_idx >= mAreaManager.Count())
{
//读完一轮了
return true;
}
}
} }
return true;
// while (true)
//{
// Plan p_doing = mAreaManager[curr_area_idx].GetNextPlan();
// if (p_doing != null)
// {
// switch (p_doing.area)
// {
// case PLCAddressArea.Coil:
// {
// if (!mclient.Do_01(p_doing.addr, p_doing.num, out IEnumerable<bool> values))
// return false;
// SetModbusData(PLCAddressArea.Coil, p_doing.addr, values);
// }
// break;
// case PLCAddressArea.Register:
// {
// if (!mclient.Do_03(p_doing.addr, p_doing.num, out IEnumerable<UInt16> values))
// return false;
// SetModbusData(PLCAddressArea.Register, p_doing.addr, values);
// }
// break;
// }
// }
// else
// {
// //读完
// curr_area_idx++;
// if (curr_area_idx >= mAreaManager.Count())
// {
// //读完一轮了
// return true;
// }
// }
//}
} }
/// <summary> /// <summary>
...@@ -404,6 +449,10 @@ namespace FLY.Modbus.WithThread ...@@ -404,6 +449,10 @@ namespace FLY.Modbus.WithThread
dr.isNeedUpdate = true; dr.isNeedUpdate = true;
} }
} }
//foreach (DataToRegs dr in DRmap)
//{
// dr.isNeedUpdate = true;
//}
DRNeedUpdateCnt = DRmap.Count((dr) => dr.isNeedUpdate); DRNeedUpdateCnt = DRmap.Count((dr) => dr.isNeedUpdate);
foreach (var areaManager in mAreaManager) foreach (var areaManager in mAreaManager)
......
...@@ -69,6 +69,10 @@ namespace FLY.OBJComponents.Server ...@@ -69,6 +69,10 @@ namespace FLY.OBJComponents.Server
FObjBase.PollModule.Current.Poll_Config(FObjBase.PollModule.POLL_CONFIG.ADD, FObjBase.PollModule.Current.Poll_Config(FObjBase.PollModule.POLL_CONFIG.ADD,
OnPoll_plans, TimeSpan.FromSeconds(1)); OnPoll_plans, TimeSpan.FromSeconds(1));
//启动!!!!
foreach (var plc in PLCs)
plc.Start();
} }
private void Obj_PropertyChanged(object sender, PropertyChangedEventArgs e) private void Obj_PropertyChanged(object sender, PropertyChangedEventArgs e)
......
<Window x:Class="FLY.Weight.UI.Server.MainWindow" <Window x:Class="FLY.Weight.UI.Server.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" ResizeMode="NoResize" SizeToContent="WidthAndHeight" > Title="MainWindow" ResizeMode="NoResize" SizeToContent="WidthAndHeight" MinHeight="80" MinWidth="200">
<Grid> <Grid>
<Grid x:Name="grid_plc"/> <Grid x:Name="grid_plc"/>
<Grid x:Name="grid_plcos"/> <Grid x:Name="grid_plcos"/>
<Grid x:Name="grid_WeightSystem"/> <Grid x:Name="grid_WeightSystem"/>
<StackPanel Orientation="Vertical" Margin="5"> <StackPanel Orientation="Vertical" Margin="5">
<ItemsControl x:Name="itemcontrol">
<StackPanel Orientation="Horizontal" > <ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal" >
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="更新速度" />
<TextBlock FontSize="20">
<Run Text="{Binding ActUpdateInterval,StringFormat=\{0:sfff\}, Mode=OneWay}" />
<Run Text="ms" FontSize="15"/>
</TextBlock>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="PLC连接状态" />
<TextBlock Text="{Binding IsRunning}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="异常次数" />
<TextBlock Text="{Binding ErrorCnt}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="寄存器更新数" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DRNeedUpdateCnt}" FontSize="20"/>
<TextBlock Text="/"/>
<TextBlock Text="{Binding DRCnt}" FontSize="20"/>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--<StackPanel Orientation="Horizontal" >
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}"> <StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="更新速度" /> <TextBlock Text="更新速度" />
<TextBlock Text="{Binding ActUpdateInterval}" FontSize="20"/> <TextBlock Text="{Binding ActUpdateInterval}" FontSize="20"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plcos}"> <StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plcos}">
<TextBlock Text="PLC连接状态" /> <TextBlock Text="PLC连接状态" />
<TextBlock Text="{Binding IsConnectedWithPLC}" FontSize="20"/> <TextBlock Text="{Binding IsRunning}" FontSize="20"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}"> <StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="寄存器更新数" /> <TextBlock Text="寄存器更新数" />
...@@ -26,7 +58,7 @@ ...@@ -26,7 +58,7 @@
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>-->
</StackPanel> </StackPanel>
</Grid> </Grid>
......
...@@ -40,12 +40,13 @@ namespace FLY.Weight.UI.Server ...@@ -40,12 +40,13 @@ namespace FLY.Weight.UI.Server
mTDGage = new TDGage("Gage1"); mTDGage = new TDGage("Gage1");
this.DataContext = mTDGage.mData.Items[0]; //this.DataContext = mTDGage.mData.Items[0];
FLY.OBJComponents.Server.PLCProxySystem plsos = FLY.OBJComponents.Server.PLCProxySystem plsos =
mTDGage.mData.PLCos as FLY.OBJComponents.Server.PLCProxySystem; mTDGage.mData.PLCos as FLY.OBJComponents.Server.PLCProxySystem;
grid_plcos.DataContext = plsos; //grid_plcos.DataContext = plsos;
grid_plc.DataContext = plsos.PLCs[0]; //grid_plc.DataContext = plsos.PLCs[0];
grid_WeightSystem.DataContext = mTDGage.mData; //grid_WeightSystem.DataContext = mTDGage.mData;
this.itemcontrol.ItemsSource = plsos.PLCs;
} }
} }
} }
...@@ -184,6 +184,7 @@ namespace FLY.Weight.Server ...@@ -184,6 +184,7 @@ namespace FLY.Weight.Server
this.PropertyChanged += WeightSystem_PropertyChanged; this.PropertyChanged += WeightSystem_PropertyChanged;
FObjBase.PollModule.Current.Poll_Config(PollModule.POLL_CONFIG.ADD, OnPoll_SaveMix, TimeSpan.FromSeconds(1)); FObjBase.PollModule.Current.Poll_Config(PollModule.POLL_CONFIG.ADD, OnPoll_SaveMix, TimeSpan.FromSeconds(1));
} }
void OnPoll_SaveMix() void OnPoll_SaveMix()
{ {
...@@ -566,7 +567,14 @@ namespace FLY.Weight.Server ...@@ -566,7 +567,14 @@ namespace FLY.Weight.Server
var plc = new Modbus.WithThread.ModbusMapper_Client(new Modbus.WithThread.ClientTCP(device.EP)); var plc = new Modbus.WithThread.ModbusMapper_Client(new Modbus.WithThread.ClientTCP(device.EP));
plcos.PLCs.Add(plc); plcos.PLCs.Add(plc);
} }
//测试---
//只加载第1个
{
//var plc = new Modbus.WithThread.ModbusMapper_Client(new Modbus.WithThread.ClientTCP(plcgroup.Devices[1].EP));
//plcos.PLCs.Add(plc);
//plc = new Modbus.WithThread.ModbusMapper_Client(new Modbus.WithThread.ClientTCP(plcgroup.Devices[1].EP));
//plcos.PLCs.Add(plc);
}
List<int> bincnts = new List<int>(); List<int> bincnts = new List<int>();
Regex r = new Regex(@"Items\[([0-9])\]"); Regex r = new Regex(@"Items\[([0-9])\]");
Regex r2 = new Regex("MixPSet_([1-9])"); Regex r2 = new Regex("MixPSet_([1-9])");
...@@ -631,6 +639,9 @@ namespace FLY.Weight.Server ...@@ -631,6 +639,9 @@ namespace FLY.Weight.Server
foreach (var plc in plcos.PLCs) foreach (var plc in plcos.PLCs)
plc.Build(); plc.Build();
} }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
......
...@@ -65,6 +65,7 @@ namespace FLY.Winder.Server ...@@ -65,6 +65,7 @@ namespace FLY.Winder.Server
InitError(); InitError();
plcos.Init(); plcos.Init();
} }
#region 报警 #region 报警
class ErrorAction class ErrorAction
......
$root_path = $PSScriptRoot
$src_path = $root_path + "\WS_local_test.xml"
$dest_dir = $root_path + "\..\..\..\..\Project.FLY.Weight\FLY.Weight.UI.Server\bin\Debug\Gage1"
$dest_path = $dest_dir + "\WS.xml"
if(-not (Test-Path $dest_dir))
{
echo $dest_dir
mkdir $dest_dir
}
echo WS.xml
cp $src_path $dest_path
echo Ƴɹ
pause
\ No newline at end of file
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