change-泡后库plc心跳及重连

foamRearStore
liuwf 8 months ago
parent 6095b45802
commit 3022b935fb

Binary file not shown.

@ -62,7 +62,7 @@ namespace Aucma.Scada.Business
#endregion #endregion
#region 私有变量 #region 私有变量
private Dictionary<string, IPlc> _plcDictionary = new Dictionary<string, IPlc>(); private static Dictionary<string, IPlc> _plcDictionary = new Dictionary<string, IPlc>();
private Dictionary<string, int> foamRearKeyValuePairs = new Dictionary<string, int>(); private Dictionary<string, int> foamRearKeyValuePairs = new Dictionary<string, int>();
/// <summary> /// <summary>
/// 泡后任务编号,PLC反馈后进行赋值 /// 泡后任务编号,PLC反馈后进行赋值
@ -134,6 +134,7 @@ namespace Aucma.Scada.Business
Thread.Sleep(2000); Thread.Sleep(2000);
while (true) while (true)
{ {
List<BaseSpaceInfo> spaceList = _spaceInfoService.GetSpaceInfosByStoreCode(appConfig.foamStoreCode); List<BaseSpaceInfo> spaceList = _spaceInfoService.GetSpaceInfosByStoreCode(appConfig.foamStoreCode);
if (spaceList != null && spaceList.Count > 0) if (spaceList != null && spaceList.Count > 0)
{ {
@ -199,19 +200,25 @@ namespace Aucma.Scada.Business
try try
{ {
Thread.Sleep(3000); Thread.Sleep(3000);
IPlc _plc = _plcDictionary[appConfig.foamStoreCode];
if (_plc != null) while (true)
{ {
while (true) Console.Write(_plcDictionary.Count);
_plcDictionary = _pool.GetAll();
if (_plcDictionary.Count == 0)
{ {
_plc.writeInt32ByAddress("D7020", 1); Thread.Sleep(5000);
Thread.Sleep(1000); continue;
_plc.writeInt32ByAddress("D7020", 0);
Thread.Sleep(1000);
} }
IPlc _plc = _plcDictionary[appConfig.foamStoreCode];
if (_plc != null)
{
_plc.writeInt32ByAddress("D7020", 1);
Thread.Sleep(1000);
_plc.writeInt32ByAddress("D7020", 0);
Thread.Sleep(1000);
}
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -480,17 +487,22 @@ namespace Aucma.Scada.Business
public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo) public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo)
{ {
var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode); var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode);
IPlc _plc = _plcDictionary[spaceInfo.storeCode]; _plcDictionary = _pool.GetAll();
if (_plcDictionary.Count > 0)
if (_plc != null)
{ {
spaceInfo.spaceStock = _plc.readInt32ByAddress(spaceAddress.onStore); IPlc _plc = _plcDictionary[spaceInfo.storeCode];
spaceInfo.onRouteAmount = _plc.readInt32ByAddress(spaceAddress.onRoute);
// spaceInfo.spaceStatus = _plc.readInt32ByAddress(spaceAddress.spaceStatus);
} if (_plc != null)
{
spaceInfo.spaceStock = _plc.readInt32ByAddress(spaceAddress.onStore);
spaceInfo.onRouteAmount = _plc.readInt32ByAddress(spaceAddress.onRoute);
// spaceInfo.spaceStatus = _plc.readInt32ByAddress(spaceAddress.spaceStatus);
}
}
return spaceInfo; return spaceInfo;
} }

@ -43,6 +43,7 @@ namespace Aucma.Scada.Business
{ {
//初始化Plc //初始化Plc
plcPool.InitPlc("MelsecBinaryPlc", plcConfig.foam_Plc_Ip, plcConfig.foam_Plc_Port, appConfig.foamStoreCode); plcPool.InitPlc("MelsecBinaryPlc", plcConfig.foam_Plc_Ip, plcConfig.foam_Plc_Port, appConfig.foamStoreCode);
plcPool.StartMelsecPlcAsync();
} }
/// <summary> /// <summary>

@ -60,7 +60,7 @@ namespace Aucma.Scada.Business
/// <summary> /// <summary>
/// 字典存放PLC连接 /// 字典存放PLC连接
/// </summary> /// </summary>
private Dictionary<string, IPlc> _plcDictionary = new Dictionary<string, IPlc>(); private static Dictionary<string, IPlc> _plcDictionary = new Dictionary<string, IPlc>();
@ -99,6 +99,7 @@ namespace Aucma.Scada.Business
RealTaskInfo task = GetTaskInfoByTaskStatus(appConfig.foamStoreCode).OrderBy(x => x.createTime).FirstOrDefault(); RealTaskInfo task = GetTaskInfoByTaskStatus(appConfig.foamStoreCode).OrderBy(x => x.createTime).FirstOrDefault();
if(task != null) if(task != null)
{ {
_plcDictionary = _pool.GetAll();
if (_plcDictionary.Count > 0) if (_plcDictionary.Count > 0)
{ {
IPlc _plc = _plcDictionary[appConfig.foamStoreCode]; IPlc _plc = _plcDictionary[appConfig.foamStoreCode];
@ -156,6 +157,7 @@ namespace Aucma.Scada.Business
int result = 0; int result = 0;
try try
{ {
_plcDictionary = _pool.GetAll();
IPlc _plc = _plcDictionary[taskInfo.storeCode]; IPlc _plc = _plcDictionary[taskInfo.storeCode];
if (_plc != null) if (_plc != null)
@ -202,6 +204,7 @@ namespace Aucma.Scada.Business
lock (string.Empty) lock (string.Empty)
{ {
bool isFlag = true; bool isFlag = true;
_plcDictionary = _pool.GetAll();
IPlc _plc = _plcDictionary[appConfig.foamStoreCode]; IPlc _plc = _plcDictionary[appConfig.foamStoreCode];
try try
{ {
@ -257,6 +260,7 @@ namespace Aucma.Scada.Business
public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo) public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo)
{ {
var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode); var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode);
_plcDictionary = _pool.GetAll();
IPlc _plc = _plcDictionary[spaceInfo.storeCode]; IPlc _plc = _plcDictionary[spaceInfo.storeCode];
if (_plc != null) if (_plc != null)

@ -8,7 +8,7 @@ namespace Aucma.Scada.Business
/// <summary> /// <summary>
/// 注册服务 /// 注册服务
/// </summary> /// </summary>
internal sealed class RegisterServices public sealed class RegisterServices
{ {
#region 单例实现 #region 单例实现
private static readonly Lazy<RegisterServices> lazy = new Lazy<RegisterServices>(() => new RegisterServices()); private static readonly Lazy<RegisterServices> lazy = new Lazy<RegisterServices>(() => new RegisterServices());

@ -57,6 +57,7 @@
<Compile Include="domain\RecordOutstore.cs" /> <Compile Include="domain\RecordOutstore.cs" />
<Compile Include="domain\RecordProductfinish.cs" /> <Compile Include="domain\RecordProductfinish.cs" />
<Compile Include="domain\SysUserInfo.cs" /> <Compile Include="domain\SysUserInfo.cs" />
<Compile Include="domain\WorkTime.cs" />
<Compile Include="dto\FoamStoreStockDto.cs" /> <Compile Include="dto\FoamStoreStockDto.cs" />
<Compile Include="dto\OperationType.cs" /> <Compile Include="dto\OperationType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Aucma.Scada.UI.Model namespace Aucma.Scada.Model.domain
{ {
/// <summary> /// <summary>
/// ///

@ -1 +1 @@
0950971ed41497fad7d277ed90ba33c6b3992ef2 c1df4a405465ec99296e7191ac19178349a56569

@ -100,7 +100,6 @@
<Compile Include="Converter\TaskInfo\TaskStatusConverter.cs" /> <Compile Include="Converter\TaskInfo\TaskStatusConverter.cs" />
<Compile Include="Converter\TaskInfo\TaskTypeConverter.cs" /> <Compile Include="Converter\TaskInfo\TaskTypeConverter.cs" />
<Compile Include="Model\typeGridModel.cs" /> <Compile Include="Model\typeGridModel.cs" />
<Compile Include="Model\WorkTime.cs" />
<Compile Include="Page\AssemblyPlan\AssemblyPlanControl.xaml.cs"> <Compile Include="Page\AssemblyPlan\AssemblyPlanControl.xaml.cs">
<DependentUpon>AssemblyPlanControl.xaml</DependentUpon> <DependentUpon>AssemblyPlanControl.xaml</DependentUpon>
</Compile> </Compile>

@ -0,0 +1,14 @@
[plcSystem]
泡后PLCIP=127.0.0.1
泡后PLC端口=6000
[foam_inStore_address]
入库货道号=D7000
入库应答字=D7010
[foam_outStore_address]
出库货道号=D7100
出库数量=D7110
出库应答字=D7130
出库完成=D7120

@ -1 +1 @@
03944b5825fa0e59c458aa58e375ee42c7ce2f0f f0687ef2739d6b9de0b1c9bfa00adaa2c57e1d99

@ -12,7 +12,7 @@ DEBUG;TRACE
E:\c#\AUCMA\最新代码整合\泡后库\foam\Aucma.Scada.UI\App.xaml E:\c#\AUCMA\最新代码整合\泡后库\foam\Aucma.Scada.UI\App.xaml
19-2058867325 19-2058867325
1-1257182505 1-1257182505
46975812225 451801671048
138-632958852 138-632958852
Page\AssemblyPlan\AssemblyPlanControl.xaml;Page\AssemblyPlan\PlanInfoEditWindow.xaml;Page\AssemblyPlan\QuantityIssuedWindow.xaml;Page\AssemblyPlan\SearchCriteriaWindow.xaml;Page\InStoreInfo\InStoreInfoControl.xaml;LogInfoControl.xaml;MainWindow.xaml;Page\InventoryInfo\BomFoamRearInventory.xaml;Page\InventoryInfo\InventoryInfoControl.xaml;Page\InventoryInfo\SelectType.xaml;Page\InventoryInfo\LinerInventory.xaml;Page\InventoryInfo\MaterialStatisticsWindow.xaml;Page\InventoryInfo\ShellInventory.xaml;Page\InventoryInfo\SpaceDetailWindow.xaml;Page\InventoryInfo\SpaceInfoControl.xaml;Page\OutStoreInfo\OutStoreInfoControl.xaml;Page\TaskInfo\TaskInfoControl.xaml;RecordControl.xaml;templates\style\resourceStyle.xaml; Page\AssemblyPlan\AssemblyPlanControl.xaml;Page\AssemblyPlan\PlanInfoEditWindow.xaml;Page\AssemblyPlan\QuantityIssuedWindow.xaml;Page\AssemblyPlan\SearchCriteriaWindow.xaml;Page\InStoreInfo\InStoreInfoControl.xaml;LogInfoControl.xaml;MainWindow.xaml;Page\InventoryInfo\BomFoamRearInventory.xaml;Page\InventoryInfo\InventoryInfoControl.xaml;Page\InventoryInfo\SelectType.xaml;Page\InventoryInfo\LinerInventory.xaml;Page\InventoryInfo\MaterialStatisticsWindow.xaml;Page\InventoryInfo\ShellInventory.xaml;Page\InventoryInfo\SpaceDetailWindow.xaml;Page\InventoryInfo\SpaceInfoControl.xaml;Page\OutStoreInfo\OutStoreInfoControl.xaml;Page\TaskInfo\TaskInfoControl.xaml;RecordControl.xaml;templates\style\resourceStyle.xaml;

@ -12,7 +12,7 @@ DEBUG;TRACE
E:\c#\AUCMA\最新代码整合\泡后库\foam\Aucma.Scada.UI\App.xaml E:\c#\AUCMA\最新代码整合\泡后库\foam\Aucma.Scada.UI\App.xaml
19-2058867325 19-2058867325
1-1257182505 1-1257182505
47-1397376950 46-571518127
138-632958852 138-632958852
Page\AssemblyPlan\AssemblyPlanControl.xaml;Page\AssemblyPlan\PlanInfoEditWindow.xaml;Page\AssemblyPlan\QuantityIssuedWindow.xaml;Page\AssemblyPlan\SearchCriteriaWindow.xaml;Page\InStoreInfo\InStoreInfoControl.xaml;LogInfoControl.xaml;MainWindow.xaml;Page\InventoryInfo\BomFoamRearInventory.xaml;Page\InventoryInfo\InventoryInfoControl.xaml;Page\InventoryInfo\SelectType.xaml;Page\InventoryInfo\LinerInventory.xaml;Page\InventoryInfo\MaterialStatisticsWindow.xaml;Page\InventoryInfo\ShellInventory.xaml;Page\InventoryInfo\SpaceDetailWindow.xaml;Page\InventoryInfo\SpaceInfoControl.xaml;Page\OutStoreInfo\OutStoreInfoControl.xaml;Page\TaskInfo\TaskInfoControl.xaml;RecordControl.xaml;templates\style\resourceStyle.xaml; Page\AssemblyPlan\AssemblyPlanControl.xaml;Page\AssemblyPlan\PlanInfoEditWindow.xaml;Page\AssemblyPlan\QuantityIssuedWindow.xaml;Page\AssemblyPlan\SearchCriteriaWindow.xaml;Page\InStoreInfo\InStoreInfoControl.xaml;LogInfoControl.xaml;MainWindow.xaml;Page\InventoryInfo\BomFoamRearInventory.xaml;Page\InventoryInfo\InventoryInfoControl.xaml;Page\InventoryInfo\SelectType.xaml;Page\InventoryInfo\LinerInventory.xaml;Page\InventoryInfo\MaterialStatisticsWindow.xaml;Page\InventoryInfo\ShellInventory.xaml;Page\InventoryInfo\SpaceDetailWindow.xaml;Page\InventoryInfo\SpaceInfoControl.xaml;Page\OutStoreInfo\OutStoreInfoControl.xaml;Page\TaskInfo\TaskInfoControl.xaml;RecordControl.xaml;templates\style\resourceStyle.xaml;

@ -32,14 +32,21 @@ namespace Aucma.Scada.UI.viewModel.AssemblyPlan
private StringChange stringChange = StringChange.Instance; private StringChange stringChange = StringChange.Instance;
private RegisterServices registerServices = RegisterServices.Instance;
private OutStoreBusiness outStoreBusiness = OutStoreBusiness.Instance; private OutStoreBusiness outStoreBusiness = OutStoreBusiness.Instance;
private readonly IBaseBomInfoService _baseBomInfoServices = null;
// 系统设定当班时间
public List<WorkTime> listTime = null;
public AssemblyPlanViewModel() public AssemblyPlanViewModel()
{ {
MoveUpCommand = new RelayCommand<object>(obj => MoveUp(obj)); MoveUpCommand = new RelayCommand<object>(obj => MoveUp(obj));
MoveDownCommand = new RelayCommand<object>(obj => MoveDown(obj)); MoveDownCommand = new RelayCommand<object>(obj => MoveDown(obj));
DeletePlanCommand = new RelayCommand<object>(obj => DeletePlan(obj)); DeletePlanCommand = new RelayCommand<object>(obj => DeletePlan(obj));
NextPassCommand = new RelayCommand<object>(obj => NextPass(obj)); NextPassCommand = new RelayCommand<object>(obj => NextPass(obj));
_baseBomInfoServices = registerServices.GetService<IBaseBomInfoService>();
listTime = _baseBomInfoServices.getWorkTime().Result;
PlanInfoEditCommand = new RelayCommand(PlanInfoEdit); PlanInfoEditCommand = new RelayCommand(PlanInfoEdit);
MaterialStatisticsCommand = new RelayCommand(MaterialStatistics); MaterialStatisticsCommand = new RelayCommand(MaterialStatistics);
@ -498,48 +505,57 @@ namespace Aucma.Scada.UI.viewModel.AssemblyPlan
/// <summary> /// <summary>
/// 刷新小时产量统计 /// 刷新小时产量统计
/// </summary> /// </summary>
private void RefreshHourAmount() private async Task RefreshHourAmount()
{ {
//获取小时产量 await Task.Run(() =>
List<dynamic> hourAmount = assemblyPlanBusiness.GetHourAmount();
App.Current.Dispatcher.Invoke((Action)(() =>
{ {
if (listTime == null)
{
listTime = _baseBomInfoServices.getWorkTime().Result;
if (listTime == null) return;
}
//获取小时产量
List<dynamic> hourAmount = assemblyPlanBusiness.GetHourAmount();
if (hourAmount != null) if (hourAmount != null)
{ {
Achievement.Clear(); App.Current.Dispatcher.Invoke((Action)(() =>
ProductionHourList.Clear();
ProductionHourList.Clear();
ChartValues<ObservablePoint> hourAchievement = new ChartValues<ObservablePoint>();
int i = 0;
foreach (var item in hourAmount)
{ {
if(DateTime.Now.Hour>=8 && DateTime.Now.Hour <= 20)//白班 ProductionHourList.Clear();
Achievement.Clear();
ChartValues<ObservablePoint> achievement = new ChartValues<ObservablePoint>();
// x轴
foreach (WorkTime workTime in listTime)
{ {
if (int.Parse(item.PRODUCT_HOUR) >= 8 && int.Parse(item.PRODUCT_HOUR) < 20) ProductionHourList.Add(workTime.startTime.Hour.ToString());
{
ProductionHourList.Add(item.PRODUCT_HOUR);
hourAchievement.Add(new ObservablePoint(i++, Convert.ToDouble(item.PRODUCT_AMOUNT)));
}
} }
else // y轴
int i = 0;
foreach (string item in ProductionHourList)
{ {
if (int.Parse(item.PRODUCT_HOUR) < 8 || int.Parse(item.PRODUCT_HOUR) >= 20) //夜班 // achievement.Add(new ObservablePoint(i, 2));
var target = hourAmount.Where(x => int.Parse(x.PRODUCT_HOUR) == int.Parse(item)).FirstOrDefault();
if (target != null)
{
achievement.Add(new ObservablePoint(i, Convert.ToDouble(target.PRODUCT_AMOUNT)));
}
else
{ {
ProductionHourList.Add(item.PRODUCT_HOUR); achievement.Add(new ObservablePoint(i, 0));
hourAchievement.Add(new ObservablePoint(i++, Convert.ToDouble(item.PRODUCT_AMOUNT)));
} }
i++;
} }
} var houeColumn = new ColumnSeries();
var houeColumn = new ColumnSeries(); houeColumn.DataLabels = true;
houeColumn.DataLabels = true; houeColumn.Title = "小时产量";
houeColumn.Title = "小时产量"; houeColumn.Values = achievement;
houeColumn.Values = hourAchievement; houeColumn.Foreground = Brushes.White;
houeColumn.Foreground = Brushes.White; Achievement.Add(houeColumn);
Achievement.Add(houeColumn);
}));
} }
}));
});
} }
} }

@ -203,6 +203,8 @@ namespace Aucma.Scada.UI.viewModel.InStoreInfo
public RelayCommand ResetCommand { get; set; } public RelayCommand ResetCommand { get; set; }
#endregion #endregion
private string lastMessage = "";
/// <summary> /// <summary>
/// listBox绑定日志 /// listBox绑定日志
/// </summary> /// </summary>
@ -212,12 +214,18 @@ namespace Aucma.Scada.UI.viewModel.InStoreInfo
try try
{ {
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss.ss")}==>{message}"); if (lastMessage != message)
while (listItems.Count > 120)
{ {
listItems.RemoveAt(0); listItems.Add($"{DateTime.Now.ToString("HH:mm:ss.ss")}==>{message}");
lastMessage = message;
while (listItems.Count > 120)
{
listItems.RemoveAt(0);
}
LogInfoListBox = listItems.OrderByDescending(x => x);
} }
LogInfoListBox = listItems.OrderByDescending(x => x);
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -299,7 +299,7 @@ namespace Aucma.Scada.UI.viewModel
/// <param name="e"></param> /// <param name="e"></param>
public void RefreshPlc() public void RefreshPlc()
{ {
_plcDictionary = _pool.GetAll(); _plcDictionary = _pool.keyValuePairs;
// 箱壳状态 // 箱壳状态
_plcDictionary.TryGetValue(appConfig.foamStoreCode, out IPlc _plc); _plcDictionary.TryGetValue(appConfig.foamStoreCode, out IPlc _plc);
if (_plc != null) if (_plc != null)

@ -181,6 +181,8 @@ namespace Aucma.Scada.UI.viewModel.OutStoreInfo
public RelayCommand<object> DeleteTaskInfoCommand { get; set; } public RelayCommand<object> DeleteTaskInfoCommand { get; set; }
#endregion #endregion
private string lastMessage = "";
/// <summary> /// <summary>
/// listBox绑定日志 /// listBox绑定日志
/// </summary> /// </summary>
@ -190,14 +192,19 @@ namespace Aucma.Scada.UI.viewModel.OutStoreInfo
try try
{ {
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss.ss")}==>{message}"); if (lastMessage != message)
{
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss.ss")}==>{message}");
lastMessage = message;
LogInfoListBox = listItems.OrderByDescending(x => x);
LogInfoListBox = listItems.OrderByDescending(x => x); while (listItems.Count > 120)
{
listItems.RemoveAt(0);
}
while (listItems.Count > 120)
{
listItems.RemoveAt(0);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -58,6 +58,10 @@
<Project>{89a1edd9-d79e-468d-b6d3-7d07b8843562}</Project> <Project>{89a1edd9-d79e-468d-b6d3-7d07b8843562}</Project>
<Name>HighWayIot.Common</Name> <Name>HighWayIot.Common</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\HighWayIot.Config\HighWayIot.Config.csproj">
<Project>{75180EE5-13AE-499B-B0F6-C7BFEE1140CC}</Project>
<Name>HighWayIot.Config</Name>
</ProjectReference>
<ProjectReference Include="..\HighWayIot.Log4net\HighWayIot.Log4net.csproj"> <ProjectReference Include="..\HighWayIot.Log4net\HighWayIot.Log4net.csproj">
<Project>{deabc30c-ec6f-472e-bd67-d65702fdaf74}</Project> <Project>{deabc30c-ec6f-472e-bd67-d65702fdaf74}</Project>
<Name>HighWayIot.Log4net</Name> <Name>HighWayIot.Log4net</Name>

@ -1,9 +1,14 @@
namespace HighWayIot.Plc using System.Threading.Tasks;
namespace HighWayIot.Plc
{ {
public interface IPlc public interface IPlc
{ {
bool IsConnected { get; set; } bool IsConnected { get; set; }
bool DisConnect();
/// <summary> /// <summary>
/// 建立连接 /// 建立连接
/// </summary> /// </summary>
@ -13,10 +18,10 @@
bool Connect(string IP, int port); bool Connect(string IP, int port);
/// <summary> /// <summary>
/// 断开连接 /// 读取心跳
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
bool DisConnect(); Task<bool> ReadHeart(string address);
/// <summary> /// <summary>
/// 通过地址和长度读取PLC数据 /// 通过地址和长度读取PLC数据

@ -3,6 +3,7 @@ using HighWayIot.Log4net;
using HslCommunication; using HslCommunication;
using HslCommunication.Profinet.Inovance; using HslCommunication.Profinet.Inovance;
using System; using System;
using System.Threading.Tasks;
namespace HighWayIot.Plc.Impl namespace HighWayIot.Plc.Impl
{ {
@ -483,5 +484,10 @@ namespace HighWayIot.Plc.Impl
return false; return false;
} }
} }
public Task<bool> ReadHeart(string address)
{
throw new NotImplementedException();
}
} }
} }

@ -3,6 +3,7 @@ using HighWayIot.Log4net;
using HslCommunication; using HslCommunication;
using HslCommunication.Profinet.Melsec; using HslCommunication.Profinet.Melsec;
using System; using System;
using System.Threading.Tasks;
namespace HighWayIot.Plc.Impl namespace HighWayIot.Plc.Impl
{ {
@ -31,6 +32,48 @@ namespace HighWayIot.Plc.Impl
public bool IsConnected { get; set; } public bool IsConnected { get; set; }
/// <summary>
/// 读取心跳
/// </summary>
/// <returns></returns>
public async Task<bool> ReadHeart(string address)
{
try
{
melsec_net.ReceiveTimeOut = 2000;
OperateResult<bool> read = melsec_net.ReadBool(address);
if (read.IsSuccess)
{
IsConnected = true;
return true;
}
else
{
var k = read.ErrorCode < 0 ? false : true;
if (k)
{
IsConnected = true;
return await Task.FromResult(IsConnected);
}
else
{
IsConnected = false;
return await Task.FromResult(IsConnected);
}
}
}
catch (Exception ex)
{
log.Error("读取心跳方法异常" + ex.ToString());
}
return false;
}
/// <summary> /// <summary>
/// 建立连接 /// 建立连接
/// </summary> /// </summary>

@ -3,6 +3,7 @@ using HighWayIot.Log4net;
using HslCommunication; using HslCommunication;
using HslCommunication.Profinet.Omron; using HslCommunication.Profinet.Omron;
using System; using System;
using System.Threading.Tasks;
namespace HighWayIot.Plc.Impl namespace HighWayIot.Plc.Impl
{ {
@ -440,5 +441,10 @@ namespace HighWayIot.Plc.Impl
return false; return false;
} }
} }
public Task<bool> ReadHeart(string address)
{
throw new NotImplementedException();
}
} }
} }

@ -3,6 +3,7 @@ using HighWayIot.Log4net;
using HslCommunication; using HslCommunication;
using HslCommunication.Profinet.Siemens; using HslCommunication.Profinet.Siemens;
using System; using System;
using System.Threading.Tasks;
namespace HighWayIot.Plc.Impl namespace HighWayIot.Plc.Impl
{ {
@ -407,5 +408,10 @@ namespace HighWayIot.Plc.Impl
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<bool> ReadHeart(string address)
{
throw new NotImplementedException();
}
} }
} }

@ -1,12 +1,20 @@
using HighWayIot.Log4net; using HighWayIot.Config;
using HighWayIot.Log4net;
using HighWayIot.Plc.Impl; using HighWayIot.Plc.Impl;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
using System.Timers;
namespace HighWayIot.Plc namespace HighWayIot.Plc
{ {
public sealed class PlcPool public sealed class PlcPool
{ {
private AppConfig appConfig = AppConfig.Instance;
private PlcConfig plcConfig = PlcConfig.Instance;
private static readonly Lazy<PlcPool> lazy = new Lazy<PlcPool>(() => new PlcPool()); private static readonly Lazy<PlcPool> lazy = new Lazy<PlcPool>(() => new PlcPool());
public static PlcPool Instance public static PlcPool Instance
{ {
@ -18,7 +26,7 @@ namespace HighWayIot.Plc
private LogHelper logHelper = LogHelper.Instance; private LogHelper logHelper = LogHelper.Instance;
private Dictionary<string, IPlc> keyValuePairs = new Dictionary<string, IPlc>(); public Dictionary<string, IPlc> keyValuePairs = new Dictionary<string, IPlc>();
private PlcPool() { } private PlcPool() { }
@ -29,32 +37,77 @@ namespace HighWayIot.Plc
/// <param name="ip"></param> /// <param name="ip"></param>
/// <param name="port"></param> /// <param name="port"></param>
/// <param name="key"></param> /// <param name="key"></param>
public void InitPlc(string plcType, string ip, int port, string key) public async void InitPlc(string plcType, string ip, int port, string key)
{
if (!keyValuePairs.ContainsKey(key))
{
IPlc _plc = null;
switch (plcType)
{
case "InovancePlc":
_plc = new InovancePlc();
break;
case "MelsecBinaryPlc":
_plc = new MelsecBinaryPlc();
break;
case "OmronNJPlc":
_plc = new OmronNJPlc();
break;
case "SiemensPlc":
_plc = new SiemensPlc();
break;
default:
break;
}
var connectResult = _plc.Connect(ip, port);
if (connectResult)
{
keyValuePairs.Add(key, _plc);
}
}
}
#region 心跳
public async Task StartMelsecPlcAsync()
{ {
IPlc _plc = null; System.Timers.Timer timer = new System.Timers.Timer(3000);
switch (plcType) timer.Elapsed += new System.Timers.ElapsedEventHandler(ExecMelsecMcHeartTask); //到达时间的时候执行事件;
timer.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
await Task.CompletedTask;
}
private async void ExecMelsecMcHeartTask(object sender, ElapsedEventArgs e)
{
if (keyValuePairs.Count == 0)
{ {
case "InovancePlc": this.InitPlc("MelsecBinaryPlc", plcConfig.foam_Plc_Ip, plcConfig.foam_Plc_Port, appConfig.foamStoreCode);
_plc = new InovancePlc();
break;
case "MelsecBinaryPlc":
_plc = new MelsecBinaryPlc();
break;
case "OmronNJPlc":
_plc = new OmronNJPlc();
break;
case "SiemensPlc":
_plc = new SiemensPlc();
break;
default:
break;
} }
var connectResult = _plc.Connect(ip, port); else
if (connectResult)
{ {
keyValuePairs.Add(key, _plc); IPlc _plc = keyValuePairs[appConfig.foamStoreCode];
if (_plc != null)
{
var result = _plc.ReadHeart("M100").Result;
if (result)
{
logHelper.Info("PLC连接成功");
}
else
{
logHelper.Info("PLC连接失败");
keyValuePairs.Clear();
}
}
} }
} }
#endregion
/// <summary> /// <summary>
/// 获取PLC /// 获取PLC

@ -1 +1 @@
8183a0a9755b329030b4405e31ff3cdff26d35b0 6e3ce38cf36e2a7877b852157f0b0e1b49337179

@ -118,3 +118,5 @@ E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\obj\Debug\HighWayIo
E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\obj\Debug\HighWayIot.Plc.csproj.CopyComplete E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\obj\Debug\HighWayIot.Plc.csproj.CopyComplete
E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\obj\Debug\HighWayIot.Plc.dll E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\obj\Debug\HighWayIot.Plc.dll
E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\obj\Debug\HighWayIot.Plc.pdb E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\obj\Debug\HighWayIot.Plc.pdb
E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\bin\Debug\HighWayIot.Config.dll
E:\c#\AUCMA\最新代码整合\泡后库\foam\HighWayIot.Plc\bin\Debug\HighWayIot.Config.pdb

@ -11,6 +11,13 @@ namespace HighWayIot.Repository.service
List<BaseBomInfo> GetBomInfos(); List<BaseBomInfo> GetBomInfos();
/// <summary>
/// 获取系统班组时间
/// </summary>
Task<List<WorkTime>> getWorkTime();
/// <summary> /// <summary>
/// 根据成品物料码获取自己BOM信息 /// 根据成品物料码获取自己BOM信息
/// </summary> /// </summary>

@ -3,6 +3,7 @@ using HighWayIot.Log4net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl namespace HighWayIot.Repository.service.Impl
{ {
@ -12,6 +13,27 @@ namespace HighWayIot.Repository.service.Impl
private LogHelper logHelper = LogHelper.Instance; private LogHelper logHelper = LogHelper.Instance;
/// <summary>
/// 获取系统班组时间
/// </summary>
public async Task<List<WorkTime>> getWorkTime()
{
try
{
List<WorkTime> list = null;
var _db = _bomInfoRepository.Context;
list = await _db.SqlQueryable<WorkTime>("SELECT * FROM VIEW_CURRENT_TEAM_TIME ORDER BY START_TIME").ToListAsync();
return list;
}
catch (Exception)
{
return null;
}
}
public List<BaseBomInfo> GetBomInfos() public List<BaseBomInfo> GetBomInfos()
{ {
try try

Loading…
Cancel
Save