Ejemplo n.º 1
0
        public bool Open(UInt32 DeviceType)
        {
            ECAN.INIT_CONFIG defaultInitConfig = new ECAN.INIT_CONFIG();
            defaultInitConfig.AccCode = 0x00000000;

            //defaultInitConfig.AccCode =
            //    this.CalculateStandardFrameAccCode((uint)DcmService.ResponseId);

            defaultInitConfig.AccMask  = 0x0;
            defaultInitConfig.Reserved = 0x0;
            defaultInitConfig.Filter   = 0x00;
            defaultInitConfig.Timing0  = 0x0;
            defaultInitConfig.Timing1  = 0x1c;
            defaultInitConfig.Mode     = 0x00;
            return(Open(DeviceType, ref defaultInitConfig));
        }
Ejemplo n.º 2
0
 public static extern ECANStatus InitCAN(
     UInt32 DeviceType,
     UInt32 DeviceInd,
     UInt32 CANInd,
     ref INIT_CONFIG InitConfig);
Ejemplo n.º 3
0
        public bool open()
        {
            if (ECANDLL.OpenDevice(device, 0, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.OpenDevice(device, 1, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.OpenDevice(device, 2, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.OpenDevice(device, 3, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.OpenDevice(device, 4, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }

            INIT_CONFIG init_config = new INIT_CONFIG();

            init_config.AccCode = 0;            //验收码
            init_config.AccMask = 0xFFFFFF;     //屏蔽码
            init_config.Filter  = 0;            //滤波方式
            init_config.Timing0 = 0;            //固定是500速率
            init_config.Timing1 = 0x1C;
            init_config.Mode    = 0;            //不屏蔽
            //初始化设备
            if (ECANDLL.InitCAN(device, 0, 0, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 0, 1, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 1, 0, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 1, 1, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 2, 0, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 2, 1, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 3, 0, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 3, 1, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 4, 0, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.InitCAN(device, 4, 1, ref init_config) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            //开始读写
            if (ECANDLL.StartCAN(device, 0, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 0, 1) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 1, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 1, 1) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 2, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 2, 1) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 3, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 3, 1) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 4, 0) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            if (ECANDLL.StartCAN(device, 4, 1) != ECANStatus.STATUS_OK)
            {
                return(false);
            }
            ECANDLL.ClearBuffer(device, 0, 0); //清除当前缓存
            ECANDLL.ClearBuffer(device, 0, 1);
            ECANDLL.ClearBuffer(device, 1, 0);
            ECANDLL.ClearBuffer(device, 1, 1);
            ECANDLL.ClearBuffer(device, 2, 0);
            ECANDLL.ClearBuffer(device, 2, 1);
            ECANDLL.ClearBuffer(device, 3, 0);
            ECANDLL.ClearBuffer(device, 3, 1);
            ECANDLL.ClearBuffer(device, 4, 0);
            ECANDLL.ClearBuffer(device, 4, 1);
            timer.Start();
            return(true);
        }