byte[] getBytes(string str) { Byte[] data; if (str.Length > 0) { switch (currentCode) { case CODE_BIT: { foreach (char c in str) { if (c != '1' && c != '0' && c != ' ' && c != '\r' && c != '\n') { return(null); } } if (currentBitOrder == BIT_LSB_FIRST) { data = Assist.BitsLsbToBytes(str); } else { data = Assist.BitsMsbToBytes(str); } } break; case CODE_HEX: { foreach (char c in str) { if ((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F') && c != ' ' && c != '\r' && c != '\n') { return(null); } } data = Assist.HexToBytes(str); } break; case CODE_ASCII: default: data = System.Text.Encoding.ASCII.GetBytes(textBoxInput.Text.Trim()); break; } return(data); } return(null); }