Hello,
I am using DPO7254C(Tektronix) and creating the code in VBA to make automatic system.
But there's runtime error like below captured and I don't know why it occurred.
Please let me know what is problem in my code or what I should check.
Below code is to get the caputured screen from oscilloscope and error is on line : [imageBytes = osc.ReadIEEEBlock(BinaryType_UI1, True)]
-------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Public OSC_ioMgr As New VISAComLib.ResourceManager
Public osc As New VISAComLib.FormattedIO488
Public OSC_GPIO As String
Public imageBytes() As Byte
Sub CaptureScreen()
' Connect to the oscilloscope
Set osc.IO = OSC_ioMgr.Open("GPIB0::15::INSTR")
osc.IO.Timeout = 10000
' Set up the oscilloscope for screen capture
osc.WriteString "HARDCOPY:FORMAT BMP"
osc.WriteString "HARDCOPY:Port FILE"
osc.WriteString "HARDCOPY:PALETTE INKSAVER"
osc.WriteString "HARDCOPY:FILENAME ""Screen shot"""
osc.WriteString "HARDCOPY START"
Sleep 5000 ' Wait for 2 seconds
imageBytes = osc.ReadIEEEBlock(BinaryType_UI1, True)
Sleep 2000 ' Wait for 2 seconds
'Save image to a temporary file
fileNumber = FreeFile
'Open "D:\temp.jpg" For Binary Lock Read Write As #fileNumber
Open "D:\temp.jpg" For Binary Lock Read Write As #fileNumber
Put #fileNumber, , imageBytes
Close #fileNumber
'Load the image back into Excel
Dim picture As Shape
Set picture = Sheets("Sheet1").Shapes.AddPicture("D:\temp.jpg", msoFalse, msoTrue, Sheets("Sheet1").Cells("A1").Left, Sheets("Sheet1").Cells("A1").Top, 1024 * 0.5, 768 * 0.5)
End Sub