Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Main() ' Declare Variables used in the program Dim status As Long 'VISA function status return code Dim defrm As Long 'Session to Default Resource Manager Dim vi As Long 'Session to instrument Dim strRes As String * 100 'Fixed length string to hold *IDN? Results Dim x As Integer 'Loop Variable Dim output As String 'output string variable Dim ArrayPtr(1) As Long 'Array of Pointers Dim ResultsArray(2500) As Single 'trace element array of Real,32 values 'For Real,64 data use Double. For Int,32 data use Long Dim length As Long 'Number of trace elements return from instrument Dim fnum As Integer 'File Number to used to open file to store data Dim isOpen As Boolean 'Boolean flag used to keep track of open file 'Set the default number of trace elements to the ResultsArray size length = 2500 'Set the array of pointers to the addresses of the variables ArrayPtr(0) = VarPtr(length) ArrayPtr(1) = VarPtr(ResultsArray(0)) On Error GoTo Error_Handler ' Open the default resource manager session status = viOpenDefaultRM(defrm) ' Open the session. Note: For PSA, to use LAN, change the string to ' "TCPIP0::xxx.xxx.xxx.xxx::inst0::INTSR" where xxxxx is the IP address status = viOpen(defrm, "", 0, 0, vi) If (status < 0) Then GoTo VisaErrorHandler 'Ask for the devices's *IDN string. status = viVPrintf(vi, "*IDN?" + Chr$(10), 0) If (status < 0) Then GoTo VisaErrorHandler 'Read back the IDN string from the instrument status = viVScanf(vi, "%t", strRes) If (status < 0) Then GoTo VisaErrorHandler 'Print the IDN string results in a message box MsgBox (strRes) ' Set instrument trace data format to 32-bit Real ' Note: For higher precision use 64-bit data, ":FORM REAL,64" ' For faster data transfer for ESA, use ":FORM INT,32" status = viVPrintf(vi, ":FORM REAL,32" + Chr$(10), 0) If (status < 0) Then GoTo VisaErrorHandler 'Set Analyzer to single sweep mode status = viVPrintf(vi, ":INIT:CONT 0" + Chr$(10), 0) If (status < 0) Then GoTo VisaErrorHandler 'Query the trace data from the instrument 'Note: Change the "%#zb" to "%#Zb" for Real,64 data ' For Int,32 leave the modifier as "%#zb" status = viVQueryf(vi, ":TRAC:DATA? TRACE1" + Chr$(10), _ "%#zb", ArrayPtr(0)) 'Close the vi session and the resource manager session Call viClose(vi) Call viClose(defrm) 'Print number of elements returned MsgBox ("Number of trace elements returned = " & length) 'Create a string from the ResultsArray to output to a file For x = 0 To length - 1 output = output & ResultsArray(x) & vbCrLf Next x 'Print Results to the Screen MsgBox (output) 'Store the results in a text file fnum = FreeFile() 'Get the next free file number Open "bintrace.txt" For Output As #fnum isOpen = True Print #fnum, output ' Intentionally flow into Error Handler to close file Error_Handler: ' Raise the error (if any), but first close the file If isOpen Then Close #fnum If Err Then Err.Raise Err.Number, , Err.Description Exit Sub VisaErrorHandler: Dim strVisaErr As String * 200 Call viStatusDesc(defrm, status, strVisaErr) MsgBox "*** Error : " & strVisaErr, vbExclamation, "VISA Error Message" Exit Sub End Sub