Exemple #1
0
        /// <summary>
        /// Test if the str is valid to convert to certain type
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool ValidString(string str, emViewFormat type)
        {
            try
            {
                byte n        = 0;
                int  formBase = 10;
                switch (type)
                {
                case emViewFormat.Dec:
                    formBase = 10;
                    break;

                case emViewFormat.Hex:
                    formBase = 16;
                    break;

                default:
                    throw new NotImplementedException();
                }
                n = System.Convert.ToByte(str, formBase);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        public static string GetViewString(byte[] data, emViewFormat format)
        {
            CommonData cd = new CommonData();

            cd.Content = data;
            cd.Format  = format;
            return(cd.GetViewString());
        }
Exemple #3
0
 private void SetFormat(emViewFormat format)
 {
     if (format == emViewFormat.Hex)
     {
         cmbShowFormat.SelectedIndex = 0;
     }
     else
     {
         cmbShowFormat.SelectedIndex = 1;
     }
 }
Exemple #4
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);
        }
Exemple #5
0
        private byte[] GetInstanceData()
        {
            emViewFormat format = mData.Format;
            string       str    = txtQuickSend.Text;

            byte[] data = new byte[0];

            switch (format)
            {
            case emViewFormat.Dec:
                data = CommonData.GetBytesFromDecString(str);
                break;

            case emViewFormat.Hex:
                data = CommonData.GetBytesFromHexString(str);
                break;

            default:
                break;
            }
            return(data);
        }
Exemple #6
0
        public static byte[] GetBytes(string str, emViewFormat format, string cr)
        {
            byte[] data = null;
            switch (format)
            {
            case emViewFormat.Text:
                data = CommonData.GetBytesFromTextString(str, cr);
                break;

            case emViewFormat.Dec:
                data = CommonData.GetBytesFromDecString(str);
                break;

            case emViewFormat.Hex:
                data = CommonData.GetBytesFromHexString(str);
                break;

            default:
                break;
            }
            return(data);
        }
Exemple #7
0
        public static byte[] GetBytes(string str, emViewFormat format)
        {
            byte[]   data   = null;
            Encoding coding = Encoding.GetEncoding("iso-8859-1");

            switch (format)
            {
            case emViewFormat.Text:
                data = coding.GetBytes(str);
                break;

            case emViewFormat.Dec:
                data = CommonData.GetBytesFromDecString(str);
                break;

            case emViewFormat.Hex:
                data = CommonData.GetBytesFromHexString(str);
                break;

            default:
                break;
            }
            return(data);
        }
        private void SetFormat(emViewFormat format)
        {
            if (format == emViewFormat.Hex)
            {
                cmbShowFormat.SelectedIndex = 0;
            }
            else
            {
                cmbShowFormat.SelectedIndex = 1;
            }

        }
Exemple #9
0
 public static string GetViewString(byte[] data, emViewFormat format)
 {
     CommonData cd = new CommonData();
     cd.Content = data;
     cd.Format = format;
     return cd.GetViewString();
 }
Exemple #10
0
 public static byte[] GetBytes(string str, emViewFormat format, string cr)
 {
     byte[] data = null;
     switch (format)
     {
         case emViewFormat.Text:
             data = CommonData.GetBytesFromTextString(str, cr);
             break;
         case emViewFormat.Dec:
             data = CommonData.GetBytesFromDecString(str);
             break;
         case emViewFormat.Hex:
             data = CommonData.GetBytesFromHexString(str);
             break;
         default:
             break;
     }
     return data;
 }
Exemple #11
0
 public static byte[] GetBytes(string str, emViewFormat format)
 {
     byte[] data = null;
     Encoding coding = Encoding.GetEncoding("iso-8859-1");
     switch (format)
     {
         case emViewFormat.Text:
             data  = coding.GetBytes(str);
             break;
         case emViewFormat.Dec:
             data = CommonData.GetBytesFromDecString(str);
             break;
         case emViewFormat.Hex:
             data = CommonData.GetBytesFromHexString(str);
             break;
         default:
             break;
     }
     return data;
 }
Exemple #12
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;
        }
Exemple #13
0
 /// <summary>
 /// Test if the str is valid to convert to certain type
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static bool ValidString(string str, emViewFormat type)
 {
     try
     {
         byte n = 0;
         int formBase = 10;
         switch (type)
         {
             case emViewFormat.Dec:
                 formBase = 10;
                 break;
             case emViewFormat.Hex:
                 formBase = 16;
                 break;
             default:
                 throw new NotImplementedException();
         }
         n = System.Convert.ToByte(str, formBase);
     }
     catch (Exception ex)
     {
         return false;
     }
     return true;
 }