예제 #1
0
        /// <summary>
        /// 打开或关闭飞轮1电源
        /// </summary>
        /// <returns></returns>
        public bool OpenElecSource(string state, out string error, string experiment_name,
                                   string experiment_memeber, string experiment_product)
        {
            bool results = true;

            error = string.Empty;

            if (state == "ON")
            {
                #region 数据采集卡

                Defs.ModifyState("4", '0');
                D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2));
                DateTime dt = DateTime.Now;

                #region 采集卡获得浪涌电流
                ushort[] chans = new ushort[1];
                chans[0] = 1;
                ushort[] ranges    = new ushort[1];
                ushort[] chan_data = new ushort[1];
                double   temp      = 0.0;
                double[] MotorCur  = new double[1000]; //浪涌电流
                TimeSpan span;
                int      length_wave = 0;

                DateTime[] dttime = new DateTime[1000];

                ranges[0] = D2KDASK.AD_B_10_V | D2KDASK.AI_DIFF;

                short ret1 = D2KDASK.D2K_AI_MuxScanSetup(0, 1, chans, ranges);
                if (ret1 < 0)
                {
                    error = "Wave current error!";
                    Defs.ModifyState("4", '1');
                    D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2));
                    return(false);
                }


                while (true)
                {
                    D2KDASK.D2K_AI_ReadMuxScan(0, chan_data);
                    D2KDASK.D2K_AI_VoltScale(0, D2KDASK.AD_B_10_V, (short)chan_data[0], out temp);
                    MotorCur[length_wave] = Math.Round(temp, 3);
                    if (length_wave == 1000)
                    {
                        break;
                    }
                    dttime[length_wave] = DateTime.Now;
                    length_wave         = length_wave + 1;
                    span = DateTime.Now - dt;
                    if (span.TotalMilliseconds > 10)
                    {
                        break;
                    }
                }
                for (int i = 0; i < length_wave; i++)
                {
                    WriteDataToDatabaseWave("4", "7", MotorCur[i].ToString(), dttime[i].ToString(), experiment_name, experiment_memeber, experiment_product);
                }
                #endregion


                #endregion


                #region can线程启动
                if (Defs.Can1ReadStatus == false)
                {
                    Defs.Can1ReadStatus = true;
                    Defs.Thread1.Start();
                }
                if (Defs.Can2ReadStatus == false)
                {
                    Defs.Can2ReadStatus = true;
                    Defs.Thread2.Start();
                }
                #endregion
            }
            else
            {
                Defs.ModifyState("4", '1');
                D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2));
                Defs.Motor4RSuceess = false;
            }
            return(results);
        }