Dicom.Network.AAssociateRQ.Write C# (CSharp) Method

Write() public method

Writes A-ASSOCIATE-RQ to PDU buffer
public Write ( ) : RawPDU
return RawPDU
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU((byte)0x01);

            pdu.Write("Version", (ushort)0x0001);
            pdu.Write("Reserved", 0x00, 2);
            pdu.Write("Called AE", _assoc.CalledAE, 16, ' ');
            pdu.Write("Calling AE", _assoc.CallingAE, 16, ' ');
            pdu.Write("Reserved", 0x00, 32);

            // Application Context
            pdu.Write("Item-Type", (byte)0x10);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Application Context Name", DicomUID.DICOMApplicationContextName.UID);
            pdu.WriteLength16();

            foreach (DcmPresContext pc in _assoc.GetPresentationContexts()) {
                // Presentation Context
                pdu.Write("Item-Type", (byte)0x20);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Presentation Context ID", (byte)pc.ID);
                pdu.Write("Reserved", (byte)0x00, 3);

                // Abstract Syntax
                pdu.Write("Item-Type", (byte)0x30);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Abstract Syntax UID", pc.AbstractSyntax.UID);
                pdu.WriteLength16();

                // Transfer Syntax
                foreach (DicomTransferSyntax ts in pc.GetTransfers()) {
                    pdu.Write("Item-Type", (byte)0x40);
                    pdu.Write("Reserved", (byte)0x00);
                    pdu.MarkLength16("Item-Length");
                    pdu.Write("Transfer Syntax UID", ts.UID.UID);
                    pdu.WriteLength16();
                }

                pdu.WriteLength16();
            }

            // User Data Fields
            pdu.Write("Item-Type", (byte)0x50);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");

            // Maximum PDU
            pdu.Write("Item-Type", (byte)0x51);
            pdu.Write("Reserved", (byte)0x00);
            pdu.Write("Item-Length", (ushort)0x0004);
            pdu.Write("Max PDU Length", (uint)_assoc.MaximumPduLength);

            // Implementation Class UID
            pdu.Write("Item-Type", (byte)0x52);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Class UID", Implementation.ClassUID.UID);
            pdu.WriteLength16();

            // Asynchronous Operations Negotiation
            if (_assoc.NegotiateAsyncOps) {
                pdu.Write("Item-Type", (byte)0x53);
                pdu.Write("Reserved", (byte)0x00);
                pdu.Write("Item-Length", (ushort)0x0004);
                pdu.Write("Asynchronous Operations Invoked", (ushort)_assoc.AsyncOpsInvoked);
                pdu.Write("Asynchronous Operations Performed", (ushort)_assoc.AsyncOpsPerformed);
            }

            // Implementation Version
            pdu.Write("Item-Type", (byte)0x55);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Version", Implementation.Version);
            pdu.WriteLength16();

            pdu.WriteLength16();

            return pdu;
        }

Usage Example

Beispiel #1
0
        public void Write_AeWithNonAsciiCharacters_ShouldBeAsciified()
        {
            var notExpected = "GĂ–TEBORG";
            var request = new AAssociateRQ(new DicomAssociation("MALMĂ–", notExpected));

            var writePdu = request.Write();

            RawPDU readPdu;
            using (var stream = new MemoryStream())
            {
                writePdu.WritePDU(stream);

                var length = (int)writePdu.Length;
                var buffer = new byte[length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(buffer, 0, length);
                readPdu = new RawPDU(buffer);
            }

            readPdu.Reset();
            readPdu.SkipBytes("Unknown", 10);
            var actual = readPdu.ReadString("Called AE", 16);

            Assert.NotEqual(notExpected, actual);
        }
All Usage Examples Of Dicom.Network.AAssociateRQ::Write