Ejemplo n.º 1
0
        public bool WriteCpms(string measurement, Cpm[] cpms, int offset, int count)
        {
            if (offset + count >= cpms.Length)
            {
                return(false);
            }
            List <string> paramList = new List <string>();

            for (int i = offset; i < count + offset; i++)
            {
                var cpm = cpms[i];
                if (cpm.ValueType != SmParamType.Signal)
                {
                    continue;
                }
                var timeStamp = "";
                //fixed:不能插入时间
                timeStamp = YUtil.GetUtcTimestampMs(cpm.PickTime) + "000000";
                var param = $"{measurement},param={cpm.Name.Replace(" ","")} value={cpm.Value} {timeStamp}";
                paramList.Add(param);
            }
            var resp = WriteMulti(paramList.ToArray());

            if (resp.Length > 0)
            {
                Console.WriteLine(Encoding.UTF8.GetString(resp));
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取写入 InfluxDb 的字符串
        /// 使用 StringBuilder 为了防止内存溢出
        /// </summary>
        /// <param name="measurement"></param>
        /// <param name="cpms"></param>
        /// <param name="pickTime"></param>
        /// <returns></returns>
        public StringBuilder GetCpms2WriteString(string measurement, List <Cpm> cpms, DateTime pickTime)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append($"{measurement},tag=采集参数 ");
            var  timestamp = YUtil.GetUtcTimestampMs(pickTime) + "000000";
            bool valid     = false;

            foreach (var cpm in cpms)
            {
                if (cpm.ValueType != SmParamType.Signal)
                {
                    continue;
                }
                //fix: 由于名字空格不能插入的情况
                builder.Append($"{cpm.Name.Replace(" ", "")}={cpm.Value},");
                valid = true;
            }
            //无有效参数的时候返回空的 sb
            if (valid == false)
            {
                builder.Clear();
                return(builder);
            }

            builder.Remove(builder.Length - 1, 1);
            builder.Append($" {timestamp}");
            builder = builder.Replace("/", string.Empty).Replace("\\", string.Empty);
            return(builder);
        }
Ejemplo n.º 3
0
        public bool WriteCpms(string measurement, params Cpm[] cpms)
        {
            List <string> paramList = new List <string>();

            foreach (var cpm in cpms)
            {
                if (cpm.ValueType != SmParamType.Signal)
                {
                    continue;
                }
                var timeStamp = "";
                //fixed:不能插入时间
                timeStamp = YUtil.GetUtcTimestampMs(cpm.PickTime) + "000000";
                var param = $"{measurement},param={cpm.Name} value={cpm.Value} {timeStamp}";
                paramList.Add(param);
            }
            var resp = WriteMulti(paramList.ToArray());

            if (resp.Length > 0)
            {
                Console.WriteLine(Encoding.UTF8.GetString(resp));
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
 public static MqAlarm CreateOneAlarm(int code = -1)
 {
     return(new MqAlarm()
     {
         alarmType = AlarmType.OtherErr,
         axisCode = "GD2017122701ls01",
         code = code,
         CpmName = "直径",
         message = "直径值超过Plc设定的最大值",
         time = YUtil.GetUtcTimestampMs(DateTime.Now),
         meter = 1103.3f,
         workCode = "GD2017122701",
         machineCode = MachineConfig.MachineDict.First().Key
     });
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 往influxDb中写入数据
        /// </summary>
        /// <param name="tags">类似:param=hello,code=112211</param>
        /// <param name="val">数据值</param>
        /// <param name="measurement">表名</param>
        /// <returns></returns>
        public byte[] Write(string measurement, string tags, object val, DateTime?dateTime = null)
        {
            var postData = $"{measurement},{tags} value={val} ";

            if (dateTime.HasValue)
            {
                //转换成纳秒
                //fixed:不能插入时间
                postData += YUtil.GetUtcTimestampMs(dateTime.Value) + "000000";
            }
            postData = postData.Replace("/", string.Empty).Replace("\\", string.Empty);
            var httpUri = $"{DbAddr}/write?db={DbName}";

            try {
                using (var webClient = new WebClient()) {
                    var result = webClient.UploadData(httpUri, Encoding.UTF8.GetBytes(postData));
                    return(result);
                }
            } catch (WebException ex) {
                return(Encoding.UTF8.GetBytes(ex.ToString()));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 派发模拟排产任务
        /// </summary>
        public static void DispatchMockSchTask(string machineCode, int id = 0)
        {
            var mockEffects = UnityIocService.ResolveDepend <MockEffects>();
            var task        = YUtil.GetJsonObjectFromFile <MqSchTask>(AssetsHelper.GetAssets().MockMqSchTaskJson);

            task.workcode = YUtil.GetRandomString(8);
            task.id       = id;
            task.taskId   = id.ToString();
            task.maccode  = machineCode;
            foreach (var axis in task.axisParam)
            {
                axis.maccode  = task.maccode;
                axis.axiscode = YUtil.GetRandomString(10);
                axis.taskId   = task.taskId;
            }
            JavaTime startTime = new JavaTime()
            {
                time = YUtil.GetUtcTimestampMs(YUtil.GetRandomTime(DateTime.Now.AddDays(-1), DateTime.Now))
            };

            task.pstime = startTime;
            task.pdtime = startTime;
            App.Store.Dispatch(mockEffects.MockSchTaskAccept(new MockActions.MockSchTaskAccpet(task)));
        }
Ejemplo n.º 7
0
 public PipeCmd()
 {
     SendTime = YUtil.GetUtcTimestampMs(DateTime.Now);
 }