|
|
2 éve | |
|---|---|---|
| doc | 2 éve | |
| src | 2 éve | |
| .gitignore | 2 éve | |
| README.md | 2 éve |
namespace YSAI.Core.@interface
{
/// <summary>
/// 数采接口
/// </summary>
public interface IDaq : IOn, IOff, IRead, IWrite, ISubscribe, IGetStatus, IEvent, IDisposable
{
}
}
namespace YSAI.Core.@interface
{
/// <summary>
/// 转发接口
/// </summary>
public interface IRelay : IOn, IOff, IProducer, IConsumer, IGetStatus, IEvent, IDisposable
{
}
}
1.上 NUGET 搜索 YSAI
2.安装对应的协议包
3.应用代码如下
4.协议包内还有内部公共方法,请自行研究使用
------------------------------------------------------
//采集协议
using (类 operate = new 类(new 类数据.Basics
{
//采集对象参数
}))
{
//打开
OperateResult result = operate.On();
LogHelper.Info(result.ToJson().JsonFormatting());
//点位地址
Address address = new Address();
address.SN = Guid.NewGuid().ToString();
address.CreationTime = DateTime.Now.ToLocalTime();
address.AddressArray = new List<AddressDetails>
{
new AddressDetails()//S7点位地址
{
SN=$"{Guid.NewGuid().ToNString()} - Factory",
AddressName = "DB71.DBD4",
AddressDataType = YSAI.Core.@enum.DataType.Float
},
new AddressDetails()//OpcUa点位地址
{
SN=$"{Guid.NewGuid().ToNString()} - Factory",
AddressName = "ns=2;s=Scalar_Simulation_Float",
AddressDataType = YSAI.Core.@enum.DataType.Float
},
new AddressDetails()//OpcDa点位地址
{
SN=$"{Guid.NewGuid().ToNString()} - Factory",
AddressName = "a.a.a",
AddressDataType = YSAI.Core.@enum.DataType.Float
},
new AddressDetails()//Modbus点位地址
{
SN=$"{Guid.NewGuid().ToNString()} - Factory",
AddressName = "0,2",
AddressDataType = YSAI.Core.@enum.DataType.Float
},
new AddressDetails() //DB点位地址
{
SN=$"{Guid.NewGuid().ToNString()} - Factory",
AddressName = "数据库采集",
AddressDataType = YSAI.Core.@enum.DataType.String,
AddressExtendParam=new DBData.ExtendParam.Read()
{
Sql = @"SELECT A,B,C,D FORM TABLE ORDER BY YPBH DESC LIMIT 0,1",
ColumnName = new List<string>() { "A", "B", "C", "D"}
}
},
new AddressDetails() //OpcDaHttp点位地址
{
SN=$"{Guid.NewGuid().ToNString()} - Factory",
AddressName = "a.a.a",
AddressDataType = YSAI.Core.@enum.DataType.String,
AddressExtendParam=new OpcDaHttpData.ExtendParam.Read()
{
GroupName="YF75ZDHPJ",
ReadInterval=1000,
ServerName="OPC.SimaticNET.1"
}
},
new AddressDetails() //地址详情参数介绍
{
SN=$"A88", //可以理解成唯一标识符(可以存机台号、组名、车间、厂)
AddressAnotherName="A_Name", //地址别名
AddressDataType=YSAI.Core.@enum.DataType.Float, //数据类型
AddressDescribe="NameDescribe", //地址描述
AddressExtendParam=new object(), //扩展数据
AddressName="Name", //地址名称
//AddressParseParam=new AddressParse //地址解析参数
//{
// ParseType=ParseType.ScriptAnalysis, //解析类型
// Script=new YSAI.Core.script.ScriptData.Basics //脚本解析数据
// {
// }
//},
AddressParseParam=new AddressParse //地址解析参数
{
ParseType=ParseType.MethodAnalysis, //解析类型
ReflectionSN="反射SN"
},
AddressPropertyName="Name1", //地址别名
AddressType=AddressType.Reality, //地址类型
IsEnable=true //是否启用
}
};
//读取
result = operate.Read(address);
LogHelper.Info(result.ToJson().JsonFormatting());
//订阅
operate.OnEvent += delegate (object? sender, EventResult e)
{
LogHelper.Info(e.ToJson().JsonFormatting());
};
result = operate.Subscribe(address);
LogHelper.Info(result.ToJson().JsonFormatting());
//写入
ConcurrentDictionary<string, string> value = new ConcurrentDictionary<string, string>
{
["地址"] = "值"
};
result = operate.Write(value);
LogHelper.Info(result.ToJson().JsonFormatting());
//关闭
result = operate.Off();
LogHelper.Info(result.ToJson().JsonFormatting());
}
------------------------------------------------------
//转发协议
using (类 operate = new 类(new 类数据.Basics
{
//转发对象参数
}))
{
//打开
OperateResult result = operate.On();
LogHelper.Info(result.ToJson().JsonFormatting());
//生产
result = operate.Produce("主题", "内容");
LogHelper.Info(result.ToJson().JsonFormatting());
//消费
operate.OnEvent += delegate (object? sender, EventResult e)
{
LogHelper.Info(e.ToJson().JsonFormatting());
};
result = operate.Subscribe("主题");
LogHelper.Info(result.ToJson().JsonFormatting());
//关闭
result = operate.Off();
LogHelper.Info(result.ToJson().JsonFormatting());
}
//更新,无休眠时间
while(true)
{
//三大步骤
1.优化
2.更新
3.提交
}
1.Mqtt 客户端 修改内部公共方法函数名 2.转发协议包修改