예제 #1
0
        /// <summary>
        /// 使用配置文件初始化AIThing
        /// </summary>
        /// <param name="dataFileParentDirectory">存放所有数据文件的根文件夹路径</param>
        /// <param name="configFilePath">配置文件完整路径</param>
        public void InitAIThing(string dataFileParentDirectory, string configFilePath)
        {
            //用读到的配置文件初始化AI
            staticConfig = new StaticConfig(configFilePath);

            subInit(dataFileParentDirectory, staticConfig);
        }
예제 #2
0
        public void InitAIThing(string dataFileParentDirectory)
        {
            //使用默认值初始化AI
            StaticConfig staticConfig = new StaticConfig();

            subInit(dataFileParentDirectory, staticConfig);
        }
예제 #3
0
        /// <summary>
        /// 读取配置文件,构造新实例
        /// </summary>
        /// <param name="filePath">配置文件完整路径</param>
        public StaticConfig(string filePath)
        {
            //读取配置文件
            FileStream   fs = new FileStream(filePath, FileMode.Open);
            StreamReader fileStreamReader = new StreamReader(fs);
            string       configJson       = fileStreamReader.ReadToEnd();

            fileStreamReader.Close();
            //反序列化后为属性赋值
            StaticConfig readConfig = JsonConvert.DeserializeObject <StaticConfig>(configJson);

            AITriggerType               = readConfig.AITriggerType;
            TerminalConfig              = readConfig.TerminalConfig;
            MinimumVolt                 = readConfig.MinimumVolt;
            MaximumVolt                 = readConfig.MaximumVolt;
            SampleRate                  = readConfig.SampleRate;
            TriggerSource               = readConfig.TriggerSource;
            AITriggerEdge               = readConfig.AITriggerEdge;
            AnalogTriggerLevel          = readConfig.AnalogTriggerLevel;
            ClkSource                   = readConfig.ClkSource;
            ClkActiveEdge               = readConfig.ClkActiveEdge;
            AISamplesMode               = readConfig.AISamplesMode;
            SamplesPerChannel           = readConfig.SamplesPerChannel;
            ReadSamplePerTime           = readConfig.ReadSamplePerTime;
            Channel                     = readConfig.Channel;
            AutoReArm                   = readConfig.AutoReArm;
            ChannelNames                = readConfig.ChannelNames;
            TotalSampleLengthPerChannel = readConfig.TotalSampleLengthPerChannel;
        }
예제 #4
0
        private void subInit(string dataFileParentDirectory, StaticConfig staticConfig)
        {
            DataFileParentDirectory = dataFileParentDirectory;

            ai.InitAI(staticConfig);

            //订阅AI的event
            subscribeEvent();
            //如果AutoReArm为真,则自动开始任务
            if (AutoReArm == true)
            {
                TryArm();
            }
        }
예제 #5
0
        /// <summary>
        /// 从文件中读出指定通道的数据片段
        /// </summary>
        /// <param name="channelNo">指定的通道,从0开始</param>
        /// <param name="start">大于等于0</param>
        /// <param name="length">如果小于0则代表从start开始,读余下的所有点;大于等于零则代表读length个数的点</param>
        /// <returns></returns>
        public double[] LoadDataFromFile(int channelNo, int start, long length)
        {
            StaticConfig config          = new StaticConfig(configFilePath);
            int          totalChannelNo  = config.ChannelNames.Count();
            long         totalDataLength = config.TotalSampleLengthPerChannel;
            //真正读数据的长度
            long readDataCount;

            if (start >= 0)
            {
                if (channelNo > totalChannelNo)
                {
                    throw new Exception("通道号错误!");
                }
                if (length < 0)
                {
                    readDataCount = totalDataLength - start;
                }
                else
                {
                    readDataCount = length;
                    if (start + readDataCount > totalDataLength)
                    {
                        throw new Exception("读取请求位置和长度不匹配!");
                    }
                }
            }
            else
            {
                throw new Exception("读取请求数据起始位置应大于等于0!");
            }

            double[] result     = new double[readDataCount];
            int      doubleSize = sizeof(double);

            FileStream   dataFileStream   = new FileStream(dataFilePath, FileMode.Open);
            BinaryReader fileBinaryReader = new BinaryReader(dataFileStream);

            for (long i = 0; i < readDataCount; i++)
            {
                //找到对应double的位置
                fileBinaryReader.BaseStream.Seek((start * totalChannelNo + channelNo + i * totalChannelNo) * doubleSize, SeekOrigin.Begin);
                var a = fileBinaryReader.BaseStream.Position;
                result[i] = fileBinaryReader.ReadDouble();
            }
            fileBinaryReader.Close();

            return(result);
        }
예제 #6
0
 public void InitAI(StaticConfig config)
 {
     AITriggerType      = config.AITriggerType;
     TerminalConfig     = config.TerminalConfig;
     MinimumVolt        = config.MinimumVolt;
     MaximumVolt        = config.MaximumVolt;
     SampleRate         = config.SampleRate;
     TriggerSource      = config.TriggerSource;
     AITriggerEdge      = config.AITriggerEdge;
     AnalogTriggerLevel = config.AnalogTriggerLevel;
     ClkSource          = config.ClkSource;
     ClkActiveEdge      = config.ClkActiveEdge;
     AISamplesMode      = config.AISamplesMode;
     SamplesPerChannel  = config.SamplesPerChannel;
     ReadSamplePerTime  = config.ReadSamplePerTime;
     channel            = config.Channel;
     AutoReArm          = config.AutoReArm;
 }