Files
Modbus.Net/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs
2016-01-29 12:52:19 +08:00

35 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBus.Net.OPC
{
public class AddressFormaterOpc : AddressFormater
{
public BaseMachine Machine { get; set; }
protected Func<BaseMachine, AddressUnit, string[]> TagGeter { get; set; }
public AddressFormaterOpc(Func<BaseMachine, AddressUnit, string[]> tagGeter)
{
TagGeter = tagGeter;
}
public override string FormatAddress(string area, int address)
{
var findAddress = Machine?.GetAddresses.FirstOrDefault(p => p.Area == area && p.Address == address);
if (findAddress == null) return null;
var strings = TagGeter(Machine, findAddress);
var ans = "";
for (int i = 0; i < strings.Length; i++)
{
ans += strings[i].Trim().Replace(" ", "") + ".";
}
ans = ans.Substring(0, ans.Length - 1);
return ans;
}
}
}