using System; using System.IO; using System.Data; using System.Collections.Generic; using Mesnac.Equips; using Mesnac.Equips.BaseInfo; using System.Runtime.InteropServices; using System.Data.SqlClient; namespace Mesnac.Equip.ConfigInfo.Test.GroupNet { public class Equip : BaseEquip { private Mesnac.Equips.Connection.GroupNet.ConnType connType = null; private Dictionary _dicIP = null; #region 辅助方法 - 获取设备组IP字典 public Dictionary GetIPS() { this.connType = (Mesnac.Equips.Connection.GroupNet.ConnType)this.Main.ConnType; this._dicIP = new Dictionary(); try { if (!String.IsNullOrEmpty(this.connType.IPList)) { string[] strItems = this.connType.IPList.Split(new char[] { ';' }); if (null != strItems && strItems.Length > 0) { foreach (string strItem in strItems) { if (!String.IsNullOrEmpty(strItem)) { string[] items = strItem.Split(new char[] { ':' }); if (null != items && items.Length > 0) { this._dicIP.Add(items[0], items[1]); } } } } } } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("打开设备失败:解析设备配置错误-" + ex.Message); } return this._dicIP; } #endregion public override bool Open() { if (this._dicIP == null) { this._dicIP = GetIPS(); } if (this._dicIP.ContainsKey(this.Name)) { string ip = this._dicIP[this.Name]; ICSharpCode.Core.LoggingService.Debug(String.Format("{0}:{1}", this.Name, ip)); return true; } else { ICSharpCode.Core.LoggingService.Debug(String.Format("设备配置中不存在此设备组的IP-{0}", this.Name)); return false; } } int iPost = 0; public override bool Read(string block, int start, int len, out object[] buff) { //if (this._dicIP == null) //{ // this._dicIP = GetIPS(); //} //if (this._dicIP.ContainsKey(this.Name)) //{ // string ip = this._dicIP[this.Name]; // ICSharpCode.Core.LoggingService.Debug(String.Format("{0}:{1}", this.Name, ip)); //} //else //{ // ICSharpCode.Core.LoggingService.Debug(String.Format("设备配置中不存在此设备组的IP-{0}", this.Name)); //} if (iPost >= int.MaxValue - 10) { iPost = 0; } iPost++; buff = new object[1] { iPost }; return true; } public override bool Write(int block, int start, object[] buff) { return false; } public override void Close() { } } }