using System;
|
using System.Collections.Generic;
|
using System.IO.Ports;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using TProduct.Model;
|
|
namespace TProduct.Link.Kedi
|
{
|
/// <summary>
|
/// 丹泉款
|
/// </summary>
|
public class SiPumpHelper : IDisposable
|
{
|
List<SiSingleComLinkHelper> _singleLinkList = null;
|
|
|
/// <summary>
|
/// 构造函数(输入测试类型)
|
/// </summary>
|
public SiPumpHelper()
|
{
|
|
}
|
|
/// <summary>
|
/// 构建设备
|
/// </summary>
|
/// <param name="bundles"></param>
|
/// <param name="error_info"></param>
|
/// <returns></returns>
|
public bool InitialData(
|
List<Model.WorkBenchInstrumentKedi> instrumentParas,
|
List<TProduct.Model.WorkBenchMonitorPoint> allMonitors,
|
out string error_info)
|
{
|
_singleLinkList = new List<SiSingleComLinkHelper>();
|
var com_names = (from x in instrumentParas where x.UseStatus == eUseStatus.Enable select x.ComPortName).Distinct();
|
foreach (var com_name in com_names)
|
{
|
if (string.IsNullOrEmpty(com_name))
|
continue;
|
|
var f_allItemList = from x in instrumentParas
|
where x.ComPortName == com_name && x.UseStatus == eUseStatus.Enable
|
select x;
|
if(f_allItemList == null || f_allItemList.Count() == 0)
|
{
|
continue;
|
}
|
SiSingleComLinkHelper singleComlink = new SiSingleComLinkHelper();
|
singleComlink.OnReceiveMsg += (s, e) => { InvokeReceiveMsg(e.Values, e.ErrorInfo, e.BtyeMessage); };
|
if (!singleComlink.InitialData(com_name, f_allItemList.ToList(), allMonitors, out error_info))
|
{
|
return false;
|
}
|
_singleLinkList.Add(singleComlink);
|
}
|
if (_singleLinkList.Count == 0)
|
{
|
error_info = "数据未初始化失败";
|
return false;
|
}
|
|
error_info = null;
|
return true;
|
}
|
|
/// <summary>
|
/// 发送控制消息
|
/// </summary>
|
/// <param name="error_info"></param>
|
/// <returns></returns>
|
public override bool SendCtrlMsg(string tag, string paras, out string error_info)
|
{
|
if (_singleLinkList == null)
|
{
|
error_info = null;
|
return true ;
|
}
|
foreach (var link in _singleLinkList)
|
{
|
link.SendCtrlMsg(tag, paras, out error_info);
|
}
|
error_info = null;
|
return true;
|
}
|
/// <summary>
|
/// 开始
|
/// </summary>
|
/// <param name="error_info"></param>
|
/// <returns></returns>
|
public override bool Start(out string error_info)
|
{
|
if (_singleLinkList == null)
|
{
|
error_info = "COM数据未初始化";
|
return false;
|
}
|
foreach (var link in _singleLinkList)
|
{
|
if (!link.Start(out error_info))
|
{
|
return false;
|
}
|
Thread.Sleep(150);//错开一下
|
}
|
error_info = null;
|
return true;
|
}
|
|
|
|
|
|
|
/// <summary>
|
/// 关闭
|
/// </summary>
|
public override bool Stop(out string error_info)
|
{
|
error_info = null;
|
if (_singleLinkList == null)
|
{
|
return true ;
|
}
|
foreach (var link in _singleLinkList)
|
{
|
link.Stop(out error_info);
|
}
|
return true;
|
}
|
|
|
|
|
/// <summary>
|
///
|
/// </summary>
|
public void Dispose()
|
{
|
string strInfo;
|
Stop(out strInfo);
|
}
|
}
|
|
|
}
|