天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
6.5 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.DAL.Basic;
using QMAPP.FJC.Entity;
using QMFrameWork.Common.Serialization;
using OPCPLC;
namespace EQUIPINTERFACETEST
{
public class CastOperateTest
{
public void Test()
{
int clientHandleValue = 0;
Dictionary<int, string> clientHandleDict = new Dictionary<int, string>();
Dictionary<string, int> parameterValueDict = new Dictionary<string, int>();
MachineInfo m = new MachineInfo();
MachineInfoDAL mdal = new MachineInfoDAL();
m = mdal.Get(new MachineInfo() { PID = "df56bcd0-f68d-44d6-8ac5-316c85e09895" });
ParameterConfigDAL paraConDal = new QMAPP.FJC.DAL.Basic.ParameterConfigDAL();
List<ParameterConfig> paraConfigList
= paraConDal.GetList(new ParameterConfig()
{
PROCESSTYPE = EnumGeter.ProcessType.jiaozhu.GetHashCode().ToString()
,
COLUMNTYPE = "0"
});
//opcServer服务器IP
string opcServerIP = "127.0.0.1";
//opcServer服务名称
string opcServerName = "kepware.KEPServerEX.V5";
//OPCPLCAutomation opcplcConnection = new OPCPLC.OPCPLCAutomation();
//opcplcConnection.GetListOPCServers(opcServerIP);
//opcplcConnection.ConnectRemoteServer(opcServerName, opcServerIP);
////为该模块创建参数组
//opcplcConnection.CreateGroup(m.MACHINECODDE + ":" + "1" + ":GetData");
//if (opcplcConnection.KepGroups.DefaultGroupUpdateRate == 1000)
//{
// opcplcConnection.KepGroups.DefaultGroupUpdateRate = 200;
//}
m.MOLDNUMBER = "1";
//变该模块下的所有参数信息
foreach (var pc in paraConfigList)
{
//初始化字典名称: 设备名称+模块编号+字段名称
string dicKeyStr = m.MACHINECODDE + ":" + m.MOLDNUMBER + ":" + pc.COLUMNCODE;
try
{
// //初始化字段信息值为0
// parameterValueDict.Add(dicKeyStr, 0);
// //获取opc中tagName
// string itemName = pc.CONNECTIONSTRING;
// clientHandleValue++;
// clientHandleDict.Add(clientHandleValue, dicKeyStr);
// //将字典中的与PLC内存地址向绑定
// parameterValueDict[dicKeyStr] = opcplcConnection.AddKepItem(itemName, clientHandleValue);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(dicKeyStr);
continue;
}
}
foreach (var p in paraConfigList)
{
#region
if (p.COLUMNCODE == "FLOW")
{
p.PARAVALUE = 394.2;
}
if (p.COLUMNCODE == "MCNO")
{
p.PARAVALUE = 1;
}
if (p.COLUMNCODE == "STRESSPERCENT")
{
p.PARAVALUE = 0.58;
}
if (p.COLUMNCODE == "MOULDNO")
{
p.PARAVALUE = 2;
}
if (p.COLUMNCODE == "DAY")
{
p.PARAVALUE = 3;
}
if (p.COLUMNCODE == "HOUR")
{
p.PARAVALUE = 15;
}
if (p.COLUMNCODE == "MINUTE")
{
p.PARAVALUE = 58;
}
if (p.COLUMNCODE == "MONTH")
{
p.PARAVALUE = 3;
}
if (p.COLUMNCODE == "SECOND")
{
p.PARAVALUE = 12;
}
if (p.COLUMNCODE == "YEAR")
{
p.PARAVALUE = 16;
}
if (p.COLUMNCODE == "METARIALTEMPRATURE")
{
p.PARAVALUE = 27.4;
}
if (p.COLUMNCODE == "METARIALTEMPRATURETWO")
{
p.PARAVALUE = 28;
}
#endregion
}
//List<ParameterConfig> resultList = new List<ParameterConfig>();
////获取所有的加工参数
//foreach (var parameter in paraConfigList)
//{
// #region 获取参数
// ParameterConfig paraConfig = GetResultParameterConfig(parameter);
// string item = parameter.MACHINECODDE + ":" + parameter.MOLDNUMBER + ":" + parameter.COLUMNCODE;
// var result = opcplcConnection.ReadtagValue(parameterValueDict[item]);
// if (result != null)
// {
// paraConfig.PARAVALUE = result;
// }
// resultList.Add(paraConfig);
// #endregion
// Console.WriteLine(paraConfig.MACHINECODDE + ":" + paraConfig.MOLDNUMBER + ":" + paraConfig.COLUMNCODE + " " + ((result == null) ? " " : result.ToString()));
// WriteLog.Write(paraConfig.MACHINECODDE + ":" + paraConfig.MOLDNUMBER + ":" + paraConfig.COLUMNCODE + " " + ((result == null) ? " " : result.ToString()));
//}
//string a = JsonConvertHelper.GetSerializes(paraConfigList);
//OpcServiceClient client = new OpcServiceClient();
//client.SubmitParameters(a);
}
private static ParameterConfig GetResultParameterConfig(ParameterConfig parameter)
{
ParameterConfig paraConfig = new ParameterConfig();
#region 属性复制
paraConfig.COLUMNCODE = parameter.COLUMNCODE;
paraConfig.COLUMNTYPE = parameter.COLUMNTYPE;
paraConfig.DATATYPE = parameter.DATATYPE;
paraConfig.DBNUMBER = parameter.DBNUMBER;
paraConfig.DEALTYPE = parameter.DEALTYPE;
paraConfig.MACHINECODDE = parameter.MACHINECODDE;
paraConfig.MOLDNUMBER = parameter.MOLDNUMBER;
paraConfig.OPERATETYPE = parameter.OPERATETYPE;
paraConfig.PROCESSTYPE = parameter.PROCESSTYPE;
#endregion
return paraConfig;
}
}
}