using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
namespace TProduct.Link.Kedi
{
public partial class LinkHelper
{
///
/// 构建设备
///
///
///
///
///
///
public bool InitialData杭州力夫(
TProduct.Model.ProductMainExPump pump,
TProduct.Model.ProductMainExMotor motor,
TProduct.Model.WorkBenchBase workBench,
TProduct.Model.TestProjectItemView tesItem,
List instrumentParas,
List allMonitors,
out string error_info)
{
_singleCommList = new List();
var com_names = (from x in instrumentParas select x.ComPortName).Distinct();
foreach (var com_name in com_names)
{
if (string.IsNullOrEmpty(com_name))
continue;
var single_com_helper = new SingleComBaseHelper();
single_com_helper.InitialComPort(workBench, com_name);
single_com_helper.OnReceivePollValue += (values, additionInfo, info, bytes) =>
{
this.InvokeReceiveMonitorValue(values, additionInfo, info, bytes);
};
single_com_helper.OnShowMsg += (content) =>
{
if (OnShowMsg != null)
{
OnShowMsg(content);
}
};
var f_instrumentParas = from x in instrumentParas where x.ComPortName == com_name select x;
foreach (var instrument in f_instrumentParas)
{
if (instrument.UseStatus != Model.eUseStatus.Enable)
continue;
if (instrument.InstrumentType ==
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.电参数仪)
{
var msg_item = new MsgItem_力夫_电参数();
msg_item.Name = "电参数仪";
msg_item.InitialData(instrument, allMonitors);
single_com_helper.AddMsgItem(msg_item);
}
if (instrument.InstrumentType ==
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.无纸数据记录仪)
{
var msg_item = new MsgItem_力夫_Dr();
msg_item.SetMeterInfo(_allPressMeter, _allFlowMeter);
msg_item.Name = "无纸数据记录仪";
msg_item.InitialData(workBench, instrument, allMonitors);
single_com_helper.AddMsgItem(msg_item);
}
if (instrument.InstrumentType ==
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.直流电源)
{
bool isHaveV = false;
if (motor != null)
{
if (motor.RatedU != null)
{
isHaveV = true;
var msg_item = new MsgItem_力夫_直流电源();
msg_item.Name = "直流电源";
msg_item.InitialData(Convert.ToSingle(motor.RatedU.Value.ToString()));
single_com_helper.AddMsgItem(msg_item);
}
}
else
{
var pumpParas = TProduct.Model.RatedParas4Pump.ToModel(pump.RatedParas);
if (pumpParas.Voltage > 0)
{
isHaveV = true;
var msg_item = new MsgItem_力夫_直流电源();
msg_item.Name = "直流电源";
msg_item.InitialData(Convert.ToSingle(pumpParas.Voltage.ToString()));
single_com_helper.AddMsgItem(msg_item);
}
}
if (!isHaveV)
{
error_info = "未设置电机电压";
return false;
}
}
if (instrument.InstrumentType ==
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.PLC)
{
var msg_item = new MsgItem_力夫_PLC();
msg_item.Name = "PLC";
single_com_helper.SetParity(Parity.Even);
single_com_helper.SetDataBits(7);
single_com_helper.AddMsgItem(msg_item);
}
if (instrument.InstrumentType ==
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.温度控制仪)
{
var msg_item = new MsgItem_力夫_温度控制器();
msg_item.InitialData(instrument, allMonitors);
msg_item.Name = "温度控制仪";
single_com_helper.AddMsgItem(msg_item);
}
if (instrument.InstrumentType ==
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.阀门)
{
var pipeParas = new Model.PipeParas4Pump(workBench.PipeParas);
if (string.IsNullOrEmpty(workBench.PipeParas))
{
error_info = "测试台未设置进出口口径";
return false;
}
if (pipeParas.InletDia == null)
{
error_info = "测试台未设置进出口口径";
return false;
}
int inletDia = (int)pipeParas.InletDia.Value;
if (inletDia != 8 && inletDia != 15 && inletDia != 20)
{
error_info = "测试台未设置进口口径,只支持8,15,20";
return false;
}
if (pipeParas.OutletDia == null)
{
error_info = "测试台未设置 出口口径";
return false;
}
int outletDia = (int)pipeParas.OutletDia.Value;
if (outletDia != 8 && outletDia != 15 && outletDia != 20)
{
error_info = "测试台未设置出口口径,只支持8,15,20";
return false;
}
var msg_item = new MsgItem_力夫_阀门();
msg_item.Name = "阀门";
msg_item.InitialData(inletDia, outletDia);
single_com_helper.AddMsgItem(msg_item);
}
if (instrument.InstrumentType ==
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.扭矩仪)
{
}
}
if (single_com_helper.TotalMsgItemCount > 0)
_singleCommList.Add(single_com_helper);
}
error_info = null;
return true;
}
}
}