generated from wenjy/Sln.Iot
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.
74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using HslCommunication;
|
|
using Sln.Iot.PLC;
|
|
using Sln.Iot.Repository.service;
|
|
using Sln.Iot.Serilog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sln.Iot.Business
|
|
{
|
|
public class RFID05Business
|
|
{
|
|
private Timer _timer;
|
|
|
|
private readonly PLCConnect _plc;
|
|
|
|
private readonly SerilogHelper _log;
|
|
|
|
public RFID05Business()
|
|
{
|
|
_timer = new Timer(TimerCallback, null, 0, 5000);
|
|
}
|
|
|
|
/// <summary>
|
|
/// RFID02胶机1真空箱数据处理流程
|
|
/// </summary>
|
|
/// <param name="state"></param>
|
|
public void TimerCallback(object? state)
|
|
{
|
|
// 定时任务逻辑
|
|
//读取信号
|
|
OperateResult<short> signalRes = _plc.ReadInt16(_plc.DeltaInstance2, "D802");
|
|
//成功验证
|
|
if (signalRes.IsSuccess)
|
|
{
|
|
short signalValue = signalRes.Content;
|
|
//如果有读取信号
|
|
if (signalValue == 5001)
|
|
{
|
|
//读取托盘码
|
|
OperateResult<byte[]> trayBytesResult = _plc.ReadBytes(_plc.DeltaInstance2, "D5020", 20);
|
|
//成功验证
|
|
if (trayBytesResult.IsSuccess)
|
|
{
|
|
//转换托盘吗
|
|
string traycode = Encoding.ASCII.GetString(trayBytesResult.Content);
|
|
|
|
//sql更新
|
|
bool res = TrayBindingService.Instance.UpDateTime(DateTime.Now.ToString(), traycode, "4");
|
|
if (!res)
|
|
{
|
|
_log.Error("胶机2真空箱后数据库写入异常");
|
|
}
|
|
|
|
//写入完成信号
|
|
res = _plc.PlcWrite(_plc.DeltaInstance2, "D802", 5002, DataTypeEnum.UInt16).IsSuccess;
|
|
if (!res)
|
|
{
|
|
_log.Error("胶机2真空箱后PLC写入完成信号异常");
|
|
}
|
|
}
|
|
//流程完成
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_log.Error("胶机2真空箱后PLC读取信号异常");
|
|
}
|
|
}
|
|
}
|
|
}
|