Example #1
0
        /// <summary>
        /// CanBus連線
        /// </summary>
        /// <returns> 連線成功回傳1,否則回傳0</returns>
        public static int CanConnect()
        {
            //開始連線
            if (m_bOpen == 1)
            {
                CanBusTool.VCI_CloseDevice(m_devtype, m_devind);
                m_bOpen = 0;
            }
            else
            {
                //開啟第一個device,用於轉向馬達
                m_devtype  = m_arrdevtype[1];
                m_devind   = 0;
                m_canind   = 0;
                m_devind_2 = 0;
                m_canind_2 = 1;

                if (CanBusTool.VCI_OpenDevice(m_devtype, m_devind, 0) == 0)
                {
                    return(0);
                }

                m_bOpen = 1;
                VCI_INIT_CONFIG config = new VCI_INIT_CONFIG();
                config.AccCode = System.Convert.ToUInt32("0x" + "40e00000", 16);
                config.AccMask = System.Convert.ToUInt32("0x" + "FFFFFFFF", 16);

                /*config.AccCode = System.Convert.ToUInt32("0x" + "41600000", 16);
                *  config.AccMask = System.Convert.ToUInt32("0x" + "0FFFFFFF", 16);*/
                config.Timing0 = System.Convert.ToByte("0x" + "03", 16);
                config.Timing1 = System.Convert.ToByte("0x" + "1c", 16);
                config.Filter  = (Byte)(1);
                config.Mode    = (Byte)0;

                VCI_INIT_CONFIG config2 = new VCI_INIT_CONFIG();
                config2.AccCode = System.Convert.ToUInt32("0x" + "30e00000", 16);
                config2.AccMask = System.Convert.ToUInt32("0x" + "FFFFFFFF", 16);

                /*config2.AccCode = System.Convert.ToUInt32("0x" + "31600000", 16);
                *  config2.AccMask = System.Convert.ToUInt32("0x" + "0FFFFFFF", 16);*/
                config2.Timing0 = System.Convert.ToByte("0x" + "03", 16);
                config2.Timing1 = System.Convert.ToByte("0x" + "1c", 16);
                config2.Filter  = (Byte)(1);
                config2.Mode    = (Byte)0;

                CanBusTool.VCI_InitCAN(m_devtype, m_devind, m_canind, ref config);
                CanBusTool.VCI_InitCAN(m_devtype, m_devind_2, m_canind_2, ref config2);

                ComputerThread = new Thread(StartComputerMonitorThread);
                MotorThread    = new Thread(StartMotorMonitorThread);
            }
            if (m_bOpen == 1)
            {
                return(1);             //CAN連線
            }
            else
            {
                return(0);//CAN斷線
            }
        }
Example #2
0
 public static extern UInt32 VCI_InitCAN(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_INIT_CONFIG pInitConfig);
Example #3
0
        /// <summary>
        /// CanBus連線
        /// </summary>
        /// <returns> 連線成功回傳1,否則回傳0</returns>
        public static int CanConnect()
        {
            //開始連線
            if (m_bOpen == 1)
            {
                CanBusTool.VCI_CloseDevice(m_devtype, m_devind);
                m_bOpen = 0;
            }
            else
            {
                //開啟第一個device,用於轉向馬達
                m_devtype = m_arrdevtype[1];
                m_devind = 0;
                m_canind = 0;
                m_devind_2 = 0;
                m_canind_2 = 1;

                if (CanBusTool.VCI_OpenDevice(m_devtype, m_devind, 0) == 0)
                {
                    return 0;
                }

                m_bOpen = 1;
                VCI_INIT_CONFIG config = new VCI_INIT_CONFIG();
                config.AccCode = System.Convert.ToUInt32("0x" + "40e00000", 16);
                config.AccMask = System.Convert.ToUInt32("0x" + "FFFFFFFF", 16);
                /*config.AccCode = System.Convert.ToUInt32("0x" + "41600000", 16);
                config.AccMask = System.Convert.ToUInt32("0x" + "0FFFFFFF", 16);*/
                config.Timing0 = System.Convert.ToByte("0x" + "03", 16);
                config.Timing1 = System.Convert.ToByte("0x" + "1c", 16);
                config.Filter = (Byte)(1);
                config.Mode = (Byte)0;

                VCI_INIT_CONFIG config2 = new VCI_INIT_CONFIG();
                config2.AccCode = System.Convert.ToUInt32("0x" + "30e00000", 16);
                config2.AccMask = System.Convert.ToUInt32("0x" + "FFFFFFFF", 16);
                /*config2.AccCode = System.Convert.ToUInt32("0x" + "31600000", 16);
                config2.AccMask = System.Convert.ToUInt32("0x" + "0FFFFFFF", 16);*/
                config2.Timing0 = System.Convert.ToByte("0x" + "03", 16);
                config2.Timing1 = System.Convert.ToByte("0x" + "1c", 16);
                config2.Filter = (Byte)(1);
                config2.Mode = (Byte)0;

                CanBusTool.VCI_InitCAN(m_devtype, m_devind, m_canind, ref config);
                CanBusTool.VCI_InitCAN(m_devtype, m_devind_2, m_canind_2, ref config2);

                ComputerThread = new Thread(StartComputerMonitorThread);
                MotorThread = new Thread(StartMotorMonitorThread);

            }
            if (m_bOpen == 1) return 1;//CAN連線
            else return 0;//CAN斷線
        }
Example #4
0
 public static extern UInt32 VCI_InitCAN(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_INIT_CONFIG pInitConfig);