public bool Remove(string pointName) { var pointNameStruct = pointName.Split('['); byte index = 0; if (pointNameStruct.Length >= 2) { byte.TryParse(pointNameStruct[1].Replace("]", ""), out index); } string type; pointIndex.Find(pointNameStruct[0], out type); PointNameGroup nameGroup = new PointNameGroup { PointName = pointNameStruct[0], Index = index, Type = type }; return(Remove(nameGroup)); }
public bool Remove(PointNameGroup nameGroup) { bool result = false; if (_pointNames.Exists((s) => (s == nameGroup))) { var type = nameGroup.Type; if (type == DataServer.ValueType.Bool) { var point = PointMapping <bool> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendBoolData; result = true; } else if (type == DataServer.ValueType.Byte) { var point = PointMapping <byte> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendByteData; result = true; } else if (type == DataServer.ValueType.Int16) { var point = PointMapping <short> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendShortData; result = true; } else if (type == DataServer.ValueType.UInt16) { var point = PointMapping <ushort> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendUshortData; result = true; } else if (type == DataServer.ValueType.Int32) { var point = PointMapping <int> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendIntData; result = true; } else if (type == DataServer.ValueType.UInt32) { var point = PointMapping <uint> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendUintData; result = true; } else if (type == DataServer.ValueType.Float) { var point = PointMapping <float> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendFloatData; result = true; } else if (type == DataServer.ValueType.Float) { var point = PointMapping <string> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged -= sendStringData; result = true; } } return(result); }
public bool Add(PointNameGroup nameGroup) { if (_pointNames.Exists((s) => (s == nameGroup))) { return(false); } var type = nameGroup.Type; if (!_pointNames.Exists(s => s.PointName == nameGroup.PointName)) { if (type == DataServer.ValueType.Bool) { var point = PointMapping <bool> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendBoolData; } else if (type == DataServer.ValueType.Byte) { var point = PointMapping <byte> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendByteData; } else if (type == DataServer.ValueType.Int16) { var point = PointMapping <short> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendShortData; } else if (type == DataServer.ValueType.UInt16) { var point = PointMapping <ushort> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendUshortData; } else if (type == DataServer.ValueType.Int32) { var point = PointMapping <int> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendIntData; } else if (type == DataServer.ValueType.UInt32) { var point = PointMapping <uint> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendUintData; } else if (type == DataServer.ValueType.Float) { var point = PointMapping <float> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendFloatData; } else if (type == DataServer.ValueType.String) { var point = PointMapping <string> .GetInstance(_log).GetPoint(nameGroup.PointName); point.PropertyChanged += sendStringData; } } _pointNames.Add(nameGroup); return(true); }
private int writeMapping(PointNameGroup nameGroup, string value) { string pointName = nameGroup.PointName; byte index = nameGroup.Index; string type = nameGroup.Type; List <string> result = new List <string>(); if (type == DataServer.ValueType.Bool) { bool temp; if (bool.TryParse(value, out temp)) { var pointMapping = PointMapping <bool> .GetInstance(_log); return(pointMapping.SetValue(pointName, temp, index)); } else { return(-1); } } else if (type == DataServer.ValueType.Byte) { byte temp; if (byte.TryParse(value, out temp)) { var pointMapping = PointMapping <byte> .GetInstance(_log); return(pointMapping.SetValue(pointName, temp, index)); } else { return(-1); } } else if (type == DataServer.ValueType.UInt16) { ushort temp; if (ushort.TryParse(value, out temp)) { var pointMapping = PointMapping <ushort> .GetInstance(_log); return(pointMapping.SetValue(pointName, temp, index)); } else { return(-1); } } else if (type == DataServer.ValueType.Int16) { short temp; if (short.TryParse(value, out temp)) { var pointMapping = PointMapping <short> .GetInstance(_log); return(pointMapping.SetValue(pointName, temp, index)); } else { return(-1); } } else if (type == DataServer.ValueType.UInt32) { uint temp; if (uint.TryParse(value, out temp)) { var pointMapping = PointMapping <uint> .GetInstance(_log); return(pointMapping.SetValue(pointName, temp, index)); } else { return(-1); } } else if (type == DataServer.ValueType.Int32) { int temp; if (int.TryParse(value, out temp)) { var pointMapping = PointMapping <int> .GetInstance(_log); return(pointMapping.SetValue(pointName, temp, index)); } else { return(-1); } } else if (type == DataServer.ValueType.Float) { float temp; if (float.TryParse(value, out temp)) { var pointMapping = PointMapping <float> .GetInstance(_log); return(pointMapping.SetValue(pointName, temp, index)); } else { return(-1); } } return(-1); }
/// <summary> /// 根据类型不同,反馈不同类型数据 /// </summary> /// <param name="nameGroup"></param> /// <returns></returns> private List <string> readFeedBack(PointNameGroup nameGroup) { string pointName = nameGroup.PointName; byte index = nameGroup.Index; string type = nameGroup.Type; List <string> result = new List <string>(); if (type == DataServer.ValueType.Bool) { var pointMapping = PointMapping <bool> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value.ToString()); result.Add(quality.ToString()); } else if (type == DataServer.ValueType.Byte) { var pointMapping = PointMapping <byte> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value.ToString()); result.Add(quality.ToString()); } else if (type == DataServer.ValueType.UInt16) { var pointMapping = PointMapping <ushort> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value.ToString()); result.Add(quality.ToString()); } else if (type == DataServer.ValueType.Int16) { var pointMapping = PointMapping <short> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value.ToString()); result.Add(quality.ToString()); } else if (type == DataServer.ValueType.UInt32) { var pointMapping = PointMapping <uint> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value.ToString()); result.Add(quality.ToString()); } else if (type == DataServer.ValueType.Int32) { var pointMapping = PointMapping <int> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value.ToString()); result.Add(quality.ToString()); } else if (type == DataServer.ValueType.Float) { var pointMapping = PointMapping <float> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value.ToString()); result.Add(quality.ToString()); } else if (type == DataServer.ValueType.String) { var pointMapping = PointMapping <string> .GetInstance(_log); var value = pointMapping.GetValue(pointName, index); byte quality = pointMapping.GetPoint(pointName).GetQuality(index); result.Add(string.Concat(pointName, "[", index, "]")); result.Add(type); result.Add(value); result.Add(quality.ToString()); } return(result); }
/// <summary> /// 返回取消订阅数据 /// </summary> /// <param name="data"></param> /// <param name="connecter"></param> /// <returns></returns> private byte[] cancelSubCodeRely(string[] source, IConnectState connecter) { byte[] result = null; List <string> errorInfoList = new List <string>(); string errorInfo = null; ASCIIEncoding encoding = new ASCIIEncoding(); if (source.Length % 2 == 0) { for (int i = 0; i < source.Length; i = i + 2) { var pointName = source[i]; var pointType = source[i + 1]; var pointNameArrary = pointName.Split(new char[] { '[' }, StringSplitOptions.RemoveEmptyEntries); byte index = 0; string type; if (pointNameArrary.Length >= 2) { byte.TryParse(pointNameArrary[1].Replace("]", ""), out index); } if (_pointMeDataList.Find(pointNameArrary[0], out type)) { if (pointType.ToLower() == type) { PointNameGroup nameGroup = new PointNameGroup { PointName = pointNameArrary[0], Index = index, Type = type }; //反馈第一次订阅值 //取消添加订阅 SubscribeItem item; if (_subscribeGroup.Exists(s => s.ConnectState.Equals(connecter))) { item = _subscribeGroup.Find(s => s.ConnectState.Equals(connecter)); if (!item.Remove(pointName)) { errorInfo = string.Concat("the point name:", pointName, " not Subscrible"); } } else { errorInfo = string.Concat("the point name:", pointName, " not Subscrible"); } } else { errorInfo = string.Concat("the point name:", pointName, " type : ", pointType, " type not match"); errorInfoList.Add(errorInfo); } } else { errorInfo = string.Concat("Not found the point name:", pointName); errorInfoList.Add(errorInfo); } } } else { errorInfoList.Add("steam length error"); } if (errorInfoList.Count != 0) { string funCodeStr = "<26>"; errorInfo = ""; foreach (var s in errorInfoList) { errorInfo = string.Concat(errorInfo, "<", s, ">"); } errorInfo = string.Concat(_headStr, funCodeStr, "<", errorInfo, ">", _endStr); connecter.Send(encoding.GetBytes(errorInfo)); } else { string funCodeStr = "<16>"; result = encoding.GetBytes(string.Concat(_headStr, funCodeStr, _endStr)); } return(result); }
private byte[] writeCodeRely(string[] source) { byte[] result = null; List <string> strList = new List <string>(); List <string> errorInfoList = new List <string>(); if (source.Length % 3 == 0) { for (int i = 0; i < source.Length; i = i + 3) { var pointName = source[i]; var pointType = source[i + 1]; var pointValue = source[i + 2]; string typeInMapping; var pointNameStruct = pointName.Split('['); byte index = 0; if (pointNameStruct.Length >= 2) { byte.TryParse(pointNameStruct[1].Replace("]", ""), out index); } if (_pointMeDataList.Find(pointNameStruct[0], out typeInMapping)) { if (pointType.ToLower() == typeInMapping) { PointNameGroup nameGroup = new PointNameGroup { PointName = pointNameStruct[0], Index = index, Type = typeInMapping }; if (writeMapping(nameGroup, pointValue) == -1) { errorInfoList.Add(string.Concat("the point name:", pointName, " type : ", pointType, " write error")); } } else { errorInfoList.Add(string.Concat("the point name:", pointName, " type : ", pointType, " type not match")); } } else { errorInfoList.Add(string.Concat("Not found the point name:", pointName)); } } } else { errorInfoList.Add("steam length error"); } ASCIIEncoding encoding = new ASCIIEncoding(); if (errorInfoList.Count != 0) { string funCodeStr = "<22>"; string errorInfo = ""; foreach (var s in errorInfoList) { errorInfo = string.Concat(errorInfo, "<", s, ">"); } result = encoding.GetBytes(string.Concat(_headStr, funCodeStr, errorInfo, _endStr)); } else { string funCodeStr = "<12>"; result = encoding.GetBytes(string.Concat(_headStr, funCodeStr, _endStr)); } return(result); }
/// <summary> /// 返回读数据 /// </summary> /// <param name="source"></param> /// <param name="funCode"></param> /// <returns></returns> private byte[] readCodeRely(string[] source) { byte[] result = null; List <string> strList = new List <string>(); string errorInfo = null; if (source.Length % 2 == 0) { for (int i = 0; i < source.Length; i = i + 2) { var pointName = source[i]; var pointType = source[i + 1]; string typeInMapping; var pointNameArrary = pointName.Split('['); byte index = 0; if (pointNameArrary.Length >= 2) { pointNameArrary[1] = pointNameArrary[1].Replace("]", ""); byte.TryParse(pointNameArrary[1], out index); } if (_pointMeDataList.Find(pointNameArrary[0], out typeInMapping)) { if (pointType.ToLower() == typeInMapping) { PointNameGroup nameGroup = new PointNameGroup { PointName = pointNameArrary[0], Index = index, Type = typeInMapping }; strList.AddRange(readFeedBack(nameGroup)); } else { errorInfo = string.Concat("the point name:", pointName, " type : ", pointType, " type not match"); break; } } else { errorInfo = string.Concat("Not found the point name:", pointName); break; } } } else { errorInfo = "steam length error"; } ASCIIEncoding encoding = new ASCIIEncoding(); if (errorInfo != null) { string funCodeStr = "<21>"; errorInfo = string.Concat("<", errorInfo, ">"); result = encoding.GetBytes(string.Concat(_headStr, funCodeStr, errorInfo, _endStr)); } else { string resultStr = ""; foreach (var s in strList) { resultStr = string.Concat(resultStr, "<", s, ">"); } string funCodeStr = "<11>"; result = encoding.GetBytes(string.Concat(_headStr, funCodeStr, resultStr, _endStr)); } return(result); }