예제 #1
0
        /*************************************************************************
         *
         *  ########   ######   ########   ##     ##     ###   #########
            #        ##     ##  ##     #  ###    ###    ## #       ##
            ######  ##       ## ## ## ##  ## #   # #    #  ##      ##
            #       ##       ## ## ## ##  ## #  ## #   ##   ##     ##
            #        ##     ##  ##     #  ## ## #  #  ########     ##
            #         #######   ##     ## ##  ###  #  #      ##    ##

                       #######      ###   ##########   ###
                       #     ##    ## #       #       ## #
                       #      ##   #  ##      ##      ## ##
                       #      ##  #    ##     ##     ##   ##
                       #     ##  ########     ##     #######
                       #######   #      ##    ##    #       #
         *
         **************************************************************************/
        /// <summary>
        /// Name: FormatData
        /// 
        /// </summary>
        /// <param name="InData"></param>
        /// <param name="type"></0: Send Data></1: Receive>
        /// <returns></returns>
        private string FormatData(String InData, DataType type, DateTime CurrTime, TabNum tabNum, bool first_rec)
        {
            String OutData;
            String TimeStamp;
            DataMode currMode;
            bool LR_Mode;
            bool show_timeStamp;

            // Add Time Stamp
            TimeStamp = CurrTime.ToString("dd MMM HH:mm:ss.fff");

            // Get Current data view mode
            switch (tabNum)
            {
                case TabNum.Tab1:
                    currMode = Tab1DataViewMode;
                    LR_Mode = Tab1LR.Checked;
                    show_timeStamp = true;
                    break;
                case TabNum.Tab2:
                    LR_Mode = Tab2LR.Checked;
                    currMode = Tab2DataViewMode;
                    show_timeStamp = Tab2_TimeStamp.Checked;
                    break;
                case TabNum.Tab3:
                    LR_Mode = Tab3LR.Checked;
                    currMode = t3_dataView;
                    show_timeStamp = true;
                    break;
                default:
                    LR_Mode = false;
                    currMode = Tab1DataViewMode;
                    show_timeStamp = true;
                    break;
            }

            if ((first_rec == false) && (type == DataType.Receive))
            {
                // in receive string
                // Add to rich text
                if (currMode == DataMode.Text)
                {
                    OutData = InData;
                    if (LR_Mode == true)
                    {
                        OutData = Change_CRLF(OutData);
                    }
                }
                else
                {
                    OutData = StringToHexString(InData);
                }
            }
            else
            {
                // Format data for receive data
                // For marciano test. we donot use time stamp for run automation test and check error
                if (show_timeStamp == false)
                {
                    TimeStamp = "";
                }

                switch (type)
                {
                    case DataType.Receive:
                        OutData = "R <" + TimeStamp + ">: ";
                        break;
                    case DataType.Send:
                        OutData = "T <" + TimeStamp + ">: ";
                        break;
                    default:
                        OutData = "Error: Can not format Message";
                        break;
                }

                // Add to rich text
                if (currMode == DataMode.Text)
                {
                    OutData += InData;
                    if (LR_Mode == true)
                    {
                        OutData = Change_CRLF(OutData);
                    }
                }
                else
                {
                    OutData += StringToHexString(InData);
                }
            }
            // Add new line
            //if (type == DataType.Send)
            //{
            //    OutData += "\n";
            //}
            return OutData;
        }
예제 #2
0
        /*************************************************
         *      ###     #######   #######
               # ##    #     ##  ##     ##
              ##  #    #      ## ##      #
             ##   ##   #      ## ##      #
             ########  #      #  ##     ##
            ##      #  #######   ########

             #        #######     #######
             #       ##     ##   #      ##
             #       #       ## ##
             #       #       ## ##   #####
             #       ##      #   #      ##
             #######   ######     ########
         **************************************************/
        /// <summary>
        /// Funtion to write data to an object not in current thread
        /// </summary>
        /// <param name="text"></param>
        private void Add_logs(String text, LogMsgType type, TabNum tabNum)
        {
            switch (tabNum)
            {
                case TabNum.Tab1:
                    currentBox = Tab1DataReceive;
                    break;
                case TabNum.Tab2:
                    currentBox = Tab2ReceiveData;
                    break;
                case TabNum.Tab3:
                    currentBox = Tab3_richText;
                    break;
                default:
                    break;
            }

            if (currentBox.InvokeRequired)
            {
                currentBox.BeginInvoke(
                    new MethodInvoker(
                        delegate() { Add_logs(text, type, tabNum); }));
            }
            else
            {
                currentBox.Focus();
                // Set up message
                switch (type)
                {
                    case LogMsgType.Error:
                        currentBox.SelectionColor = Color.Red;
                        break;
                    case LogMsgType.Incoming:
                        currentBox.SelectionColor = Color.Blue;
                        break;
                    case LogMsgType.Normal:
                        currentBox.SelectionColor = Color.Black;
                        break;
                    case LogMsgType.Outgoing:
                        currentBox.SelectionColor = Color.Green;
                        break;
                    case LogMsgType.Warning:
                        currentBox.SelectionColor = Color.Gold;
                        break;
                    case LogMsgType.Coment:
                        currentBox.SelectionColor = Color.DarkOrange;
                        break;
                    default:
                        currentBox.SelectionColor = Color.Black;
                        break;
                }
                currentBox.AppendText(text);

                if (tabNum == TabNum.Tab1)
                {
                    Tab_WriteLog(text);
                }
            }
        }