LEADTOOLS Medical (Leadtools.Dicom assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
Associate(String,Int32,String,String,DicomPrintScuPrintManagementClassFlags) Method
See Also 
Leadtools.Dicom Namespace > DicomPrintScu Class > Associate Method : Associate(String,Int32,String,String,DicomPrintScuPrintManagementClassFlags) Method



printScpIP
The IP address or DNS name of the Print SCP.
printScpPort
Port number of the Print SCP.
calledTitle
The Called AE Title (AE Title of the Print SCP).
callingTitle
The Calling AE Title (AE Title of the Print SCU).
supportedClasses
The SOP/Meta SOP Classes supported by the Print SCU. If none of the Meta SOP Classes is specified, the Basic Grayscale Print Management Meta SOP Class will be specified automatically.
printScpIP
The IP address or DNS name of the Print SCP.
printScpPort
Port number of the Print SCP.
calledTitle
The Called AE Title (AE Title of the Print SCP).
callingTitle
The Calling AE Title (AE Title of the Print SCU).
supportedClasses
The SOP/Meta SOP Classes supported by the Print SCU. If none of the Meta SOP Classes is specified, the Basic Grayscale Print Management Meta SOP Class will be specified automatically.
Connects to the Print SCP and then establishes the DICOM Association.

Syntax

Visual Basic (Declaration) 
Overloads Public Function Associate( _
   ByVal printScpIP As String, _
   ByVal printScpPort As Integer, _
   ByVal calledTitle As String, _
   ByVal callingTitle As String, _
   ByVal supportedClasses As DicomPrintScuPrintManagementClassFlags _
) As Boolean
Visual Basic (Usage)Copy Code
Dim instance As DicomPrintScu
Dim printScpIP As String
Dim printScpPort As Integer
Dim calledTitle As String
Dim callingTitle As String
Dim supportedClasses As DicomPrintScuPrintManagementClassFlags
Dim value As Boolean
 
value = instance.Associate(printScpIP, printScpPort, calledTitle, callingTitle, supportedClasses)

Parameters

printScpIP
The IP address or DNS name of the Print SCP.
printScpPort
Port number of the Print SCP.
calledTitle
The Called AE Title (AE Title of the Print SCP).
callingTitle
The Calling AE Title (AE Title of the Print SCU).
supportedClasses
The SOP/Meta SOP Classes supported by the Print SCU. If none of the Meta SOP Classes is specified, the Basic Grayscale Print Management Meta SOP Class will be specified automatically.

Return Value

true if the Association was established successfully; false if the Association request was rejected by the Print SCP.

Example

Visual BasicCopy Code
Public Class MyDicomPrintSCU : Inherits DicomPrintSCU
    Public Sub New(ByVal path As String)
       MyBase.New(path)
    End Sub
Public Overrides Sub OnStatus(ByVal status As DicomPrintScuStatus, ByVal operationStatus As DicomCommandStatusType)
Dim statusCodeType As String = "Unknown"
Dim msg As StringBuilder = New StringBuilder()
Select Case status
   Case DicomPrintScuStatus.ReceiveAbort
   Dim printSCUAbortInfo As DicomPrintScuAbortInformation = GetAbortInformation()
   msg.AppendFormat("Source = {0}, Reason = {1}", printSCUAbortInfo.Source, printSCUAbortInfo.Reason)
   MessageBox.Show(msg.ToString(), "Print SCP Aborted the Association", MessageBoxButtons.OK)

   Case DicomPrintScuStatus.ReceivePrintFilmSessionRsp
   Dim commandStatusType As DicomCommandStatusType = GetLastOperationStatus()
               If operationStatus = DicomCommandStatusType.Success Then
                  If commandStatusType = DicomCommandStatusType.Success Then
                     statusCodeType = "Success"
                  Else
                     statusCodeType = "Warning"
                  End If
               Else
                  statusCodeType = "Failure"
               End If
   msg.AppendFormat("Status: 0x{0:X4} {1}", commandStatusType, statusCodeType)
   MessageBox.Show(msg.ToString(), "Received N-ACTION-RSP (Basic Film Session SOP Class)", MessageBoxButtons.OK)
End Select
End Sub
  <Test> _
  Public Overrides Sub OnPrinterReport(ByVal eventTypeID As Integer, ByVal reportInfo As DicomPrinterReportInformation)
      Dim msg As StringBuilder = New StringBuilder()
      Dim eventTypeName As String = "Normal"
      Select Case eventTypeID
         Case 2
           eventTypeName = "Warning"

         Case 3
           eventTypeName = "Failure"
      End Select

      msg.AppendFormat("Event Type Name: {0}", eventTypeName)

      If eventTypeID <> 1 AndAlso Not reportInfo Is Nothing Then
   If Not reportInfo.PrinterStatusInfo Is Nothing Then
   msg.AppendFormat("{0}Printer Status Info: {1}", Environment.NewLine, reportInfo.PrinterStatusInfo)
   End If

   If Not reportInfo.FilmDestination Is Nothing Then
   msg.AppendFormat("{0}Film Destination: {1}", Environment.NewLine, reportInfo.FilmDestination)
   End If

   If Not reportInfo.PrinterName Is Nothing Then
   msg.AppendFormat("{0}Printer Name: {1}", Environment.NewLine, reportInfo.PrinterName)
   End If
End If
MessageBox.Show(msg.ToString(), "Printer Status Report", MessageBoxButtons.OK)
End Sub

Public Overrides Sub OnPrintJobReport(ByVal printJobInstanceUID As String, ByVal eventTypeID As Integer, ByVal reportInfo As DicomPrintJobReportInformation)
Dim msg As StringBuilder = New StringBuilder()
msg.AppendFormat("Print Job SOP Instance UID: {0}", printJobInstanceUID)

Dim eventTypeName As String = "Pending"
Select Case eventTypeID
   Case 2
   eventTypeName = "Printing"

   Case 3
   eventTypeName = "Done"

   Case 4
   eventTypeName = "Failure"
End Select
msg.AppendFormat("{0}Event Type Name: {1}", Environment.NewLine, eventTypeName)

If Not reportInfo Is Nothing Then
   If Not reportInfo.ExecutionStatusInfo Is Nothing Then
   msg.AppendFormat("{0}Execution Status Info: {1}", Environment.NewLine, reportInfo.ExecutionStatusInfo)
   End If

   If Not reportInfo.FilmSessionLabel Is Nothing Then
   msg.AppendFormat("{0}Film Session Label: {1}", Environment.NewLine, reportInfo.FilmSessionLabel)
   End If

   If Not reportInfo.PrinterName Is Nothing Then
   msg.AppendFormat("{0}Printer Name: {1}", Environment.NewLine, reportInfo.PrinterName)
   End If
End If
MessageBox.Show(msg.ToString(), "Print Job Status Report", MessageBoxButtons.OK)
End Sub
End Class

Private Sub PerformBasicPM()

'It's assumed that support for medical communication is already unlocked

'Make sure to initialize the DICOM engine, this needs to be done only once 
'In the whole application
DicomEngine.Startup()

'Make sure to initialize the DICOM Communication engine, this needs to be done only once 
'In the whole application
DicomNet.Startup()

'The DicomPrintSCU is disposable, this is why we are using the "using" keyword

Dim printSCU As MyDicomPrintSCU = New MyDicomPrintSCU(Nothing)
      Using (printSCU)
         printSCU.SetTimeout(60)

         Try
            ' Establish the Association
            Dim ret As Boolean = printSCU.Associate("10.1.1.209", 7104, "PrintSCP", "PrintSCU", DicomPrintScuPrintManagementClassFlags.BasicGrayscalePmMetaSopClass Or DicomPrintScuPrintManagementClassFlags.BasicColorPmMetaSopClass Or DicomPrintScuPrintManagementClassFlags.BasicAnnotationBoxSopClass Or DicomPrintScuPrintManagementClassFlags.BasicPrintImageOverlayBoxSopClass Or DicomPrintScuPrintManagementClassFlags.PresentationLutSopClass Or DicomPrintScuPrintManagementClassFlags.PrintJobSopClass Or DicomPrintScuPrintManagementClassFlags.PrinterConfigurationRetrievalSopClass)
            'The method will return false if the association was rejected,
            'if some other error occurred then an exception will be thrown
            If ret = False Then
               Dim associateRejectInfo As DicomPrintScuAssociateRejectInformation = printSCU.GetAssociateRejectInformation()
               If Not associateRejectInfo Is Nothing Then
                  Dim msg As StringBuilder = New StringBuilder()
                  msg.AppendFormat("Source = {0}, Reason = {1}", associateRejectInfo.Source, associateRejectInfo.Reason)
                  MessageBox.Show(msg.ToString())
                  Return
               End If
            End If

            ' Display some printer info
            GetPrinterInfo(printSCU)

            ' Display some printer configuration info
            GetPrinterConfigInfo(printSCU)

            ' Create a Film Session
            Dim filmSessionParameters As DicomFilmSessionParameters = printSCU.GetDefaultFilmSessionParameters()
            filmSessionParameters.NumberOfCopies = 1

            'Over here we can set some other film session parameters before creating the film session.
            'To set these parameters we can access one or more of these properties:
            'DicomFilmSessionParameters.NumberOfCopies
            'DicomFilmSessionParameters.MemoryAllocation
            'DicomFilmSessionParameters.OwnerID
            'DicomFilmSessionParameters.PrintPriority
            'DicomFilmSessionParameters.MediumType
            'DicomFilmSessionParameters.FilmDestination
            'DicomFilmSessionParameters.FilmSessionLabel

            printSCU.CreateFilmSession(filmSessionParameters, True)
            MessageBox.Show(printSCU.GetFilmSessionInstanceUid(), "Film Session SOP Instance UID", MessageBoxButtons.OK)

            ' Update the Film Session to specify a "MED" Print Priority
            filmSessionParameters = printSCU.GetDefaultFilmSessionParameters()
            filmSessionParameters.PrintPriority = "MED"
            printSCU.UpdateFilmSession(filmSessionParameters)


            Dim filmBoxParameters As DicomFilmBoxParameters = printSCU.GetDefaultFilmBoxParameters()

            If printSCU.IsClassSupported(DicomPrintScuPrintManagementClassFlags.BasicAnnotationBoxSopClass) Then
               filmBoxParameters.AnnotationDisplayFormatID = "SomeID"
            End If

            'Over here we can set some other film box parameters before creating the film box.
            'To set these parameters we can access one or more of these properties:
            'DicomFilmBoxParameters.ImageDisplayFormat
            'DicomFilmBoxParameters.FilmOrientation
            'DicomFilmBoxParameters.FilmSizeID
            'DicomFilmBoxParameters.ConfigurationInformation
            'DicomFilmBoxParameters.AnnotationDisplayFormatID
            'DicomFilmBoxParameters.SmoothingType
            'DicomFilmBoxParameters.BorderDensity
            'DicomFilmBoxParameters.EmptyImageDensity
            'DicomFilmBoxParameters.Trim
            'DicomFilmBoxParameters.RequestedResolutionID
            'DicomFilmBoxParameters.MaxDensity
            'DicomFilmBoxParameters.MinDensity
            'DicomFilmBoxParameters.Illumination
            'DicomFilmBoxParameters.ReflectedAmbientLight
            'DicomFilmBoxParameters.MagnificationType

            ' Create a Film Box
            printSCU.CreateFilmBox(filmBoxParameters, Nothing)
            MessageBox.Show(printSCU.GetFilmBoxInstanceUid(), "Film Box SOP Instance UID", MessageBoxButtons.OK)

            ' Create a Presentation LUT
            If printSCU.IsClassSupported(DicomPrintScuPrintManagementClassFlags.PresentationLutSopClass) Then
               ' Make sure that you have a valid presentation state dataset,
               ' otherwise leave this code commented out

               '
               'using (DicomDataSet presentationLUTDataset = new DicomDataSet())
               '{
               '//Load DICOM File
               'presentationLUTDataset.Load(@"C:\PresLUT.dcm", DicomDataSetLoadFlags.None);
               'printSCU.CreatePresentationLUT(presentationLUTDataset, null);

               'string presLUTInstanceUID = printSCU.GetPresentationLutInstanceUid();
               'if(presLUTInstanceUID != null)
               '{
               'MessageBox.Show(presLUTInstanceUID, "Pres LUT SOP Instance UID", MessageBoxButtons.OK);
               'printSCU.UpdateFilmBox(null, presLUTInstanceUID);
               '}
               '}
               '
            End If

            Dim imageDataset As DicomDataSet = New DicomDataSet()
            Using (imageDataset)
               'Load DICOM File
               imageDataset.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE3.dcm", DicomDataSetLoadFlags.LoadAndClose)
               ' Update the Image Box. Since the Image Display Format of the Film Box was
               ' set to "STANDARD\1,1", then we are supposed to have one Image Box created
               ' by the Print SCP.
               If printSCU.GetImageBoxesCount() > 0 Then
                  MessageBox.Show(printSCU.GetImageBoxInstanceUid(0), "Image Box SOP Instance UID", MessageBoxButtons.OK)

                  Dim imageBoxParameters As DicomImageBoxParameters = printSCU.GetDefaultImageBoxParameters()
                  imageBoxParameters.ImagePosition = 1
                  'Over here we can set some other image box parameters before updating the image box.
                  'To set these parameters we can access one or more of these properties:
                  'DicomImageBoxParameters.MinDensity
                  'DicomImageBoxParameters.MaxDensity
                  'DicomImageBoxParameters.RequestedImageSize
                  'DicomImageBoxParameters.Polarity
                  'DicomImageBoxParameters.MagnificationType
                  'DicomImageBoxParameters.SmoothingType
                  'DicomImageBoxParameters.ConfigurationInformation
                  'DicomImageBoxParameters.RequestedDecimateCropBehavior

                  printSCU.UpdateImageBox(printSCU.GetImageBoxInstanceUid(0), imageDataset, imageBoxParameters, Nothing, Nothing)
                  ' We don't need them any more
                  printSCU.FreeImageBoxesInstanceUids()
               End If
            End Using

            ' Update the Annotation Boxes (if there are any) 
            Dim annotationBoxCount As Integer = printSCU.GetAnnotationBoxesCount()
            Dim i As Integer = 0
            Do While i < annotationBoxCount
               printSCU.UpdateAnnotationBox(printSCU.GetAnnotationBoxInstanceUid(i), i + 1, "Some Text")
               i += 1
            Loop
            printSCU.FreeAnnotationBoxesInstanceUids() ' We don't need them any more

            ' Print the Film Session (or the Film Box; there is no difference since we
            ' have a single Film Box in the Film Session) 
            printSCU.PrintFilmSession()
            ' We can also call this
            'PrintSCU.PrintFilmBox();

            ' Display some info about the Print Job
            If printSCU.IsClassSupported(DicomPrintScuPrintManagementClassFlags.PrintJobSopClass) Then
               GetPrintJobInfo(printSCU, printSCU.GetPrintJobInstanceUid())
            End If

            ' Delete the Film Box (anyway, it would be deleted when the Film Session
            ' is deleted) 
            printSCU.DeleteFilmBox()

            ' Delete the Film Session
            printSCU.DeleteFilmSession()

            ' We can also call printSCU.DeletePresentationLUT and printSCU.DeleteOverlayBox
            ' to Delete the Presentation LUT and the Image Overlay Box 

         Catch ex As DicomException
            MessageBox.Show(String.Format("An error occurred, code: {0}", ex.Code))
            Return
         Finally
            ' Release the Association and close the connection
            printSCU.Release()
         End Try
      End Using
      DicomNet.Shutdown()
      DicomEngine.Shutdown()
   End Sub

Private Sub GetPrinterInfo(ByVal printSCU As DicomPrintScu)
' Query the Print SCP for the information
Try
   Dim printerInfo As DicomPrinterInformation = printSCU.GetPrinterInformation(Nothing, True)
   Dim msg As StringBuilder = New StringBuilder()
   msg.AppendFormat("Printer Status: {0}{2}Printer Status Info: {1}", printerInfo.PrinterStatus, printerInfo.PrinterStatusInfo, Environment.NewLine)
   'Over here we can also investigate other printer information by accessing the following 
   'properties from the DicomPrinterInformation class: TimeOfLastCalibration, DateOfLastCalibration,
   'SoftwareVersions, DeviceSerialNumber, ManufacturerModelName , Manufacturer, CreationDate, and CreationTime.
   MessageBox.Show(msg.ToString(), "Printer Info", MessageBoxButtons.OK)
Catch ex As DicomException
   MessageBox.Show(String.Format("Failed to get printer information, Error code: {0}", ex.Code))
End Try
End Sub

Private Sub GetPrinterConfigInfo(ByVal printSCU As DicomPrintScu)
' Assume that the Association is already established

Try
' Query the Print SCP for the printer configuration information
Dim printerConfiguration As DicomDataSet = printSCU.GetPrinterConfiguration()

' We will display only the Printer Name and Memory Bit Depth
' in the first Item

Dim element As DicomElement = printerConfiguration.FindFirstElement(Nothing, DicomTag.PrinterConfigurationSequence, False)
If element Is Nothing Then
   Return
End If

element = printerConfiguration.GetChildElement(element, True)
If element Is Nothing Then
   Return
End If

element = printerConfiguration.GetChildElement(element, True)
If element Is Nothing Then
   Return
End If

Dim msg As StringBuilder = New StringBuilder()
msg.Append("Printer Name: ")

Dim printerName As DicomElement = printerConfiguration.FindFirstElement(element, DicomTag.PrinterName, True)
If Not printerName Is Nothing Then
   Dim name As String = printerConfiguration.GetStringValue(printerName, 0)
   If Not name Is Nothing Then
   msg.AppendFormat("{0}{1}", name, Environment.NewLine)
   Else
   msg.AppendFormat("N/A{0}", Environment.NewLine)
   End If
End If

msg.Append("Memory Bit Depth: ")

Dim memoryBitDepth As DicomElement = printerConfiguration.FindFirstElement(element, DicomTag.MemoryBitDepth, True)
If Not memoryBitDepth Is Nothing Then
   Dim value As Short() = printerConfiguration.GetShortValue(memoryBitDepth, 0, 1)
   If value.Length > 0 Then
   msg.AppendFormat("{0}", value(0))
   Else
   msg.Append("N/A")
   End If
End If
MessageBox.Show(msg.ToString(), "Printer Config Info", MessageBoxButtons.OK)

Catch ex As DicomException
MessageBox.Show(String.Format("Failed to get Printer Configuration Info, Error code: {0}", ex.Code))
End Try
End Sub

Private Sub GetPrintJobInfo(ByVal printSCU As DicomPrintScu, ByVal printJobInstanceUID As String)
' Query the Print SCP for the Print Job information
Try
Dim printJobInfo As DicomPrintJobInformation = printSCU.GetPrintJobInformation(printJobInstanceUID, Nothing)
Dim msg As StringBuilder = New StringBuilder()

msg.AppendFormat("Execution Status: {0}{2}Execution Status Info: {1}", printJobInfo.ExecutionStatus, printJobInfo.ExecutionStatusInfo, Environment.NewLine)

MessageBox.Show(msg.ToString(), "Print Job Info", MessageBoxButtons.OK)
Catch ex As DicomException
MessageBox.Show(String.Format("Failed to get Print Job information, Error code: {0}", ex.Code))
End Try
End Sub
C#Copy Code
public class MyDicomPrintSCU : DicomPrintScu
{
   public MyDicomPrintSCU(string path) : base(path) { }
   public override void OnStatus(DicomPrintScuStatus status, DicomCommandStatusType operationStatus)
   {
      string statusCodeType = "Unknown";
      StringBuilder msg = new StringBuilder();
      switch (status)
      {
         case DicomPrintScuStatus.ReceiveAbort:
            DicomPrintScuAbortInformation printSCUAbortInfo = GetAbortInformation();
            msg.AppendFormat("Source = {0}, Reason = {1}", printSCUAbortInfo.Source, printSCUAbortInfo.Reason);
            MessageBox.Show(msg.ToString(), "Print SCP Aborted the Association", MessageBoxButtons.OK);
            break;

         case DicomPrintScuStatus.ReceivePrintFilmSessionRsp:
            DicomCommandStatusType commandStatusType = GetLastOperationStatus();
            if (operationStatus == DicomCommandStatusType.Success)
            {
               if (commandStatusType == DicomCommandStatusType.Success)
               {
                  statusCodeType = "Success";
               }
               else
               {
                  statusCodeType = "Warning";
               }
            }
            else
            {
               statusCodeType = "Failure";
            }
            msg.AppendFormat("Status: 0x{0:X4} {1}", commandStatusType, statusCodeType);
            MessageBox.Show(msg.ToString(), "Received N-ACTION-RSP (Basic Film Session SOP Class)", MessageBoxButtons.OK);
            break;
      }
   }


   public override void OnPrinterReport(int eventTypeID, DicomPrinterReportInformation reportInfo)
   {
      StringBuilder msg = new StringBuilder();
      string eventTypeName = "Normal";
      switch (eventTypeID)
      {
         case 2:
            eventTypeName = "Warning";
            break;

         case 3:
            eventTypeName = "Failure";
            break;
      }

      msg.AppendFormat("Event Type Name: {0}", eventTypeName);

      if (eventTypeID != 1 && reportInfo != null)
      {
         if (reportInfo.PrinterStatusInfo != null)
         {
            msg.AppendFormat("{0}Printer Status Info: {1}", Environment.NewLine, reportInfo.PrinterStatusInfo);
         }

         if (reportInfo.FilmDestination != null)
         {
            msg.AppendFormat("{0}Film Destination: {1}", Environment.NewLine, reportInfo.FilmDestination);
         }

         if (reportInfo.PrinterName != null)
         {
            msg.AppendFormat("{0}Printer Name: {1}", Environment.NewLine, reportInfo.PrinterName);
         }
      }
      MessageBox.Show(msg.ToString(), "Printer Status Report", MessageBoxButtons.OK);
   }

   public override void OnPrintJobReport(string printJobInstanceUID, int eventTypeID, DicomPrintJobReportInformation reportInfo)
   {
      StringBuilder msg = new StringBuilder();
      msg.AppendFormat("Print Job SOP Instance UID: {0}", printJobInstanceUID);

      string eventTypeName = "Pending";
      switch (eventTypeID)
      {
         case 2:
            eventTypeName = "Printing";
            break;

         case 3:
            eventTypeName = "Done";
            break;

         case 4:
            eventTypeName = "Failure";
            break;
      }
      msg.AppendFormat("{0}Event Type Name: {1}", Environment.NewLine, eventTypeName);

      if (reportInfo != null)
      {
         if (reportInfo.ExecutionStatusInfo != null)
         {
            msg.AppendFormat("{0}Execution Status Info: {1}", Environment.NewLine, reportInfo.ExecutionStatusInfo);
         }

         if (reportInfo.FilmSessionLabel != null)
         {
            msg.AppendFormat("{0}Film Session Label: {1}", Environment.NewLine, reportInfo.FilmSessionLabel);
         }

         if (reportInfo.PrinterName != null)
         {
            msg.AppendFormat("{0}Printer Name: {1}", Environment.NewLine, reportInfo.PrinterName);
         }
      }
      MessageBox.Show(msg.ToString(), "Print Job Status Report", MessageBoxButtons.OK);
   }
};

void PerformBasicPM()
{

   //It's assumed that support for medical communication is already unlocked

   //Make sure to initialize the DICOM engine, this needs to be done only once 
   //In the whole application
   DicomEngine.Startup();

   //Make sure to initialize the DICOM Communication engine, this needs to be done only once 
   //In the whole application
   DicomNet.Startup();

   //The DicomPrintSCU is disposable, this is why we are using the "using" keyword
   using (MyDicomPrintSCU printSCU = new MyDicomPrintSCU(null))
   {
      printSCU.SetTimeout(60);

      try
      {
         // Establish the Association
         bool ret = printSCU.Associate("10.1.1.209", 7104, "PrintSCP", "PrintSCU",
                              DicomPrintScuPrintManagementClassFlags.BasicGrayscalePmMetaSopClass |
                              DicomPrintScuPrintManagementClassFlags.BasicColorPmMetaSopClass |
                              DicomPrintScuPrintManagementClassFlags.BasicAnnotationBoxSopClass |
                              DicomPrintScuPrintManagementClassFlags.BasicPrintImageOverlayBoxSopClass |
                              DicomPrintScuPrintManagementClassFlags.PresentationLutSopClass |
                              DicomPrintScuPrintManagementClassFlags.PrintJobSopClass |
                              DicomPrintScuPrintManagementClassFlags.PrinterConfigurationRetrievalSopClass);
         //The method will return false if the association was rejected,
         //if some other error occurred then an exception will be thrown
         if (ret == false)
         {
            DicomPrintScuAssociateRejectInformation associateRejectInfo = printSCU.GetAssociateRejectInformation();
            if (associateRejectInfo != null)
            {
               StringBuilder msg = new StringBuilder();
               msg.AppendFormat("Source = {0}, Reason = {1}", associateRejectInfo.Source, associateRejectInfo.Reason);
               MessageBox.Show(msg.ToString());
               return;
            }
         }

         // Display some printer info
         GetPrinterInfo(printSCU);

         // Display some printer configuration info
         GetPrinterConfigInfo(printSCU);

         // Create a Film Session
         DicomFilmSessionParameters filmSessionParameters = printSCU.GetDefaultFilmSessionParameters();
         filmSessionParameters.NumberOfCopies = 1;

         //Over here we can set some other film session parameters before creating the film session.
         //To set these parameters we can access one or more of these properties:
         //DicomFilmSessionParameters.NumberOfCopies
         //DicomFilmSessionParameters.MemoryAllocation
         //DicomFilmSessionParameters.OwnerID
         //DicomFilmSessionParameters.PrintPriority
         //DicomFilmSessionParameters.MediumType
         //DicomFilmSessionParameters.FilmDestination
         //DicomFilmSessionParameters.FilmSessionLabel

         printSCU.CreateFilmSession(filmSessionParameters, true);
         MessageBox.Show(printSCU.GetFilmSessionInstanceUid(), "Film Session SOP Instance UID", MessageBoxButtons.OK);

         // Update the Film Session to specify a "MED" Print Priority
         filmSessionParameters = printSCU.GetDefaultFilmSessionParameters();
         filmSessionParameters.PrintPriority = "MED";
         printSCU.UpdateFilmSession(filmSessionParameters);


         DicomFilmBoxParameters filmBoxParameters = printSCU.GetDefaultFilmBoxParameters();

         if (printSCU.IsClassSupported(DicomPrintScuPrintManagementClassFlags.BasicAnnotationBoxSopClass))
         {
            filmBoxParameters.AnnotationDisplayFormatID = "SomeID";
         }

         //Over here we can set some other film box parameters before creating the film box.
         //To set these parameters we can access one or more of these properties:
         //DicomFilmBoxParameters.ImageDisplayFormat
         //DicomFilmBoxParameters.FilmOrientation
         //DicomFilmBoxParameters.FilmSizeID
         //DicomFilmBoxParameters.ConfigurationInformation
         //DicomFilmBoxParameters.AnnotationDisplayFormatID
         //DicomFilmBoxParameters.SmoothingType
         //DicomFilmBoxParameters.BorderDensity
         //DicomFilmBoxParameters.EmptyImageDensity
         //DicomFilmBoxParameters.Trim
         //DicomFilmBoxParameters.RequestedResolutionID
         //DicomFilmBoxParameters.MaxDensity
         //DicomFilmBoxParameters.MinDensity
         //DicomFilmBoxParameters.Illumination
         //DicomFilmBoxParameters.ReflectedAmbientLight
         //DicomFilmBoxParameters.MagnificationType

         // Create a Film Box
         printSCU.CreateFilmBox(filmBoxParameters, null);
         MessageBox.Show(printSCU.GetFilmBoxInstanceUid(), "Film Box SOP Instance UID", MessageBoxButtons.OK);

         // Create a Presentation LUT
         if (printSCU.IsClassSupported(DicomPrintScuPrintManagementClassFlags.PresentationLutSopClass))
         {
            // Make sure that you have a valid presentation state dataset,
            // otherwise leave this code commented out

            /*
            using (DicomDataSet presentationLUTDataset = new DicomDataSet())
            {
               //Load DICOM File
               presentationLUTDataset.Load(LeadtoolsExamples.Common.ImagesPath.Path + "plut_Pre.dcm", DicomDataSetLoadFlags.None);
               printSCU.CreatePresentationLUT(presentationLUTDataset, null);

               string presLUTInstanceUID = printSCU.GetPresentationLutInstanceUid();
               if(presLUTInstanceUID != null)
               {
                  MessageBox.Show(presLUTInstanceUID, "Pres LUT SOP Instance UID", MessageBoxButtons.OK);
                  printSCU.UpdateFilmBox(null, presLUTInstanceUID);
               }
            }
             */
         }

         using (DicomDataSet imageDataset = new DicomDataSet())
         {
            //Load DICOM File
            imageDataset.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE3.dcm", DicomDataSetLoadFlags.LoadAndClose);
            // Update the Image Box. Since the Image Display Format of the Film Box was
            // set to "STANDARD\1,1", then we are supposed to have one Image Box created
            // by the Print SCP.
            if (printSCU.GetImageBoxesCount() > 0)
            {
               MessageBox.Show(printSCU.GetImageBoxInstanceUid(0), "Image Box SOP Instance UID", MessageBoxButtons.OK);

               DicomImageBoxParameters imageBoxParameters = printSCU.GetDefaultImageBoxParameters();
               imageBoxParameters.ImagePosition = 1;

               //Over here we can set some other image box parameters before updating the image box.
               //To set these parameters we can access one or more of these properties:
               //DicomImageBoxParameters.MinDensity
               //DicomImageBoxParameters.MaxDensity
               //DicomImageBoxParameters.RequestedImageSize
               //DicomImageBoxParameters.Polarity
               //DicomImageBoxParameters.MagnificationType
               //DicomImageBoxParameters.SmoothingType
               //DicomImageBoxParameters.ConfigurationInformation
               //DicomImageBoxParameters.RequestedDecimateCropBehavior

               printSCU.UpdateImageBox(printSCU.GetImageBoxInstanceUid(0),
                                       imageDataset,
                                       imageBoxParameters,
                                       null,
                                       null);
               // We don't need them any more
               printSCU.FreeImageBoxesInstanceUids();
            }
         }

         // Update the Annotation Boxes (if there are any) 
         int annotationBoxCount = printSCU.GetAnnotationBoxesCount();
         for (int i = 0; i < annotationBoxCount; i++)
         {
            printSCU.UpdateAnnotationBox(printSCU.GetAnnotationBoxInstanceUid(i), i + 1, "Some Text");
         }
         printSCU.FreeAnnotationBoxesInstanceUids(); // We don't need them any more

         // Print the Film Session (or the Film Box; there is no difference since we
         // have a single Film Box in the Film Session) 
         printSCU.PrintFilmSession();
         // We can also call this
         //PrintSCU.PrintFilmBox();

         // Display some info about the Print Job
         if (printSCU.IsClassSupported(DicomPrintScuPrintManagementClassFlags.PrintJobSopClass))
         {
            GetPrintJobInfo(printSCU, printSCU.GetPrintJobInstanceUid());
         }

         // Delete the Film Box (anyway, it would be deleted when the Film Session
         // is deleted) 
         printSCU.DeleteFilmBox();

         // Delete the Film Session
         printSCU.DeleteFilmSession();

         // We can also call printSCU.DeletePresentationLUT and printSCU.DeleteOverlayBox
         // to Delete the Presentation LUT and the Image Overlay Box 

      }
      catch (DicomException ex)
      {
         MessageBox.Show(string.Format("An error occurred, code: {0}", ex.Code));
         return;
      }
      finally
      {
         // Release the Association and close the connection
         printSCU.Release();
      }
   }
   DicomNet.Shutdown();
   DicomEngine.Shutdown();
}

void GetPrinterInfo(DicomPrintScu printSCU)
{
   // Query the Print SCP for the information
   try
   {
      DicomPrinterInformation printerInfo = printSCU.GetPrinterInformation(null, true);
      StringBuilder msg = new StringBuilder();
      msg.AppendFormat("Printer Status: {0}{2}Printer Status Info: {1}", printerInfo.PrinterStatus, printerInfo.PrinterStatusInfo, Environment.NewLine);

      //Over here we can also investigate other printer information by accessing the following 
      //properties from the DicomPrinterInformation class: TimeOfLastCalibration, DateOfLastCalibration,
      //SoftwareVersions, DeviceSerialNumber, ManufacturerModelName , Manufacturer, CreationDate, and CreationTime.

      MessageBox.Show(msg.ToString(), "Printer Info", MessageBoxButtons.OK);
   }
   catch (DicomException ex)
   {
      MessageBox.Show(string.Format("Failed to get printer information, Error code: {0}", ex.Code));
   }
}

void GetPrinterConfigInfo(DicomPrintScu printSCU)
{
   // Assume that the Association is already established

   try
   {
      // Query the Print SCP for the printer configuration information
      DicomDataSet printerConfiguration = printSCU.GetPrinterConfiguration();

      // We will display only the Printer Name and Memory Bit Depth
      // in the first Item

      DicomElement element = printerConfiguration.FindFirstElement(null, DicomTag.PrinterConfigurationSequence, false);
      if (element == null)
         return;

      element = printerConfiguration.GetChildElement(element, true);
      if (element == null)
         return;

      element = printerConfiguration.GetChildElement(element, true);
      if (element == null)
         return;

      StringBuilder msg = new StringBuilder();
      msg.Append("Printer Name: ");

      DicomElement printerName = printerConfiguration.FindFirstElement(element, DicomTag.PrinterName, true);
      if (printerName != null)
      {
         string name = printerConfiguration.GetStringValue(printerName, 0);
         if (name != null)
         {
            msg.AppendFormat("{0}{1}", name, Environment.NewLine);
         }
         else
         {
            msg.AppendFormat("N/A{0}", Environment.NewLine);
         }
      }

      msg.Append("Memory Bit Depth: ");

      DicomElement memoryBitDepth = printerConfiguration.FindFirstElement(element, DicomTag.MemoryBitDepth, true);
      if (memoryBitDepth != null)
      {
         short[] value = printerConfiguration.GetShortValue(memoryBitDepth, 0, 1);
         if (value.Length > 0)
         {
            msg.AppendFormat("{0}", value[0]);
         }
         else
         {
            msg.Append("N/A");
         }
      }
      MessageBox.Show(msg.ToString(), "Printer Config Info", MessageBoxButtons.OK);

   }
   catch (DicomException ex)
   {
      MessageBox.Show(string.Format("Failed to get Printer Configuration Info, Error code: {0}", ex.Code));
   }
}

void GetPrintJobInfo(DicomPrintScu printSCU, string printJobInstanceUID)
{
   // Query the Print SCP for the Print Job information
   try
   {
      DicomPrintJobInformation printJobInfo = printSCU.GetPrintJobInformation(printJobInstanceUID, null);
      StringBuilder msg = new StringBuilder();

      msg.AppendFormat("Execution Status: {0}{2}Execution Status Info: {1}",
         printJobInfo.ExecutionStatus,
         printJobInfo.ExecutionStatusInfo,
         Environment.NewLine);

      MessageBox.Show(msg.ToString(), "Print Job Info", MessageBoxButtons.OK);
   }
   catch (DicomException ex)
   {
      MessageBox.Show(string.Format("Failed to get Print Job information, Error code: {0}", ex.Code));
   }
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

The Association must be established successfully before any of the print management operations can be performed.

This method will first try to connect to the Print SCP. If successful, it will then try to establish the Association. This method will not return until the Association is accpeted/rejected by the Print SCP, or an error occurs.

The method Leadtools.Dicom.DicomPrintScu.GetAssociateRejectInformation can be used to get information about the Association rejection in case the Association request was rejected by the Print SCP.

The supportedClasses parameter specifies those SOP/Meta SOP Classes that are supported by the Print SCU itself. Once the Association is established, the method IsClassSupported can be used to test whether a particular SOP/Meta SOP Class is supported on the Association (and hence by the Print SCP).

The established Association can be released using the method Leadtools.Dicom.DicomPrintScu.Release. It can also be aborted using the method Leadtools.Dicom.DicomPrintScu.Abort.

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also

Leadtools.Dicom requires a Medical toolkit server license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features