Esempio n. 1
0
        public bool Open(UInt32 DeviceType, ref INIT_CONFIG init)
        {
            if (IsOpened)
            {
                return(true);
            }

            if (ECANDLL.OpenDevice(DeviceType, 0, 0) != ECANStatus.STATUS_OK)
            {
                MessageBox.Show("Usb Can打开失败", "错误", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            if (ECANDLL.InitCAN(DeviceType, 0, 0, ref init) != ECANStatus.STATUS_OK)
            {
                MessageBox.Show("Usb Can初始化失败", "错误", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            if (ECANDLL.ClearBuffer(DeviceType, 0, 0) != ECANStatus.STATUS_OK)
            {
                MessageBox.Show("清除CAN缓冲区失败", "错误", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            if (ECANDLL.StartCAN(DeviceType, 0, 0) != ECANStatus.STATUS_OK)
            {
                MessageBox.Show("启动CAN失败", "错误", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                opened = true;
                Console.WriteLine("USB CAN open successfully!");
                return(true);
            }
        }