Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

Save HardCopy to PC by vba

DPO70000SX, DPO/MSO70000, DPO7000 Series, DPO/MSO5000 Series
Post Reply
dkq2315
Posts: 1
Joined: July 28th, 2020, 6:05 am
Country: China

Save HardCopy to PC by vba

Post by dkq2315 » July 28th, 2020, 6:52 am

Hi,
I am trying to control my scope using MS Excel VBA.save wave file to my pc.
Following is the VB code which I am having trouble fixing.

Option Explicit
Public id As Integer 'session to instrument
Public Const bytearraysize = 1000000
Public retcount As Long
Public bytearray(bytearraysize) As Byte
Public idn, idos, idac, idlda, idldb, idldc As String
Public rm As VisaComLib.ResourceManager
Public fmio As New VisaComLib.FormattedIO488
Private Declare Sub sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
Public AppSheet As Worksheet
Public strQueryResult As String

'save wave
Sub hcopy()
Dim DoCommand As String

Set AppSheet = ThisWorkbook.Sheets("Sheet1")
Set rm = New VisaComLib.ResourceManager
idos = AppSheet.Cells(1, 2) 'OSC address
Set fmio.IO = rm.Open(idos)
fmio.IO.Timeout = 500 '延时
fmio.IO.Clear
Dim byteData() As Byte

DoCommand = ":HARDCOPY START"
fmio.WriteString (DoCommand)
' byteData = DoQueryIEEEBlock_UI1(":DISPlay:DATA? PNG,COLor")
'save screen image to a file.
Dim insize As Long
insize = 2
Dim strPath As String
strPath = "e:\screen12.png"
If Len(Dir(strPath)) Then
Kill strPath
End If
Dim hFile As Long
hFile = FreeFile
Open strPath For Binary Access Write Lock Write As hFile
Dim longi As Long

'For longi = 0 To insize - 1

Put hFile, , byteData

' Next longi
Close hFile

End Sub

Private Function DoQueryIEEEBlock_UI1(query As String) As Variant
'On Error GoTo VisaComError
fmio.WriteString query
DoQueryIEEEBlock_UI1 = fmio.ReadIEEEBlock(BinaryType_UI1)
'CheckInstrumentErrors
Exit Function
'VisaComError:
End Function


The saved wave file is 0 bytes,where is the problem? can someone help me? thank you very much!

Post Reply

Return to “Windows Based Oscilloscopes”

Who is online

Users browsing this forum: No registered users and 1 guest