AHTC/RGD/RGD.OPCClient/CommModeCreate.cs
2025-05-19 09:22:33 +08:00

110 lines
3.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Reflection;
namespace RGD.OPCClient
{
/// <summary>
/// 通讯方式的类工厂
/// Creator:Richard.liu
/// </summary>
public sealed class CommModeCreate
{
//static DBOperator dbo = new DBOperator();
private static string path = "";
private CommModeCreate()
{
}
//Assembly.Load (AssemblyName) 在给定程序集的 AssemblyName 的情况下,加载程序集,return Assembly
// Assembly.CreateInstance(className)
// 从此程序集中查找IStack类型然后使用系统激活器创建它的实例。
/// <summary>
/// 根据设备索引创建获取设备状态的派生类
/// </summary>
/// <param name="Devices"></param>
/// <returns></returns>
public static IGetDeviceState CreateGetDeviceState(int Devices)
{
try
{
//20220302 暂时去掉
path = GetPath(Devices);
//path = "RGD.OPCClient";
string classname = path + ".CGetDeviceState";
return (IGetDeviceState)Assembly.Load(path).CreateInstance(classname);
}
catch (Exception ex)
{
throw (ex);
}
}
///// <summary>
///// 在串口读取数据
///// </summary>
///// <param name="Devices"></param>
///// <returns></returns>
//public static IGetSerialData CreateGetSerialData(int Devices)
//{
// try
// {
// path = GetPath(Devices);
// string classname = path + ".CGetSerialData";
// return (IGetSerialData)Assembly.Load(path).CreateInstance(classname);
// }
// catch (Exception ex)
// {
// throw (ex);
// }
//}
/// <summary>
/// 根据设备索引创建发送命令的派生类
/// </summary>
/// <param name="Devices"></param>
/// <returns></returns>
public static ISendDeviceOrder CreateSendDeviceOrder(int Devices)
{
try
{
path = GetPath(Devices);
string classname = path + ".CSendDeviceOrder";
return (ISendDeviceOrder)Assembly.Load(path).CreateInstance(classname);
}
catch (Exception ex)
{
throw (ex);
}
}
/// <summary>
/// 根据设备索引获得通讯接口的派生类
/// </summary>
/// <param name="Devices"></param>
/// <returns></returns>
private static string GetPath(int Devices)
{
try
{
//20100127
//devinfo = BaseDeviceService.GetDeviceInfo(Devices);
//DataSet ds = dbo.ExceSQL("select F_CommType from T_Base_Device where (F_CommType IS NOT NULL) AND F_DeviceIndex=" + Devices);
//if (devinfo.CommType!=null)
//{
// //dbo.Close();
// return devinfo.CommType;//ds.Tables[0].DefaultView[0]["F_CommType"].ToString();
//}
//else
//{
// //dbo.Close();
// return null;
//}
return "RGD.OPCClient";
}
catch (Exception ex)
{
throw ex;
}
}
}
}