Пример #1
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            short err;

            if (m_dev >= 0)
            {
                err = D2KDASK.D2K_Release_Card((ushort)m_dev);
            }
        }
Пример #2
0
        public void CmdExitApp(ICommand sender)
        {
            D2KDASK.D2K_Release_Card(0);
            Defs.Device1.acCanClose();
            Defs.Device2.acCanClose();
            Defs.brun1 = false;
            Defs.brun2 = false;
            Defs.Thread1.Abort();
            Defs.Thread2.Abort();
            Defs.Can1ReadStatus = false;
            Defs.Can2ReadStatus = false;
            if (guiMain != null && !guiMain.IsDisposed)
            {
                guiMain.Close();
            }

            guiMain = null;



            Application.Exit();
        }
Пример #3
0
        private void button3_Click(object sender, EventArgs e)                        //设置按键
        {
            Form2 subForm = new Form2();

            subForm.ShowDialog();
            if (m_dev >= 0)
            {
                short ret;
                ret = D2KDASK.D2K_Release_Card((ushort)m_dev);
            }
            cardT   = (ushort)subForm.comboBox1.SelectedIndex;
            cardnum = (ushort)subForm.comboBox2.SelectedIndex;
            m_dev   = D2KDASK.D2K_Register_Card(card_value[cardT], cardnum);
            if (m_dev < 0)
            {
                MessageBox.Show("D2K_Register_Card error!");
                button1.Enabled = false;
            }
            else
            {
                button1.Enabled = true;
                this.Text       = "AI Read: " + Card_Name[cardT];
            }
        }
Пример #4
0
        static int Main(string[] args)
        {
            var rawAdData = new short[short.MaxValue - short.MinValue];

            for (short i = short.MinValue; i < short.MaxValue; ++i)
            {
                rawAdData[i - short.MinValue] = i;
            }

            var voltage = new double[rawAdData.Length];

            var res = D2KDASK.D2K_Register_Card(D2KDASK.DAQ_2213, 0);

            if (res < 0)
            {
                Console.Error.WriteLine("Failed to register card.");
                return(1);
            }

            ushort cardNumber = (ushort)res;

            const int Channels = 2;
            var       channels = new ushort[Channels];
            var       ranges   = new ushort[Channels];

            for (int i = 0; i < Channels; ++i)
            {
                channels[i] = (ushort)i;
                ranges[i]   = D2KDASK.AD_B_10_V;
            }

            // Is it possible to call this function like this?
            // D2KDASK.D2K_AI_ContVScale(D2KDASK.AD_B_10_V, rawAdData, voltage, voltage.Length);
            // Why is card number necessary for such a simple function?
            res = D2KDASK.D2K_AI_ContVScale(cardNumber, D2KDASK.AD_B_10_V,
                                            rawAdData, voltage, voltage.Length);
            if (res != D2KDASK.NoError)
            {
                Console.Error.WriteLine("D2K_AI_ContVScale failed: {0}.", res);
                D2KDASK.D2K_Release_Card(cardNumber);
                return(1);
            }

            // Output: 305.17578125
            // It is about ADRange / (short.MaxValue + 1) * 1e6.
            for (int i = 0; i < voltage.Length; ++i)
            {
                Console.WriteLine("{0}", DoubleConverter.ToExactString(voltage[i] / rawAdData[i] * 1e6));
            }

            var scale = 10.0 / (short.MaxValue + 1);

            var rawAdData2 = new short[]
            {
                -32767, -32766, -10000,
                -1000, -2000, -3000,
                -1, -2, -3,
                1, 2, 3,
                1000, 2000, 3000,
                32767, 32766, 10000,
            };
            var voltage2 = new double[rawAdData2.Length];

            res = D2KDASK.D2K_AI_ContVScale(cardNumber, D2KDASK.AD_B_10_V,
                                            rawAdData2, voltage2, voltage2.Length);
            if (res != D2KDASK.NoError)
            {
                Console.Error.WriteLine("D2K_AI_ContVScale failed: {0}.", res);
                D2KDASK.D2K_Release_Card(cardNumber);
                return(1);
            }

            for (int i = 0; i < rawAdData2.Length; ++i)
            {
                Console.WriteLine("{0} {1} {2}",
                                  rawAdData2[i],
                                  DoubleConverter.ToExactString(voltage2[i]),
                                  DoubleConverter.ToExactString(rawAdData2[i] * scale));
            }

            D2KDASK.D2K_Release_Card(cardNumber);

            Util.Pause();

            return(0);
        }
Пример #5
0
        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
        }