/// <summary> /// Constructor /// </summary> /// <param name="data">Integer. </param> public GXAsn1Integer(UInt64 data) { GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt64(data); Value = bb.Array(); }
/// <summary> /// Constructor /// </summary> /// <param name="data">Integer. </param> public GXAsn1Integer(string data) { if (data == null) { throw new System.ArgumentException("data"); } GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt64(UInt64.Parse(data)); Value = bb.Array(); }
///<summary> /// Constructor. ///</summary> ///<param name="sn">Short name settings. </param> ///<param name="type"> /// Interface type. ///</param> ///<param name="flagID"> /// Three letters FLAG ID. ///</param> ///<param name="serialNumber"> /// Meter serial number. Size of serial number is 5 bytes. ///</param> public GXDLMSSecureServer(GXDLMSAssociationShortName sn, InterfaceType type, string flagID, UInt64 serialNumber) : base(sn, type) { if (flagID == null || flagID.Length != 3) { throw new ArgumentOutOfRangeException("Invalid FLAG ID."); } if (flagID == null || flagID.Length != 3) { throw new ArgumentOutOfRangeException("Invalid FLAG ID."); } GXByteBuffer bb = new GXByteBuffer(); bb.Add(flagID); GXByteBuffer serial = new GXByteBuffer(); serial.SetUInt64(serialNumber); bb.Set(serial.Data, 3, 5); Ciphering = new GXCiphering(bb.Array()); Settings.Cipher = Ciphering; }
///<summary> /// Constructor. ///</summary> ///<param name="ln">Logical name settings. </param> ///<param name="hdlc"> /// Interface type. ///</param> ///<param name="flagID"> /// Three letters FLAG ID. ///</param> ///<param name="serialNumber"> /// Meter serial number. Size of serial number is 5 bytes. ///</param> public GXDLMSSecureServer(GXDLMSAssociationLogicalName ln, GXDLMSHdlcSetup hdlc, string flagID, UInt64 serialNumber) : base(ln, hdlc) { if (flagID == null || flagID.Length != 3) { throw new ArgumentOutOfRangeException("Invalid FLAG ID."); } if (flagID == null || flagID.Length != 3) { throw new ArgumentOutOfRangeException("Invalid FLAG ID."); } ln.XDLMSContextInfo.settings = Settings; GXByteBuffer bb = new GXByteBuffer(); bb.Add(flagID); GXByteBuffer serial = new GXByteBuffer(); serial.SetUInt64(serialNumber); bb.Set(serial.Data, 3, 5); Ciphering = new GXCiphering(bb.Array()); Settings.Cipher = Ciphering; }
///<summary> ///Convert object to DLMS bytes. ///</summary> ///<param name="settings">DLMS settings.</param> ///<param name="buff">Byte buffer where data is write.</param> ///<param name="dataType">Data type.</param> ///<param name="value">Added Value.</param> public static void SetData(GXDLMSSettings settings, GXByteBuffer buff, DataType type, object value) { if ((type == DataType.Array || type == DataType.Structure) && value is byte[]) { // If byte array is added do not add type. buff.Set((byte[])value); return; } buff.SetUInt8((byte)type); switch (type) { case DataType.None: break; case DataType.Boolean: if (Convert.ToBoolean(value)) { buff.SetUInt8(1); } else { buff.SetUInt8(0); } break; case DataType.Int8: buff.SetUInt8((byte)Convert.ToSByte(value)); break; case DataType.UInt8: case DataType.Enum: buff.SetUInt8(Convert.ToByte(value)); break; case DataType.Int16: if (value is UInt16) { buff.SetUInt16((UInt16)value); } else { buff.SetUInt16((UInt16)(Convert.ToInt16(value) & 0xFFFF)); } break; case DataType.UInt16: buff.SetUInt16(Convert.ToUInt16(value)); break; case DataType.Int32: buff.SetUInt32((UInt32)Convert.ToInt32(value)); break; case DataType.UInt32: buff.SetUInt32(Convert.ToUInt32(value)); break; case DataType.Int64: buff.SetUInt64((UInt64)Convert.ToInt64(value)); break; case DataType.UInt64: buff.SetUInt64(Convert.ToUInt64(value)); break; case DataType.Float32: buff.SetFloat((float)value); break; case DataType.Float64: buff.SetDouble((double)value); break; case DataType.BitString: SetBitString(buff, value); break; case DataType.String: SetString(buff, value); break; case DataType.StringUTF8: SetUtcString(buff, value); break; case DataType.OctetString: if (value is GXDate) { //Add size buff.SetUInt8(5); SetDate(buff, value); } else if (value is GXTime) { //Add size buff.SetUInt8(4); SetTime(buff, value); } else if (value is GXDateTime || value is DateTime) { //Add size buff.SetUInt8(12); SetDateTime(settings, buff, value); } else { SetOctetString(buff, value); } break; case DataType.Array: case DataType.Structure: SetArray(settings, buff, value); break; case DataType.Bcd: SetBcd(buff, value); break; case DataType.CompactArray: throw new Exception("Invalid data type."); case DataType.DateTime: SetDateTime(settings, buff, value); break; case DataType.Date: SetDate(buff, value); break; case DataType.Time: SetTime(buff, value); break; default: throw new Exception("Invalid data type."); } }