/// <summary> /// 获取所有的串口或者端口配置,如果没有配置信道协议或者数据协议,返回空的信道协议和数据协议名 /// </summary> /// <returns></returns> public List <CPortProtocolConfig> GetComOrPortConfig(bool bIsCom = true) { // 先遍历所有串口号 List <CPortProtocolConfig> listResult = new List <CPortProtocolConfig>(); List <int> listPorts = null; if (bIsCom) { // 获取串口号 listPorts = GetAllComPorts(); } else { // 获取端口号 listPorts = GetAllPorts(); } for (int i = 0; i < listPorts.Count; ++i) { // 获取信道协议 XmlDllInfo dllChannel = GetChannelDllByComOrPort(listPorts[i], bIsCom); XmlDllInfo dllData = GetDataDllByComOrPort(listPorts[i], bIsCom); // 即使没有配任何数据协议和信道协议,返回空的信道协议和数据协议名 CPortProtocolConfig config = new CPortProtocolConfig(); config.PortNumber = listPorts[i]; if (dllChannel != null) { config.ProtocolChannelName = dllChannel.Name; // 判断端口的启动模式 for (int j = 0; j < dllChannel.Ports.Count; ++j) { if (dllChannel.Ports[j].PortNumber == listPorts[i]) { //通讯方式写入,TCP协议或者UDP协议,并不在配置文件中存储 config.BTcpOrUdp = dllChannel.Ports[j].BTcpOrUdp; //启动模式写入,是否启动,并不在配置文件中存储 config.BAutoStart = dllChannel.Ports[j].BAutoStart; break; } } } if (dllData != null) { config.ProtocolDataName = dllData.Name; // 判断端口的启动模式, 数据协议应该和信道协议一致的 for (int j = 0; j < dllData.Ports.Count; ++j) { if (dllData.Ports[j].PortNumber == listPorts[i]) { //通讯方式写入,TCP协议或者UDP协议,并不在配置文件中存储 config.BTcpOrUdp = dllChannel.Ports[j].BTcpOrUdp; //启动模式写入,是否启动,并不在配置文件中存储 config.BAutoStart = dllData.Ports[j].BAutoStart; break; } } } listResult.Add(config); } return(listResult); }
/// <summary> /// 判断dll是否有效 /// </summary> /// <param name="dll"></param> /// <returns></returns> public static bool AssertDllValid(XmlDllInfo dll) { try { string filepath = dll.BaseDir + "\\" + dll.FileName; Assembly asm = Assembly.LoadFile(filepath); foreach (XmlMember member in dll.Members) { if (IsTagValid(member.Tag)) { // tag有效,继续判断实例化类是否错误,如果没有该类型,返回null if (null == asm.CreateInstance(member.ClassName)) { return(false); } } else { // 遇到不认识的tag return(false); } } // 创建实例都正确的话 return(true); } catch (System.Exception ex) { Debug.WriteLine(ex.ToString()); return(false); } }
public XmlDllInfo GetInfoByName(string name) { XmlDllInfo info = null; foreach (var item in this.m_dllInfo.Infos) { if (!item.Enabled) { continue; } if (item.Name != name) { continue; } info = item; break; } return(info); }
public static ISoil Soil(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.Tag_Data_Soil) as ISoil); }
public static IUBatch UDisk(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_DATA_UBatch) as IUBatch); }
public static IFlashBatch Flash(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_DATA_FlashBatch) as IFlashBatch); }
public static IDown Down(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_DATA_Down) as IDown); }
public static IUp Up(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_DATA_Up) as IUp); }
public static IBeidou500 Beidou500(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_CHANNEL_BEIDOU_500) as IBeidou500); }
public static ICable Cable(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_CHANNEL_CABLE) as ICable); }
/// <summary> /// 创建信道协议类型实例 /// </summary> /// <param name="info"></param> /// <returns></returns> public static object CreateInstance(XmlDllInfo info, string tag) { try { /* * 读取配置文件 * 获取程序集的完全限定名称,类名称 * */ if (!info.Enabled) { return(null); } if (string.IsNullOrEmpty(info.BaseDir)) { return(null); } String curDir = Environment.CurrentDirectory; if (string.IsNullOrEmpty(info.FileName)) { return(null); } string assemblyString = string.Format(@"{0}\{1}", info.BaseDir, info.FileName); if (!File.Exists(assemblyString)) { return(null); } if (info.Members.Count <= 0) { return(null); } string classname = string.Empty; foreach (var item in info.Members) { if (item.Tag == tag) { classname = item.ClassName; break; } } if (string.IsNullOrEmpty(classname)) { return(null); } /* * 加载程序集 * */ Assembly asm = Assembly.LoadFile(assemblyString); /* * 创建实例 * */ return(asm.CreateInstance(classname)); } catch (System.Exception exp) { System.Diagnostics.Debug.WriteLine(exp.Message); } return(null); }
public static IBeidouNormal BeidouNormal(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_CHANNEL_BEIDOU_NORMAL) as IBeidouNormal); }
public static IHDGprs HDGprs(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_CHANNEL_HDGPRS) as IHDGprs); }
public static IGsm GSM(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_CHANNEL_GSM) as IGsm); }
public static ITransparen Transparen(XmlDllInfo info) { return(Reflect.CreateInstance(info, CS_DEFINE.TAG_CHANNEL_TRANSPAREN) as ITransparen); }