コード例 #1
0
ファイル: SomebusDriver.cs プロジェクト: awdxqqqaz/CAN-panel
        public override bool InitializeDevice(string[] args)
        {
            useDeviceIndex = 0;
            useCANIndex    = DeviceUtil.SelectSubDeviceByIndex(0, 1, "CAN端口");
            if (ECANDLL.OpenDevice(deviceType, useDeviceIndex, 0)
                != ECANStatus.STATUS_OK)
            {
                GetErrorInfo();
                return(false);
            }
            INIT_CONFIG InitialConfig = new INIT_CONFIG();

            InitialConfig.AccCode = 0;
            InitialConfig.AccMask = 0xffffff;
            InitialConfig.Filter  = 0;
            InitialConfig.Mode    = 0;

            List <string> SelectBaudRate = new List <string>()
            {
                "250kbps", "500kbps"
            };
            FrmDeviceSelect FrmSelectBaudRate = new FrmDeviceSelect();

            FrmSelectBaudRate.LoadDeviceList(SelectBaudRate);
            FrmSelectBaudRate.SetTitle("请选择合适的波特率");
            FrmSelectBaudRate.ShowDialog();
            if (FrmSelectBaudRate.selectedText == "250kbps")
            {
                //250kbps
                InitialConfig.Timing0 = 0x01;
                InitialConfig.Timing1 = 0x1c;
            }
            else if (FrmSelectBaudRate.selectedText == "500kbps")
            {
                //250kbps
                InitialConfig.Timing0 = 0x00;
                InitialConfig.Timing1 = 0x1c;
            }
            else
            {
                // TODO add more baud rate setting here
                return(false);
            }
            if (ECANDLL.InitCAN(deviceType, useDeviceIndex, useCANIndex, ref InitialConfig) != ECANStatus.STATUS_OK)
            {
                ECANDLL.CloseDevice(deviceType, useDeviceIndex);
                GetErrorInfo();
                return(false);
            }
            //uint bRel = ECANDLL.ClearBuffer(deviceType, useDeviceIndex, useCANIndex);
            //Logger.logDebug("Clean Buffer结果(1 成功,0 失败):" + bRel.ToString());
            //之所以发送这么一个毫无意义的东西是驱动的锅, 砍死开发驱动的
            SendData(new CANData(0x1, new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 }));
            return(true);
        }
コード例 #2
0
        public override bool InitializeDevice(string[] args)
        {
            useDeviceIndex = 0;
            useCANIndex    = useCANIndex = DeviceUtil.SelectSubDeviceByIndex(0, 1, "CAN端口");
            uint openResult = iTekAnalyst2API.VCI_OpenDevice(devideType, useDeviceIndex, 0);

            if (openResult == 0)
            {
                Logger.logError("iTek(CANPRO)打开失败!原因:" + openResult.ToString());
                return(false);
            }
            VCI_INIT_CONFIG config = new VCI_INIT_CONFIG();

            config.AccCode = 0;
            config.AccMask = 0xffffff;
            List <string> selectBaudRate = new List <string>()
            {
                "250kbps", "500kbps"
            };
            FrmDeviceSelect frmSelectBaudRate = new FrmDeviceSelect();

            frmSelectBaudRate.LoadDeviceList(selectBaudRate);
            frmSelectBaudRate.SetTitle("请选择合适的波特率");
            frmSelectBaudRate.ShowDialog();
            if (frmSelectBaudRate.selectedText == "250kbps")
            {
                //250kbps
                config.Timing0 = 0x01;
                config.Timing1 = 0x1c;
            }
            else if (frmSelectBaudRate.selectedText == "500kbps")
            {
                //250kbps
                config.Timing0 = 0x00;
                config.Timing1 = 0x1c;
            }
            else
            {
                return(false);
            }
            frmSelectBaudRate.Dispose();
            config.Filter = 0;
            config.Mode   = 0;
            uint initResult = iTekAnalyst2API.VCI_InitCAN(devideType, useDeviceIndex, useCANIndex, ref config);

            Logger.logInfo("iTek(CANPRO)初始化结果:" + initResult.ToString());
            uint startResult = iTekAnalyst2API.VCI_StartCAN(devideType, useDeviceIndex, useCANIndex);

            Logger.logInfo("iTek(CANPRO)启动结果:" + startResult.ToString());
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Some device will have more than one channel
        /// You can use this function to let user select
        /// </summary>
        /// <param name="minVal"></param>
        /// <param name="maxVal"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static uint SelectSubDeviceByIndex(uint minVal, uint maxVal, string comment)
        {
            FrmDeviceSelect PopFrm   = new FrmDeviceSelect();
            List <string>   infoList = new List <string>();

            for (uint i = minVal; i <= maxVal; i++)
            {
                infoList.Add(comment + " No." + i.ToString());
            }
            PopFrm.LoadDeviceList(infoList);
            PopFrm.SetTitle("请选择" + comment);
            PopFrm.ShowDialog();
            uint returnValue = (uint)(PopFrm.selectedIndex + minVal);

            PopFrm.Dispose();
            return(returnValue);
        }