コード例 #1
0
ファイル: Communication.cs プロジェクト: ww4u/MRQUpdate
        /// <summary>
        /// 打开Can
        /// </summary>
        /// <param name="devind">设备号</param>
        /// <param name="canind">can通道号</param>
        private int InitCan(uint devind, uint canind)
        {
            if (CanHelper.VCI_CloseDevice == null)
            {
                return(-1);
            }
            try
            {
                // 先关闭设备
                CanHelper.VCI_CloseDevice(currentDeviceType, devind);
            }
            catch (Exception)
            {
                return(-1);
            }
            // 打开设备
            if (CanHelper.VCI_OpenDevice(currentDeviceType, devind, 0) != 1)
            {
                return(-1);
            }
            var config = new VCI_INIT_CONFIG
            {
                AccCode = 0,
                AccMask = 0xFFFFFFFF,
                Timing0 = 0x00,
                Timing1 = 0x14,
                Filter  = 0,
                Mode    = 0,
                Baud    = 1000000
            };

            //不关心所有的位,即,在CAN总线上的所有帧,主机都要接收
            //1M波特率
            //接收全部帧(标准帧或扩展帧)
            CanHelper.VCI_ClearBuffer(currentDeviceType, devind, canind);
            //配置can口参数,初始化失败,关闭can
            if (CanHelper.VCI_InitCAN(currentDeviceType, devind, canind, ref config) != 1)
            {
                CanHelper.VCI_CloseDevice(currentDeviceType, devind);
                return(-1);
            }
            CanHelper.VCI_StartCAN(currentDeviceType, devind, canind);
            canIsOpened = true;
            return(0);
        }
コード例 #2
0
ファイル: Communication.cs プロジェクト: ww4u/MRQUpdate
 public int CloseCan()
 {
     canIsOpened = false;
     return((int)CanHelper.VCI_CloseDevice(currentDeviceType, selectedCanIndex));
 }