Ejemplo n.º 1
0
        private double[] read(string tagName, int shotNo, bool isTimeAxis)
        {
            try
            {
                mds.Connect(myConfig.Host);
                mds.MdsOpen(myConfig.Tree, shotNo);
            }
            catch
            {
                throw new Exception("Failed to connect to Mds Server : " + myConfig.Host + "," + myConfig.Tree + "," + shotNo);
            }

            int status = 0;

            double[] result;
            try
            {
                if (isTimeAxis)
                {
                    result = (double[])mds.MdsValue(@"DIM_OF(BUILD_PATH(\" + tagName + "))", ref status);
                }
                else
                {
                    result = (double[])mds.MdsValue(@"\" + tagName, ref status);
                }
            }
            catch
            {
                mds.DisConnect();
                throw new Exception("Failed to read tagName : " + tagName);
            }

            mds.DisConnect();
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// upload 1/all channels in 1 shot
        /// </summary>
        private void Upload(int localShot, int mdsShot, string localChannelDataSourceUri)
        {
            MDSplus mds = new MDSplus();

            mds.Connect(myConfig.ServerConfig.Host);
            mds.MdsOpen(myConfig.ServerConfig.Tree, mdsShot);

            int status = 0;

            //如果没有传入 channelNo 的获取路径
            if (localChannelDataSourceUri == null)
            {
                foreach (var s in myConfig.RealChannelsDic)
                {
                    //利用短路,可以同时判断 null 和 false
                    if (s.Value.Enable == false)
                    {
                        continue;
                    }
                    status = 0;

                    //获取采样率
                    sampleRate = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeSampleRateSrcUri(s.Value, localShot)).ObjectVal);
                    //获取长度
                    length = Convert.ToInt32(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeLengthSrcUri(s.Value, localShot)).ObjectVal);
                    //获取开始时间
                    startTime = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeStartTimeSrcUri(s.Value, localShot)).ObjectVal);
                    //获取数据
                    data = (double[])MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeDataSrcUri(s.Value, localShot, length)).ObjectVal;

                    //利用数据的 double数组、BUILD_SIGNAL(开始时间,总时间,1/采样率) 上传一个 Mds 的 signal 类型数据
                    mds.MdsPut("\\" + s.Value.Tag, "BUILD_SIGNAL($1,*,MAKE_DIM(*,$2 : $3 : $4))",
                               data, startTime, length * 1.0 / sampleRate + startTime, 1.0 / sampleRate,
                               ref status);
                }
            }

            //必定手动上传
            else
            {
                try
                {
                    if (myConfig.RealChannelsDic[localChannelDataSourceUri] != null && myConfig.RealChannelsDic[localChannelDataSourceUri].Enable == true)
                    {
                        string uri = AiRequestUriComposer.ComposeSampleRateSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot);
                        sampleRate = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(uri).ObjectVal);
                        length     = Convert.ToInt32(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeLengthSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot)).ObjectVal);
                        startTime  = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeStartTimeSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot)).ObjectVal);
                        data       = (double[])MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeDataSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot, length)).ObjectVal;

                        mds.MdsPut("\\" + myConfig.RealChannelsDic[localChannelDataSourceUri].Tag, "BUILD_SIGNAL($1,*,MAKE_DIM(*,$2 : $3 : $4))",
                                   data, startTime, length * 1.0 / sampleRate + startTime, 1.0 / sampleRate,
                                   ref status);
                    }
                }
                catch
                {
                    // unlock after finished
                    lock (myStateLock)
                    {
                        State = Status.Idle;
                    }
                    logger.Error("手动上传错误!数据源:" + localChannelDataSourceUri);
                    throw new Exception("手动上传错误!请检查相关参数设置!");
                }
            }

            System.Diagnostics.Debug.WriteLine("Upload finished!", DateTime.Now.ToLocalTime().ToString("HH:mm:ss.fff"));
            logger.Info("上传成功!");
            mds.DisConnect();

            // unlock after finished
            lock (myStateLock)
            {
                State = Status.Idle;
            }

            if (myConfig.MasterOrSlave == 2)
            {
                Process.GetCurrentProcess().Kill();
            }
        }