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.
83 lines
2.9 KiB
83 lines
2.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.ServiceModel;
|
|
using System.ServiceModel.Channels;
|
|
using OpcServerHost.Init;
|
|
using System.Threading;
|
|
using System.Configuration;
|
|
using OpcServerHost.Common;
|
|
using QMFrameWork.Common.Serialization;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using EQUIPINTERFACETEST;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace OpcServerHost
|
|
{
|
|
class Program
|
|
{
|
|
|
|
public delegate bool ControlCtrlDelegate(int CtrlType);
|
|
[DllImport("kernel32.dll")]
|
|
private static extern bool SetConsoleCtrlHandler(ControlCtrlDelegate HandlerRoutine, bool Add);
|
|
private static ControlCtrlDelegate cancelHandler = new ControlCtrlDelegate(HandlerRoutine);
|
|
|
|
|
|
public static bool HandlerRoutine(int CtrlType)
|
|
{
|
|
switch (CtrlType)
|
|
{
|
|
case 0:
|
|
ParaInit.Exit(); //Ctrl+C关闭
|
|
break;
|
|
case 2:
|
|
ParaInit.Exit();//按控制台关闭按钮关闭
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
|
|
|
|
//读取加工参数
|
|
Console.WriteLine("Read Configure");
|
|
|
|
//装配数据工厂
|
|
QMFrameWork.Data.DataFactory.Configure(true);
|
|
|
|
ParaInit.InitParameter();
|
|
|
|
NetTcpBinding bind = new NetTcpBinding();
|
|
string serverIP = ConfigurationManager.AppSettings["ServerAddressIP"];
|
|
Uri uri = new Uri(serverIP);//从配置文D:\项目文件夹\FJC_CC_B9\truck\B9\ServicesCenter\WCF\OpcServerHost\App.config件中读取服务的Url
|
|
ServiceHost host = new ServiceHost(typeof(OpcServerHost.OpcService), uri);
|
|
////if中的代码可以没有,但是如果想利用Svctuil.exe生成代理类的时候,就需要下面的代码,否则将会报错,无法解析元数据
|
|
if (host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
|
|
{
|
|
BindingElement metaElement = new TcpTransportBindingElement();
|
|
CustomBinding metaBind = new CustomBinding(metaElement);
|
|
host.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior());
|
|
host.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), metaBind, "MEX");
|
|
}
|
|
host.Open();
|
|
|
|
|
|
Console.WriteLine("Start to monitor");
|
|
|
|
Thread.Sleep(10000);
|
|
|
|
string line = "";
|
|
do
|
|
{
|
|
Console.Write("请输入[设备:模具号:参数编号]");
|
|
line = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(line) == false)
|
|
ParaInit.InVokeComplete(line);
|
|
} while (string.IsNullOrEmpty(line) == false);
|
|
|
|
}
|
|
}
|
|
}
|
|
|