Screen Images as Bitmaps (BMP)

Some of the more recent instruments let you retrieve the screen image as a bitmap. This makes getting the image into a PictureBox reasonably simple. The Keysight 54620-series oscilloscopes let you retrieve a bitmap from the I/O with just a few lines of code. The bitmap is in the IEEE 488.2 binary block data format. Getting the data into a binary file looks like this.

    Dim byteData() As Byte
    Const filePath = "C:\~scp_tmp.bmp"
    With Scope
        .IO.Timeout = 15000
        .WriteString ":DISPlay:DATA? BMP, SCReen"
        byteData = .ReadIEEEBlock(BinaryType_UI1)
        .IO.Timeout = 10000
    End With

You have to declare the 'byteData' as a dynamic array because the size of the data is unknown. The code will return an IEEE488.2 block as bytes. Next save the byte array to a file and then call it with LoadPicture() That's all there is to it. The complete code looks like this:

     Private Sub cmdGetBitMap_Click()
         ' Gets the bitmap from a 5462xA scope
         Dim byteData() As Byte
         Dim dummy As String    
         Const filePath = "C:\~scp_tmp.bmp"
    
         Set Picture1 = LoadPicture("")
    
         With Scope
             .IO.Timeout = 15000
             .WriteString ":DISPlay:DATA? BMP, SCReen"
             byteData = .ReadIEEEBlock(BinaryType_UI1)
             .IO.Timeout = 10000
         End With
    
         saveAsFile filePath, byteData
    
         Picture1.AutoSize = True
         Set Picture1 = LoadPicture(filePath)
         Kill filePath    
     End Sub
     Private Sub saveAsFile(ByVal filePath As String, _
                 byteData() As Byte)
       Dim hFile As Long
       Dim isOpen As Boolean
 
       hFile = FreeFile()
       Open filePath For Binary Access Write Shared As hFile
       isOpen = True
 
       Put #hFile, , byteData
       If isOpen Then Close #hFile
     End Sub