コード例 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        public Channel(uint mChannelIndex, string mChannelName, Device pParentDevice)
        {
            this.m_IsStarted     = false;
            this.m_IsInitialized = false;

            this.p_StatusTimer          = new Timer();
            this.p_StatusTimer.Interval = DEFAULT_STATUS_ERRORINFO_TIMER_INTERVAL;
            this.p_StatusTimer.Elapsed += StatusTimer_Elapsed;

            this.p_RcvTimer          = new Timer();
            this.p_RcvTimer.Interval = DEFAULT_RCV_TIMER_INTERVAL;
            this.p_RcvTimer.Elapsed += RcvTimer_Elapsed;

            this.p_SendTimer          = new Timer();
            this.p_SendTimer.Interval = DEFAULT_SEND_TIMER_INTERVAL;
            this.p_SendTimer.Elapsed += SendTimer_Elapsed;

            this.m_ChannelIndex = mChannelIndex;
            this.m_ChannelName  = mChannelName;
            this.p_ParentDevice = pParentDevice;

            this.p_InitConfig = CAN.CreateBasicInitConfig();
            this.m_BaudRate   = CAN.CHANNEL_DEFAULT_BAUDRATE;

            this.InitCAN(this.m_BaudRate, ref this.p_InitConfig);

            this.p_StatusTimer.Start();
            this.p_RcvTimer.Start();
            this.p_SendTimer.Start();
        }
コード例 #2
0
        /// <summary>
        /// 初始化CAN
        /// </summary>
        /// <param name="mBaudRate">波特率</param>
        /// <param name="pInitConfig">初始化CAN的配置参数</param>
        /// <returns></returns>
        public uint InitCAN(int mBaudRate, ref INIT_CONFIG pInitConfig)
        {
            INIT_CONFIG pConfig = CAN.CreateBasicInitConfig();

            CAN.ConfigBaudRate(m_BaudRate, ref pConfig);

            if (pConfig.Timing0 != pInitConfig.Timing0 || pConfig.Timing1 != pInitConfig.Timing1)
            {
                Logger.Info(string.Format("baudrate[{0}] and initConfig[0x{1}:0x{2}] not match",
                                          m_BaudRate, pInitConfig.Timing0.ToString("x"), pInitConfig.Timing1.ToString("x")));
                return((uint)CAN_RESULT.ERR_UNKNOWN);
            }

            this.m_BaudRate   = mBaudRate;
            this.p_InitConfig = pInitConfig;
            if (CANDLL.InitCAN((UInt32)p_ParentDevice.DeviceType, p_ParentDevice.DeviceIndex, m_ChannelIndex, ref pInitConfig) == CAN.CAN_DLL_RESULT_SUCCESS)
            {
                Logger.Info(string.Format("init channel[{0}] successful.", m_ChannelName));
                this.m_IsInitialized = true;
                return((uint)CAN_RESULT.SUCCESSFUL);
            }

            this.m_IsInitialized = false;
            uint         result        = (uint)CAN_RESULT.ERR_UNKNOWN;
            CAN_ERR_INFO pCANErrorInfo = new CAN_ERR_INFO();

            if (ReadErrInfo(ref pCANErrorInfo) == (uint)CAN_RESULT.SUCCESSFUL)
            {
                result = pCANErrorInfo.ErrCode;
            }

            Logger.Info(string.Format("init channel[{0}] failed: [0x{1}].", m_ChannelName, result.ToString("x")));
            return(result);
        }