public static VarPacket CreateReadResponse(object owner, IPEndPoint endPoint, List <decimal> varValues) { if (endPoint == null) { throw new ArgumentNullException(); } var p = new VarPacket() { EndPoint = endPoint, Owner = owner }; int index = 0; if (varValues == null) { p.Data = new byte[9]; p.Data.WriteAt(BitConverter.GetBytes(9), ref index); p.Data[4] = 1; ++index; p.Data.WriteAt(BitConverter.GetBytes(0), ref index); } else { int len = 9 + (varValues.Count << 4); p.Data = new byte[len]; p.Data.WriteAt(BitConverter.GetBytes(len), ref index); p.Data[4] = 1; ++index; p.Data.WriteAt(BitConverter.GetBytes(varValues.Count), ref index); for (int i = 0; i < varValues.Count; ++i) { p.Data.WriteAt(DecimalConverter.GetBytes(varValues[i]), ref index); } } return(p); }
public static VarPacket CreateWriteRequest(object owner, IPEndPoint endPoint, List <string> varNames, decimal value) { if (endPoint == null || varNames == null) { throw new ArgumentNullException(); } var p = new VarPacket() { EndPoint = endPoint, Owner = owner }; int len = 25 + (varNames.Count << 2); for (int i = 0; i < varNames.Count; ++i) { len += (sizeof(char) * varNames[i].Length); } int index = 0; p.Data = new byte[len]; p.Data.WriteAt(BitConverter.GetBytes(len), ref index); p.Data[4] = 2; ++index; p.Data.WriteAt(BitConverter.GetBytes(varNames.Count), ref index); for (int i = 0; i < varNames.Count; ++i) { p.Data.WriteAt(BitConverter.GetBytes(varNames[i].Length * sizeof(char)), ref index); p.Data.WriteAt(varNames[i].ToCharArray(), ref index); } p.Data.WriteAt(DecimalConverter.GetBytes(value), ref index); return(p); }