Gurux.DLMS.GXDLMSTranslator.MessageToXml C# (CSharp) Méthode

MessageToXml() public méthode

Convert message to xml.
public MessageToXml ( GXByteBuffer value ) : string
value GXByteBuffer Bytes to convert.
Résultat string
        public string MessageToXml(GXByteBuffer value)
        {
            if (value == null || value.Size == 0)
            {
                throw new ArgumentNullException("value");
            }
            try
            {
                GXReplyData data = new GXReplyData();
                GXDLMSTranslatorStructure xml = new GXDLMSTranslatorStructure(OutputType, Hex, ShowStringAsHex, tags);
                data.Xml = xml;
                //If HDLC framing.
                int offset = value.Position;
                if (value.GetUInt8(value.Position) == 0x7e)
                {
                    GXDLMSSettings settings = new GXDLMSSettings(true);
                    settings.InterfaceType = Enums.InterfaceType.HDLC;
                    if (GXDLMS.GetData(settings, value, data))
                    {
                        if (!PduOnly)
                        {
                            xml.AppendLine("<HDLC len=\"" + (data.PacketLength - offset).ToString("X") + "\" >");
                            xml.AppendLine("<TargetAddress Value=\"" + settings.ServerAddress.ToString("X") + "\" />");
                            xml.AppendLine("<SourceAddress Value=\"" + settings.ClientAddress.ToString("X") + "\" />");
                        }
                        if (data.Data.Size == 0)
                        {
                            if ((data.FrameId & 1) != 0 && data.Command == Command.None)
                            {
                                if (!CompletePdu)
                                {
                                    xml.AppendLine("<Command Value=\"NextFrame\" />");
                                }
                                multipleFrames = true;
                            }
                            else
                            {
                                xml.AppendStartTag(data.Command);
                                xml.AppendEndTag(data.Command);
                            }
                        }
                        else
                        {
                            if (multipleFrames || (data.MoreData & Enums.RequestTypes.Frame) != 0)
                            {
                                if (CompletePdu)
                                {
                                    pduFrames.Set(data.Data.Data);
                                }
                                else
                                {
                                    xml.AppendLine("<NextFrame Value=\"" + GXCommon.ToHex(data.Data.Data, false, data.Data.Position, data.Data.Size - data.Data.Position) + "\" />");
                                }
                                multipleFrames = false;
                            }
                            if (!data.IsMoreData)
                            {
                                if (!PduOnly)
                                {
                                    xml.AppendLine("<PDU>");
                                }
                                if (pduFrames.Size != 0)
                                {
                                    if (!CompletePdu)
                                    {
                                        pduFrames.Set(data.Data.Data);
                                    }
                                    xml.AppendLine(PduToXml(pduFrames));
                                    pduFrames.Clear();
                                }
                                else
                                {
                                    xml.AppendLine(PduToXml(data.Data));
                                }
                                //Remove \r\n.
                                xml.sb.Length -= 2;
                                if (!PduOnly)
                                {
                                    xml.AppendLine("</PDU>");
                                }
                            }
                        }
                        if (!PduOnly)
                        {
                            xml.AppendLine("</HDLC>");
                        }
                    }
                    return xml.sb.ToString();
                }
                //If wrapper.
                if (value.GetUInt16(value.Position) == 1)
                {
                    GXDLMSSettings settings = new GXDLMSSettings(true);
                    settings.InterfaceType = Enums.InterfaceType.WRAPPER;
                    GXDLMS.GetData(settings, value, data);
                    if (!PduOnly)
                    {
                        xml.AppendLine("<WRAPPER len=\"" + (data.PacketLength - offset).ToString("X") + "\" >");
                        xml.AppendLine("<TargetAddress Value=\"" + settings.ClientAddress.ToString("X") + "\" />");
                        xml.AppendLine("<SourceAddress Value=\"" + settings.ServerAddress.ToString("X") + "\" />");
                    }
                    if (data.Data.Size == 0)
                    {
                        xml.AppendLine("<Command Value=\"" + data.Command.ToString().ToUpper() + "\" />");
                    }
                    else
                    {
                        if (data.Data.Size == 0)
                        {
                            if ((data.FrameId & 1) != 0 && data.Command == Command.None)
                            {
                                if (!CompletePdu)
                                {
                                    xml.AppendLine("<Command Value=\"NextFrame\" />");
                                }
                                multipleFrames = true;
                            }
                            else
                            {
                                xml.AppendStartTag(data.Command);
                                xml.AppendEndTag(data.Command);
                            }
                        }
                        else
                        {
                            if (multipleFrames || (data.MoreData & Enums.RequestTypes.Frame) != 0)
                            {
                                if (CompletePdu)
                                {
                                    pduFrames.Set(data.Data.Data);
                                }
                                else
                                {
                                    xml.AppendLine("<NextFrame Value=\"" + GXCommon.ToHex(data.Data.Data, false, data.Data.Position, data.Data.Size - data.Data.Position) + "\" />");
                                }
                                multipleFrames = false;
                            }
                            if (!data.IsMoreData)
                            {
                                if (!PduOnly)
                                {
                                    xml.AppendLine("<PDU>");
                                }
                                if (pduFrames.Size != 0)
                                {
                                    if (!CompletePdu)
                                    {
                                        pduFrames.Set(data.Data.Data);
                                    }
                                    xml.AppendLine(PduToXml(pduFrames));
                                    pduFrames.Clear();
                                }
                                else
                                {
                                    xml.AppendLine(PduToXml(data.Data));
                                }
                                //Remove \r\n.
                                xml.sb.Length -= 2;
                                if (!PduOnly)
                                {
                                    xml.AppendLine("</PDU>");
                                }
                            }
                        }
                    }
                    if (!PduOnly)
                    {
                        xml.AppendLine("</WRAPPER>");
                    }
                    return xml.sb.ToString();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex.ToString());
            }
            throw new ArgumentNullException("Invalid DLMS framing.");
        }

Same methods

GXDLMSTranslator::MessageToXml ( byte value ) : string