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.
Aucma.Scada/Aucma.Scada.Business/TaskHandleBusiness.cs

96 lines
3.0 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using HighWayIot.Common;
using HighWayIot.Config;
using HighWayIot.Log4net;
using HighWayIot.Plc;
using HighWayIot.Plc.Impl;
using HighWayIot.Repository.domain;
using HighWayIot.Repository.service;
using HighWayIot.Repository.service.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.Business
{
public sealed class TaskHandleBusiness
{
private static readonly Lazy<TaskHandleBusiness> lazy = new Lazy<TaskHandleBusiness>(() => new TaskHandleBusiness());
public static TaskHandleBusiness Instance
{
get
{
return lazy.Value;
}
}
public delegate void OutStoreFinsih(string storeCode,string taskCode);
public event OutStoreFinsih OutStoreFinsihEvent;
private IPlc _plc = new SiemensPlc();
private LogHelper logHelper = LogHelper.Instance;
private AppConfig appConfig = AppConfig.Instance;
private PlcConfig plcConfig = PlcConfig.Instance;
private TaskHandleBusiness()
{
}
public void Inite()
{
_plc.Connect("127.0.0.1", 124);
}
public bool SendOutStoreTask(RealTaskInfo realTaskInfo)
{
bool result = false;
string spaceCode = string.Empty;
string amount = string.Empty;
string taskCode = string.Empty;
string answer = string.Empty;
try
{
if(realTaskInfo.storeCode == appConfig.shellStoreCode)
{
spaceCode = plcConfig.out_shell_spaceCode;
amount = plcConfig.out_shell_amount;
taskCode = plcConfig.out_shell_task;
}else if (realTaskInfo.storeCode == appConfig.linerStoreCode)
{
spaceCode = plcConfig.out_liner_spaceCode;
amount = plcConfig.out_liner_amount;
taskCode = plcConfig.out_liner_task;
}
//写入货道号
_plc.writeStringByAddress(spaceCode, realTaskInfo.spaceCode);
//写入出库数量
_plc.writeInt32ByAddress(amount, realTaskInfo.planAmount);
//写入任务号
_plc.writeStringByAddress(taskCode,realTaskInfo.taskCode);
//写入应答字
_plc.writeInt32ByAddress(answer, 1);
result = true;
}
catch(Exception ex)
{
logHelper.Error("出库任务下发异常", ex);
}
return result;
}
private void ReadPlc()
{
if(_plc.readInt32ByAddress("") == 1) // 读取PLC出库应答字出库完成后读取任务号
{
string taskCode = _plc.readStringByAddress("", (ushort)12);
OutStoreFinsihEvent?.Invoke(appConfig.shellStoreCode, taskCode);
}
}
}
}