Exemplo n.º 1
0
 private void txtQuickSend_TextChanged(object sender, EventArgs e)
 {
     HelpFunction.ValidateResult result = HelpFunction.CheckInput(txtQuickSend.Text, mData.Format);
     if (result.IsValid)
     {
         lbInfo.IsShowText = false;
         lbInfo.Value      = new int[] { GetInstanceData().Length };
         lbInfo.ForeColor  = Color.Black;
     }
     else
     {
         lbInfo.IsShowText = true;
         lbInfo.Text       = "Wrong Data";
         lbInfo.ForeColor  = Color.Red;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Convert string like " Hex,"Hello world" " to CommonData.
        /// data.Name = "Send Data", data.Format = Hex, data.Content = Hello world
        /// </summary>
        /// <param name="str">string always read from files</param>
        /// <returns></returns>
        public static CommonData ConvertStringToCommonData(string str)
        {
            CommonData sendData = new CommonData();

            if (str == null || str.Length == 0)
            {
                return(sendData);
            }
            sendData.Name = "Send Data";
            string[] typeString = HelpFunction.SplitString(str, new char[] { ',' });
            sendData.Format = (emViewFormat)Enum.Parse(typeof(emViewFormat), typeString[0], false);
            int    firstLetter = str.IndexOf('"') + 1;
            string hexStr      = str.Substring(firstLetter, str.Length - firstLetter - 1);

            sendData.Content = CommonData.GetBytesFromHexString(hexStr);
            return(sendData);
        }
Exemplo n.º 3
0
        public static ValidateResult CheckInput(string str, emViewFormat type)
        {
            ValidateResult result = new ValidateResult(true, 0, 0);

            if (type == emViewFormat.Text)
            {
                return(result);
            }

            if (type == emViewFormat.File)
            {
                return(result);
            }

            if (type == emViewFormat.ComStatus)
            {
                return(result);
            }

            if (type == emViewFormat.WaitPeriod || type == emViewFormat.WaitTime)
            {
                return(result);
            }



            char[]   dilimer = new char[] { ' ', ',', '\r', '\n', '\t' };
            string[] strs    = HelpFunction.SplitString(str, dilimer);
            for (int i = 0; i < strs.Length; i++)
            {
                System.Diagnostics.Debug.WriteLine(strs[i]);
                bool bValid = ValidString(strs[i], type);
                if (!bValid)
                {
                    result.IsValid       = bValid;
                    result.StartPosition = str.IndexOf(strs[i]);
                    result.Length        = strs[i].Length;
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// convert time string to DateTime. timestring format like "11:11:11.000"
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime ConvertStringToDateTime(string str)
        {
            //11:11:11.11
            str = str.Length < 11 ?  str.PadRight(11, '0') : str;
            DateTime time = DateTime.Today;

            string[] splitStr = HelpFunction.SplitString(str, new char[] { '.' });  //"11:11:11" & "000"

            int milliSecond = (splitStr[1].Length > 0) ? Convert.ToInt16(splitStr[1]) : Convert.ToInt16(0);

            time = time.AddMilliseconds(milliSecond);        //add milliseconds
            string timeStr = splitStr[0].Replace(' ', '0');  //" 1:1 :11" -> "01:10:11"

            splitStr = HelpFunction.SplitString(timeStr, new char[] { ':' });
            time     = time.AddHours(Convert.ToInt32(splitStr[0]));   //add hours
            time     = time.AddMinutes(Convert.ToInt32(splitStr[1])); //add minutes
            time     = time.AddSeconds(Convert.ToInt32(splitStr[2])); //add seconds
            //time = Convert.ToDateTime(timeStr);

            return(time);
        }