using System; using System.Reflection; namespace RGD.OPCClient { /// /// 通讯方式的类工厂 /// Creator:Richard.liu /// 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类型,然后使用系统激活器创建它的实例。 /// /// 根据设备索引创建获取设备状态的派生类 /// /// /// 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); } } ///// ///// 在串口读取数据 ///// ///// ///// //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); // } //} /// /// 根据设备索引创建发送命令的派生类 /// /// /// 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); } } /// /// 根据设备索引获得通讯接口的派生类 /// /// /// 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; } } } }