コード例 #1
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);
        }
コード例 #2
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);
        }