61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace DoAn.PLC
|
|||
|
|
{
|
|||
|
|
public class Host
|
|||
|
|
{
|
|||
|
|
Dictionary<string, TagServer> _lstTagServer;
|
|||
|
|
|
|||
|
|
public Host()
|
|||
|
|
{
|
|||
|
|
this._lstTagServer = new Dictionary<string, TagServer>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 创建一个PLC服务
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="hostIp"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public TagServer CreateTagServer(string hostIp)
|
|||
|
|
{
|
|||
|
|
if (GetTagServerByIp(hostIp) != null) return null;
|
|||
|
|
|
|||
|
|
// 用带IP地址创建对象
|
|||
|
|
TagServer tagServer = new TagServer(hostIp);
|
|||
|
|
|
|||
|
|
AddTagServer(hostIp, tagServer);
|
|||
|
|
return tagServer;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void AddTagServer(string hostIp,TagServer tagServer)
|
|||
|
|
{
|
|||
|
|
this._lstTagServer.Add(hostIp, tagServer);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据IP返回一个PLC服务
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="hostIp"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public TagServer GetTagServerByIp(string hostIp)
|
|||
|
|
{
|
|||
|
|
return this._lstTagServer.ContainsKey(hostIp) ? this._lstTagServer[hostIp] : null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 关闭所有
|
|||
|
|
/// </summary>
|
|||
|
|
public void CloseConnect()
|
|||
|
|
{
|
|||
|
|
foreach (KeyValuePair<string,TagServer> item in this._lstTagServer)
|
|||
|
|
{
|
|||
|
|
item.Value.DisconnectPLC();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|