Esempio n. 1
0
        /// <summary>
        /// Generates discover report.
        /// </summary>
        /// <param name="systemTitle">System title</param>
        /// <param name="newMeter">Is this a new meter.</param>
        /// <returns>Generated bytes.</returns>
        public byte[] DiscoverReport(byte[] systemTitle, bool newMeter)
        {
            GXByteBuffer bb = new GXByteBuffer();

            if (settings.InterfaceType != Enums.InterfaceType.Plc &&
                settings.InterfaceType != Enums.InterfaceType.PlcHdlc)
            {
                throw new ArgumentOutOfRangeException("Invalid interface type.");
            }
            byte alarmDescription;

            if (settings.InterfaceType == Enums.InterfaceType.Plc)
            {
                alarmDescription = (byte)(newMeter ? 1 : 0x82);
            }
            else
            {
                alarmDescription = 0;
            }
            if (settings.InterfaceType == Enums.InterfaceType.PlcHdlc)
            {
                bb.Set(GXCommon.LLCReplyBytes);
            }
            bb.SetUInt8((byte)Command.DiscoverReport);
            bb.SetUInt8(1);
            bb.Set(systemTitle);
            if (alarmDescription != 0)
            {
                bb.SetUInt8(1);
            }
            bb.SetUInt8(alarmDescription);
            int    clientAddress    = settings.ClientAddress;
            int    serverAddress    = settings.ServerAddress;
            UInt16 macSourceAddress = settings.Plc.MacSourceAddress;
            UInt16 macTargetAddress = settings.Plc.MacDestinationAddress;

            try
            {
                //10.4.6.4 Source and destination APs and addresses of CI-PDUs
                //Client address is No-station in discoverReport.
                if (settings.InterfaceType == Enums.InterfaceType.PlcHdlc)
                {
                    settings.Plc.MacDestinationAddress = (UInt16)PlcHdlcSourceAddress.Initiator;
                }
                else
                {
                    settings.ClientAddress = 0;
                    settings.ServerAddress = 0xFD;
                }
                return(GXDLMS.GetMacFrame(settings, 0x13, 0, bb));
            }
            finally
            {
                settings.ClientAddress             = clientAddress;
                settings.ServerAddress             = serverAddress;
                settings.Plc.MacSourceAddress      = macSourceAddress;
                settings.Plc.MacDestinationAddress = macTargetAddress;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Discover available PLC meters.
        /// </summary>
        /// <returns>Generated bytes.</returns>
        public byte[] DiscoverRequest()
        {
            GXByteBuffer bb = new GXByteBuffer();

            if (settings.InterfaceType != Enums.InterfaceType.Plc &&
                settings.InterfaceType != Enums.InterfaceType.PlcHdlc)
            {
                throw new ArgumentOutOfRangeException("Invalid interface type.");
            }
            if (settings.InterfaceType == Enums.InterfaceType.PlcHdlc)
            {
                bb.Set(GXCommon.LLCSendBytes);
            }
            bb.SetUInt8((byte)Command.DiscoverRequest);
            bb.SetUInt8(ResponseProbability);
            bb.SetUInt16(AllowedTimeSlots);
            //DiscoverReport initial credit
            bb.SetUInt8(0);
            // IC Equal credit
            bb.SetUInt8(0);
            int    val           = 0;
            int    clientAddress = settings.ClientAddress;
            int    serverAddress = settings.ServerAddress;
            UInt16 da            = settings.Plc.MacDestinationAddress;
            UInt16 sa            = settings.Plc.MacSourceAddress;

            try
            {
                //10.4.6.4 Source and destination APs and addresses of CI-PDUs
                //Client address is No-station in discoverReport.
                if (settings.InterfaceType == Enums.InterfaceType.PlcHdlc)
                {
                    settings.Plc.InitialCredit         = 0;
                    settings.Plc.CurrentCredit         = 0;
                    settings.Plc.MacSourceAddress      = 0xC01;
                    settings.Plc.MacDestinationAddress = 0xFFF;
                    settings.ClientAddress             = 0x66;
                    // All-station
                    settings.ServerAddress = 0x33FF;
                }
                else
                {
                    val  = settings.Plc.InitialCredit << 5;
                    val |= settings.Plc.CurrentCredit << 2;
                    val |= settings.Plc.DeltaCredit & 0x3;
                    settings.Plc.MacSourceAddress = 0xC00;
                    settings.ClientAddress        = 1;
                    settings.ServerAddress        = 0;
                }
                return(GXDLMS.GetMacFrame(settings, 0x13, (byte)val, bb));
            }
            finally
            {
                settings.ClientAddress             = clientAddress;
                settings.ServerAddress             = serverAddress;
                settings.Plc.MacDestinationAddress = da;
                settings.Plc.MacSourceAddress      = sa;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Ping PLC meter.
        /// </summary>
        /// <returns>Generated bytes.</returns>
        public byte[] PingRequest(byte[] systemTitle)
        {
            GXByteBuffer bb = new GXByteBuffer();

            //Control byte.
            bb.SetUInt8((byte)Command.PingRequest);
            bb.Set(systemTitle);
            return(GXDLMS.GetMacFrame(settings, 0x13, 0, bb));
        }
Esempio n. 4
0
        /// <summary>
        /// Register PLC meters.
        /// </summary>
        /// <param name="initiatorSystemTitle">Active initiator systemtitle</param>
        /// <param name="systemTitle"></param>
        /// <returns>Generated bytes.</returns>
        public byte[] RegisterRequest(byte[] initiatorSystemTitle, byte[] systemTitle)
        {
            GXByteBuffer bb = new GXByteBuffer();

            //Control byte.
            bb.SetUInt8((byte)Command.RegisterRequest);
            bb.Set(initiatorSystemTitle);
            //LEN
            bb.SetUInt8(0x1);
            bb.Set(systemTitle);
            //MAC address.
            bb.SetUInt16(MacSourceAddress);
            int val = settings.Plc.InitialCredit << 5;

            val |= settings.Plc.CurrentCredit << 2;
            val |= settings.Plc.DeltaCredit & 0x3;

            int    clientAddress    = settings.ClientAddress;
            int    serverAddress    = settings.ServerAddress;
            UInt16 macSourceAddress = settings.Plc.MacSourceAddress;
            UInt16 macTargetAddress = settings.Plc.MacDestinationAddress;

            try
            {
                //10.4.6.4 Source and destination APs and addresses of CI-PDUs
                //Client address is No-station in discoverReport.
                if (settings.InterfaceType == Enums.InterfaceType.PlcHdlc)
                {
                    settings.Plc.InitialCredit         = 0;
                    settings.Plc.CurrentCredit         = 0;
                    settings.Plc.MacSourceAddress      = 0xC01;
                    settings.Plc.MacDestinationAddress = 0xFFF;
                    settings.ClientAddress             = 0x66;
                    // All-station
                    settings.ServerAddress = 0x33FF;
                }
                else
                {
                    settings.ClientAddress             = 1;
                    settings.ServerAddress             = 0;
                    settings.Plc.MacSourceAddress      = 0xC00;
                    settings.Plc.MacDestinationAddress = 0xFFF;
                }
                return(GXDLMS.GetMacFrame(settings, 0x13, (byte)val, bb));
            }
            finally
            {
                settings.ClientAddress             = clientAddress;
                settings.ServerAddress             = serverAddress;
                settings.Plc.MacSourceAddress      = macSourceAddress;
                settings.Plc.MacDestinationAddress = macTargetAddress;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Repear call request.
        /// </summary>
        /// <returns>Generated bytes.</returns>
        public byte[] RepeaterCallRequest()
        {
            GXByteBuffer bb = new GXByteBuffer();

            //Control byte.
            bb.SetUInt8((byte)Command.RepeatCallRequest);
            //MaxAdrMac.
            bb.SetUInt16(0x63);
            //Nb_Tslot_For_New
            bb.SetUInt8(0);
            //Reception-Threshold default value
            bb.SetUInt8(0);
            return(GXDLMS.GetMacFrame(settings, 0x13, 0xFC, bb));
        }