Esempio n. 1
0
        public static void Main()
        {
            txMessage.CANID   = 0x09;
            txMessage.data[0] = 0x11;
            txMessage.data[1] = 0x22;
            txMessage.data[2] = 0x33;
            txMessage.data[3] = 0x44;
            txMessage.data[4] = 0x55;
            txMessage.data[5] = 0x66;
            txMessage.data[6] = 0x77;
            txMessage.data[7] = 0x88;

            canCS.Write(false);
            Thread.Sleep(50);
            CANHandler.InitCAN(MCP2515.enBaudRate.CAN_BAUD_500K, filter, mask);
            Thread.Sleep(50);
            canCS.Write(true);
            Thread.Sleep(50);

            canCS.Write(false);
            Thread.Sleep(50);
            CANHandler.canReset();
            Thread.Sleep(50);
            canCS.Write(true);
            Thread.Sleep(50);

            // SEt baud rate
            //canCS.Write(false);
            //Thread.Sleep(50);
            //CANHandler.SetCANBaud(MCP2515.enBaudRate.CAN_BAUD_500K);
            //Thread.Sleep(50);
            //canCS.Write(true);
            //Thread.Sleep(50);

            // Baud rate commands split up so we can manually do chip select..
            canCS.Write(false);
            Thread.Sleep(50);
            CANHandler.baud1();
            Thread.Sleep(50);
            canCS.Write(true);
            Thread.Sleep(50);

            canCS.Write(false);
            Thread.Sleep(50);
            CANHandler.baud2();
            Thread.Sleep(50);
            canCS.Write(true);
            Thread.Sleep(50);

            canCS.Write(false);
            Thread.Sleep(50);
            CANHandler.baud3();
            Thread.Sleep(50);
            canCS.Write(true);
            Thread.Sleep(50);

            // Set normal mode
            canCS.Write(false);
            Thread.Sleep(50);
            CANHandler.SetCANNormalMode();
            canCS.Write(true);
            Thread.Sleep(50);

            while (true)
            {
                // The method with auto chip select
                //CANHandler.Transmit(txMessage, 100);

                // Now with manual chip select.
                canCS.Write(false);
                CANHandler.tId(txMessage);
                canCS.Write(true);

                canCS.Write(false);
                CANHandler.tRemote();
                canCS.Write(true);

                canCS.Write(false);
                CANHandler.tSend(txMessage);
                canCS.Write(true);

                canCS.Write(false);
                CANHandler.tTransmit();
                canCS.Write(true);

                Thread.Sleep(1000);
            }
        }