Ejemplo n.º 1
0
 private void CarTest_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         RecvThread.Abort();
         if (canOpen)
         {
             CanZLG.VCI_CloseDevice(m_devtype, 0);
         }
         timer1.Stop();
         SimulateTimer.Stop();
         sw_Record.Close();
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 2
0
        private void StartCanButton_Click(object sender, EventArgs e)
        {
            if (canOpen)
            {
                canOpen = false;
                CanZLG.VCI_CloseDevice(m_devtype, 0);
            }

            CanZLG.VCI_INIT_CONFIG init_config = new CanZLG.VCI_INIT_CONFIG();
            init_config.Mode    = 0;
            init_config.Filter  = 1;
            init_config.AccCode = 0;
            init_config.AccMask = 0xffffffff;
            init_config.AccCode = 0x451 << 20;
            init_config.AccMask = 0x000FFFFF;
            //  init_config.Timing0 = 0;
            // init_config.Timing1 = 0x1c;
            if (CanZLG.VCI_OpenDevice(m_devtype, 0, 0) != CanZLG.STATUS_OK)
            {
                MessageBox.Show("Open device fault!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            byte[] baud;
            baud = BitConverter.GetBytes(0x60007); //500k 0x60007
            //UInt32 baud;
            //baud = 0x1000c8;
            if (CanZLG.VCI_SetReference(m_devtype, 0, can_ind1, 0, baud) != CanZLG.STATUS_OK)
            {
                MessageBox.Show("设置波特率错误,打开设备失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                CanZLG.VCI_CloseDevice(m_devtype, 0);
                return;
            }

            if (CanZLG.VCI_InitCAN(m_devtype, 0, can_ind1, ref init_config) != CanZLG.STATUS_OK)
            {
                MessageBox.Show("Init can fault!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                CanZLG.VCI_CloseDevice(m_devtype, 0);
                return;
            }
            if (CanZLG.VCI_StartCAN(m_devtype, 0, can_ind1) != CanZLG.STATUS_OK)
            {
                MessageBox.Show("Start Failed");
            }

            /*
             * baud = BitConverter.GetBytes(0x1000c8);//250k
             * init_config.Timing0 = 1;
             * init_config.Timing1 = 0x1c;
             * if (CanZLG.VCI_SetReference(m_devtype, 0, can_ind0, 0, baud) != CanZLG.STATUS_OK)
             * {
             *
             *  MessageBox.Show("设置波特率错误,打开设备失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *  CanZLG.VCI_CloseDevice(m_devtype, 0);
             *  return;
             * }
             *
             * if (CanZLG.VCI_InitCAN(m_devtype, 0, can_ind0, ref init_config) != CanZLG.STATUS_OK)
             * {
             *
             *  //MessageBox.Show("Init can fault!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *
             *  //CanZLG.VCI_CloseDevice(m_devtype, 0);
             *  //return;
             * }
             * if (CanZLG.VCI_StartCAN(m_devtype, 0, can_ind0) != CanZLG.STATUS_OK)
             * {
             *  MessageBox.Show("Start Failed");
             * }
             */
            canOpen = true;
            StartCanButton.Enabled = false;
            ModeButton.Enabled     = true;
            ResetCanButton.Enabled = true;
            //RecTimer.Start();
        }