Example #1
0
        // the region contains a class constructor
        #region Constructor

        // constructor
        public UcCanTrace(CanMessageSendTool can)
        {
            InitializeComponent();

            // parent
            CanTool = can;

            // grid
            createGrid();
            // menu
            createMenu();
            grid.ContextMenuStrip = menu;

            // send tool
            sendWrkr = new canTraceUtils.sendWorker(CanTool, this);

            mode = traceMode.pause;


            //ts = new canTraceUtils.timestamp();
            ts = new canTraceUtils.timestamp_offset();

            conv    = new canTraceUtils.mConverter();
            conv.TS = ts;

            tbPlayFrom.KeyPress += Tools.textBoxIntOnlyEvent;
            tbPlayTo.KeyPress   += Tools.textBoxIntOnlyEvent;

            updateMsgCounter();


            cbTraceMode.Items.Add("All");
            cbTraceMode.Items.Add("Selected");
            cbTraceMode.SelectedIndex = 0;

            // icons
            btnTrace.Image    = Properties.Resources.icon_record;
            btnSendStep.Image = Properties.Resources.icon_step;
            btnPlay.Image     = Properties.Resources.icon_play;
            btnClear.Image    = Properties.Resources.icon_clear;

            btnSendStep.Enabled  = false;
            btnPlay.Enabled      = false;
            btnSendRange.Enabled = false;
            btnClear.Enabled     = false;

            tbPlayFrom.Enabled  = btnPlay.Enabled;
            tbPlayTo.Enabled    = btnPlay.Enabled;
            lblSendFrom.Enabled = btnPlay.Enabled;
            lblSendTo.Enabled   = btnPlay.Enabled;

            lblSendFrom.Font = new Font("Consolas", 9, FontStyle.Italic);
            lblSendTo.Font   = lblSendFrom.Font;

            cbTraceMode.Font = new Font("Consolas", 8f);

            lblTotalMsgs.Font = new Font("Calibri", 9.0f);

            foreach (DataGridViewColumn col in grid.Columns)
            {
                col.HeaderCell.Style.Font = new Font("Calibri", 9.0f, FontStyle.Bold);
            }

            grid.DefaultCellStyle.Font = new Font("Consolas", 8.5f);//, FontStyle.Italic);

            // System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
            //  ToolTip1.SetToolTip(this.btnTrace, "Start/Stop Recording");
        }
Example #2
0
        // convert message list to string
        public static string msg_list_to_string(List <canAnalyzer.canMessage2> ls, timestamp_offset usr_ts = null, bool add_header = true)
        {
            // converter
            mConverter conv = new canTraceUtils.mConverter();
            // timestamp
            timestamp_offset ts = usr_ts == null ? new canTraceUtils.timestamp_offset() : usr_ts;

            conv.TS = ts;
            // builder
            StringBuilder sb = new StringBuilder();

            // append the header string
            if (add_header)
            {
                sb.Append(conv.getHeaderString());
                sb.Append(Environment.NewLine);
            }

            // append the messages (fast edition)
            for (int i = 0; i < ls.Count; i++)
            {
                var msg = ls[i];

                // update timestamp
                int new_ts = ts.update(msg.timestamp_absolute);

                // pad positins
                int sb_start_pos = sb.Length;
                int pad_cnt;

                // 1) time
                if (new_ts < 10000)
                {
                    sb.Append(' ');
                }
                sb.AppendFormat("{0} s.", ((double)new_ts / 1000).ToString("F3"));

                pad_cnt = sb.Length - sb_start_pos;
                sb.Append(' ', tsLenMin - pad_cnt);

                // 2) CAN id
                sb_start_pos = sb.Length;
                sb.Append("0x");
                sb.Append(msg.Id.GetIdAsString());

                pad_cnt = sb.Length - sb_start_pos;
                sb.Append(' ', idLenMin - pad_cnt);

                // 3) CAN dlc
                sb_start_pos = sb.Length;
                sb.Append(msg.Id.GetDlcAsString());

                pad_cnt = sb.Length - sb_start_pos;
                sb.Append(' ', dlcMinLen - pad_cnt);

                // 4) data, works faster then 'getdatastring'
                if (msg.Data != null && msg.Data.Length > 0)
                {
                    for (int d = 0; d < msg.Data.Length - 1; d++)
                    {
                        sb.Append("0x");
                        sb.Append(msg.Data[d].ToString("X2"));
                        sb.Append(", ");
                    }
                    // the last one
                    sb.Append("0x");
                    sb.Append(msg.Data[msg.Data.Length - 1].ToString("X2"));
                }

                sb.Append(Environment.NewLine);
            }

            // to string
            return(sb.ToString());
        }