private void SetParameters(Parity parity = Parity.None, BitesPerCharacter bitesPerCharacter = BitesPerCharacter.Eight, StopBits stopBits = StopBits.One, Handshake handshake = Handshake.RequestToSend, bool dtrEnable = true, bool rtsEnable = true) { serialPort.Parity = parity; serialPort.DataBits = 8; serialPort.StopBits = stopBits; serialPort.Handshake = handshake; serialPort.DtrEnable = dtrEnable; serialPort.RtsEnable = rtsEnable; serialPort.Encoding = Helpers.GetEncoding(bitesPerCharacter); serialPort.NewLine = Environment.NewLine; }
public static Encoding GetEncoding(BitesPerCharacter bitesPerCharacter) { switch (bitesPerCharacter) { case BitesPerCharacter.Eight: return Encoding.ASCII; case BitesPerCharacter.Sixteen: return Encoding.Unicode; default: break; } throw new NotSupportedException("bitesPerCharacter"); }
public static string GetStringSmsContent(this byte[] _this, BitesPerCharacter bitesPerCharacter) => Helpers.GetEncoding(bitesPerCharacter).GetString(_this);
public static string GetStringSmsContent(this IEnumerable <byte> _this, BitesPerCharacter bitesPerCharacter) => _this.ToArray().GetStringSmsContent(bitesPerCharacter);
public static byte[] GetSmsContent(this string _this, BitesPerCharacter bitesPerCharacter) => Helpers.GetEncoding(bitesPerCharacter).GetBytes(_this);
public Message(byte[] content, BitesPerCharacter bitesPerCharacter) { DataBits = bitesPerCharacter; Content = content; NumberOfSubmessages = Length / Values.BytesPerSubmessage + (Length % Values.BytesPerSubmessage > 0 ? 1 : 0); }
public Message(string content, BitesPerCharacter bitesPerCharacter) : this(content.GetSmsContent(bitesPerCharacter), bitesPerCharacter) { }