Esempio n. 1
0
        //-------------------------------------------------------------------------

        /**
         *  Writes a CAN message to log file.
         *
         *  @param      r_canMsg        message
         *  @param      IsTransmit      ???
         */
        private void DumpCanMsg(CANMessage r_canMsg, bool IsTransmit)
        {
            DateTime dt = DateTime.Now;

            try
            {
                using (StreamWriter sw = new StreamWriter(Path.Combine(this.startup_path,
                                                                       dt.Year.ToString("D4") + dt.Month.ToString("D2") +
                                                                       dt.Day.ToString("D2") + "-CanTrace.log"), true))
                {
                    if (IsTransmit)
                    {
                        // get the byte transmitted
                        int transmitvalue = (int)(r_canMsg.getData() & 0x000000000000FF00);
                        transmitvalue /= 256;

                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") +
                                     " TX: id=" + r_canMsg.getID().ToString("D2") +
                                     " len= " + r_canMsg.getLength().ToString("X8") +
                                     " data=" + r_canMsg.getData().ToString("X16") +
                                     " " + r_canMsg.getFlags().ToString("X2") +
                                     " character = " + GetCharString(transmitvalue) +
                                     "\t ts: " + r_canMsg.getTimeStamp().ToString("X16") +
                                     " flags: " + r_canMsg.getFlags().ToString("X2"));
                    }
                    else
                    {
                        // get the byte received
                        int receivevalue = (int)(r_canMsg.getData() & 0x0000000000FF0000);
                        receivevalue /= (256 * 256);
                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") +
                                     " RX: id=" + r_canMsg.getID().ToString("D2") +
                                     " len= " + r_canMsg.getLength().ToString("X8") +
                                     " data=" + r_canMsg.getData().ToString("X16") +
                                     " " + r_canMsg.getFlags().ToString("X2") +
                                     " character = " + GetCharString(receivevalue) +
                                     "\t ts: " + r_canMsg.getTimeStamp().ToString("X16") +
                                     " flags: " + r_canMsg.getFlags().ToString("X2"));
                    }
                }
            }
            catch (Exception E)
            {
                Console.WriteLine("Failed to write to logfile: " + E.Message);
            }
        }
Esempio n. 2
0
        private void DumpCanMsg(CANMessage canMsg, bool IsTransmit)
        {
            DateTime dt = DateTime.Now;
            try
            {
                using (StreamWriter sw = new StreamWriter(@"c:\" + dt.Year.ToString("D4") + dt.Month.ToString("D2") + dt.Day.ToString("D2") + "-CanTrace.log", true))
                {
                    if (IsTransmit)
                    {
                        // get the byte transmitted
                        int transmitvalue = (int)(canMsg.getData() & 0x000000000000FF00);
                        transmitvalue /= 256;

                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") + " TX: id=" + canMsg.getID().ToString("X2") + " len= " + canMsg.getLength().ToString("X8") + " data=" + canMsg.getData().ToString("X16") + " " + canMsg.getFlags().ToString("X2") + "\t ts: " + canMsg.getTimeStamp().ToString("X16") + " flags: " + canMsg.getFlags().ToString("X2"));
                    }
                    else
                    {
                        // get the byte received
                        int receivevalue = (int)(canMsg.getData() & 0x0000000000FF0000);
                        receivevalue /= (256 * 256);
                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") + " RX: id=" + canMsg.getID().ToString("X2") + " len= " + canMsg.getLength().ToString("X8") + " data=" + canMsg.getData().ToString("X16") + " " + canMsg.getFlags().ToString("X2") + "\t ts: " + canMsg.getTimeStamp().ToString("X16") + " flags: " + canMsg.getFlags().ToString("X2"));
                    }
                }
            }
            catch (Exception E)
            {
                Console.WriteLine("Failed to write to logfile: " + E.Message);
            }
        }