You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Const;
using HybirdFrameworkDriver.ModbusTcpMaster;
using Minio.DataModel;
using Service.PlcAfrica.Msg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static HybirdFrameworkCore.Const.EndingConst;
namespace Service.PlcAfrica.Client
{
[Scope]
public class PlcAfricaClient : ModbusTcpMaster
{
7 days ago
private long TaskNo = 0;
public PlcAfricaClient()
{
ReadAction = BatchRead;
Ip = "192.168.3.200";
Port = 502;
Duration = 1000;
AutoReConnect = true;
ByteSeq = EndingConst.ByteSeq.BA;
WordSeq = EndingConst.WordSeq.DC;
}
private bool BatchRead(ModbusTcpMaster master)
{
bool resul = Connected;
//0x03
var bytes01 = master.Read("x=3;7000", 2500).Content;
if (bytes01 != null)
{
PlcAfricaMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcAfricaMsg>(bytes01, PlcAfricaMgr.PlcAfricaMsg,
EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
}
return resul;
}
7 days ago
//修改当前任务
public void ExChangeTaskNo(long taskNo)
{
Interlocked.Exchange(ref TaskNo, taskNo);
}
//重置当前任务
public void ResetTaskNo()
{
Interlocked.Exchange(ref TaskNo, 0);
}
public bool IsTaskFree()
{
return ReadTaskNo() == 0l;
}
//读取当前任务
public long ReadTaskNo()
{
return Interlocked.Read(ref TaskNo);
}
}
}