Example #1
0
        /// <summary>
        /// 返回所有点的元数据
        /// </summary>
        /// <returns></returns>
        private byte[] metaDataRely(IConnectState connecter)
        {
            string funCodeStr = "<1F>";

            byte[]        result   = null;
            List <string> strList  = new List <string>();
            ASCIIEncoding encoding = new ASCIIEncoding();

            foreach (var metaData in _pointMeDataList.Data)
            {
                strList.Add(metaData.Name);
                strList.Add(metaData.ValueType);
                strList.Add(metaData.IsVirtual.ToString());
                strList.Add(metaData.Length.ToString());
            }
            if (strList.Count != 0)
            {
                string resultStr;
                while (strList.Count >= 5000)
                {
                    resultStr = "";
                    for (int i = 0; i < 5000; i++)
                    {
                        resultStr = string.Concat(resultStr, "<", strList[i], ">");
                    }
                    strList.RemoveRange(0, 5000);

                    if ((connecter.Send(encoding.GetBytes(string.Concat(_headStr, funCodeStr, resultStr, _endStr))) != 1))
                    {
                        return(null);
                    }
                }
                resultStr = "";
                foreach (var s in strList)
                {
                    resultStr = string.Concat(resultStr, "<", s, ">");
                }
                if (resultStr != "")
                {
                    connecter.Send(encoding.GetBytes(string.Concat(_headStr, funCodeStr, resultStr, _endStr)));
                }
            }
            else
            {
                funCodeStr = "<2F>";
                result     = encoding.GetBytes(string.Concat(_headStr, funCodeStr, "<Point Meta data is Null>", _endStr));
            }
            return(result);
        }
Example #2
0
 private void sendBoolData(object sender, PropertyChangedEventArgs e)
 {
     lock (_locker1)
     {
         ASCIIEncoding endcoding = new ASCIIEncoding();
         var           point     = sender as IPoint <bool>;
         var           pointName = point.Name;
         var           index     = byte.Parse(e.PropertyName);
         if (_pointNames.Exists(s => s.PointName == pointName && s.Index == index))
         {
             var    value   = point.GetValue(index);
             byte   quality = point.GetQuality(index);
             string sendStr = string.Concat(_headStr, "<15>", "<", pointName, "[", index, "]", ">", "<", DataServer.ValueType.Bool, ">", "<", value, ">", "<", quality, ">", _endStr);
             _connectState.Send(endcoding.GetBytes(sendStr));
         }
     }
 }
Example #3
0
        /// <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);
        }