Esempio n. 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);
        }
        protected void Init()
        {
            InitResources();
            InitShortcutManager();
            //InitMenuBar();
            InitToolBars();
            InitStatusBar();
            InitContextMenus();
            InitTrayIcon();
            this._wm  = new WinGui.Utility.WindowManage(this, this.panelGround);
            this.Text = CardApplication.applicationName;


            #region 数据采集卡初始化
            short m_dev = D2KDASK.D2K_Register_Card(D2KDASK.DAQ_2205, 0);
            if (m_dev < 0)
            {
                _statusInfo.Text = "Select Device First!";
                MessageBox.Show("Select Device First!");
            }
            else
            {
                short ret = D2KDASK.D2K_DIO_PortConfig(0, D2KDASK.Channel_P1A, D2KDASK.OUTPUT_PORT);
                if (ret < 0)
                {
                    _statusInfo.Text = "D2K_DIO_PortConfig error!";
                    MessageBox.Show("D2K_DIO_PortConfig error!");
                    D2KDASK.D2K_Release_Card(0);
                }

                D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2));
            }
            #endregion

            string   Commu = System.Configuration.ConfigurationSettings.AppSettings["CommunicationString1"];
            string[] para  = Commu.Split(';');


            string[] com  = para[0].Split('=');
            string   can1 = com[1].Trim();


            string[] baud  = para[1].Split('=');
            string   baud1 = baud[1].Trim();

            com = para[2].Split('=');
            ReadTimeOutValue_can1 = com[1].Trim();
            com = para[3].Split('=');
            WriteTimeOutValue_can1 = com[1].Trim();



            Commu = System.Configuration.ConfigurationSettings.AppSettings["CommunicationString2"];
            para  = Commu.Split(';');


            com = para[0].Split('=');
            string can2 = com[1].Trim();


            baud = para[1].Split('=');
            string baud2 = baud[1].Trim();


            com = para[2].Split('=');
            ReadTimeOutValue_can2 = com[1].Trim();


            com = para[3].Split('=');
            WriteTimeOutValue_can2 = com[1].Trim();

            #region can 总线配置
            bool syncflag    = false;
            uint nWriteCount = 10;
            uint nReadCount  = 10;

            int nRet1 = Defs.Device1.acCanOpen(can1, syncflag, nReadCount, nWriteCount);
            int nRet2 = Defs.Device2.acCanOpen(can2, syncflag, nReadCount, nWriteCount);

            if (nRet1 < 0 && nRet2 < 0)
            {
                _statusInfo.Text = "Failed to open the CAN1 and CAN2 port, please check the CAN1 and CAN2 port name!";
                MessageBox.Show("Failed to open the CAN1 and CAN2 port, please check the CAN1 and CAN2 port name!");
            }
            #endregion


            int nRet;

            #region can1 配置
            if (nRet1 >= 0)
            {
                nRet = Defs.Device1.acEnterResetMode();
                if (nRet < 0)
                {
                    _statusInfo.Text = "Failed to stop opertion1!";
                    MessageBox.Show("Failed to stop opertion1!");
                    Defs.Device1.acCanClose();
                }
                else
                {
                    nRet = Defs.Device1.acSetBaud(Convert.ToUInt32(baud1));
                    if (nRet < 0)
                    {
                        _statusInfo.Text = "Failed to set baud 1!";
                        MessageBox.Show("Failed to set baud 1!");
                        Defs.Device1.acCanClose();
                    }
                    else
                    {
                        nRet = Defs.Device1.acSetTimeOut(Convert.ToUInt32(ReadTimeOutValue_can1), Convert.ToUInt32(WriteTimeOutValue_can1));
                        if (nRet < 0)
                        {
                            _statusInfo.Text = "Failed to set Timeout 1!";
                            MessageBox.Show("Failed to set Timeout 1!");
                            Defs.Device1.acCanClose();
                        }
                        else
                        {
                            nRet = Defs.Device1.acEnterWorkMode();
                            if (nRet < 0)
                            {
                                _statusInfo.Text = "Failed to restart operation!";
                                MessageBox.Show("Failed to restart operation!");
                                Defs.Device1.acCanClose();
                            }
                        }
                    }
                }
            }
            #endregion

            #region can2 配置
            if (nRet2 >= 0)
            {
                nRet = Defs.Device2.acEnterResetMode();
                if (nRet < 0)
                {
                    _statusInfo.Text = "Failed to stop opertion2!";
                    MessageBox.Show("Failed to stop opertion2!");
                    Defs.Device2.acCanClose();
                }
                else
                {
                    nRet = Defs.Device2.acSetBaud(Convert.ToUInt32(baud2));
                    if (nRet < 0)
                    {
                        _statusInfo.Text = "Failed to set baud 2!";
                        MessageBox.Show("Failed to set baud 2!");
                        Defs.Device2.acCanClose();
                    }
                    else
                    {
                        nRet = Defs.Device2.acSetTimeOut(Convert.ToUInt32(ReadTimeOutValue_can2), Convert.ToUInt32(WriteTimeOutValue_can2));
                        if (nRet < 0)
                        {
                            _statusInfo.Text = "Failed to set Timeout 2!";
                            MessageBox.Show("Failed to set Timeout 2!");
                            Defs.Device2.acCanClose();
                        }
                        else
                        {
                            nRet = Defs.Device2.acEnterWorkMode();
                            if (nRet < 0)
                            {
                                _statusInfo.Text = "Failed to restart operation!";
                                MessageBox.Show("Failed to restart operation!");
                                Defs.Device2.acCanClose();
                            }
                        }
                    }
                }
            }
            #endregion
        }