by Drod » Tue Apr 03, 2012 7:50 am
Eddietronic, as soon as you test some instructions, please, let us know if you had success!
Here's an Excel Macro example in order to comunicate with the hardware, sent by the creator:
I stumbled across a HO 3852A measurement mainframe a few months ago for
the sum of 60€ so I spent the weekend writing code for that. I have a
Excel sample I will post later that pulls 10 readings from the
High-Speed voltmeter and puts them in an excel sheet.
OK. Here is the Excelmacro:
Sub Logger()
'
' Loger Macro
' Sample to read 10 values from a HP 3852A
'
Dim Port As Integer
Dim rc As Long
Dim str As String
Dim i, j As Integer
Dim n As Long
Dim Result(20) As Double
Port = 1
j = 1
rc = CommClose(Port)
rc = CommOpen(Port, "COM5", "baud=9600 parity=N data=8 stop=1") ' Speed does not really matter as COM-port is virtual anyway
If rc > 0 Then
rc = CommGetError(str)
MsgBox str
End If
str = "Q " + Chr$(3) ' Turn off interface verbose mode
rc = CommWrite(Port, str)
CommFlush (Port)
str = "6" + Chr$(10) ' Set remote
rc = CommWrite(Port, str)
For n = 1 To 1000
Next n
str = "2 ?U8" + Chr$(10) ' Set HP 3852A to listen
rc = CommWrite(Port, str)
For n = 1 To 1000
Next n
CommFlush (Port)
rc = GPIB(Port, "DISPLAY START") ' Show info on display
rc = GPIB(Port, "OUTBUF ON") ' Set output buffering on
rc = GPIB(Port, "USE 600") ' Use Voltmeter in slot 6-7
rc = GPIB(Port, "RST 600") ' Reset it
rc = GPIB(Port, "TERM EXT") ' Use voltmeter external terminals
rc = GPIB(Port, "NRDGS 10") ' Ten readings
rc = GPIB(Port, "DELAY 0,1") ' 1s between readings
rc = GPIB(Port, "AZERO ONCE") ' Send command
rc = GPIB(Port, "TRIG INT") ' Internal trigger (pacer)
rc = GPIB(Port, "XRDGS 600") ' Do read
MsgBox "Press OK when you think 3852A has finished"
CommFlush (Port)
str = "2 ?UX" + Chr$(10) ' Set HP 3852A to talk
rc = CommWrite(Port, str)
For n = 1 To 1000
Next n
rc = GPIB(Port, "DISPLAY end") ' Show we're done
rc = CommWrite(Port, str)
For n = 1 To 1000
Next n
rc = GPIBReadValues(Port, 10, Result)
str = CommGetstr(Port) ' Read data to skip garbage
Cells(1, 1).Value = "Reading"
Cells(1, 2).Value = "Value"
For i = 2 To 11
Cells(i, 2).Value = Result(i)
Cells(i, 1).Value = i - 1
Next i
Cells(20, 1).Value = rc
str = "2 ?U " + Chr$(10) ' Unlisten
rc = CommWrite(Port, str)
str = "4 " + Chr$(10) ' IFC, Interface Clear
rc = CommWrite(Port, str)
rc = CommClose(Port)
'
End Sub
Function CommGetstr(Port As Integer) As String
Dim str As String
Dim timeout As Integer
done = 0
timeout = 1000
While done <> 1 And timeout > 0
If CommRead(Port, str, 10) > 0 Then
If InStr(str, Chr$(10)) Then done = 1
CommGetstr = CommGetstr + str
End If
timeout = timeout - 1
Wend
CommGetstr = Replace(CommGetstr, Chr$(0), "")
CommGetstr = Replace(CommGetstr, Chr$(10), "*")
CommGetstr = Replace(CommGetstr, Chr$(13), "|")
End Function
Function GPIB(Port As Integer, Cmd As String) As Integer
rc = CommWrite(Port, " " + Cmd + Chr$(10))
For n = 1 To 1000
Next n
End Function
Function GPIBReadValues(Port As Integer, Num As Integer, A As Variant) As Integer
Dim str As String ' Read Num decimal values from GPIB at Port, put into Array
Dim str2 As String ' Returns number of values read or valued resd+1000 on timeout
Dim nvalues As Integer
Dim sVal As String
done = 0
nvalues = 0
timeout = 100000 ' Loop counter for timeout
While nvalues <= Num And timeout > 0
If CommRead(Port, str, 10) > 0 Then
str2 = str2 + str
End If
'
If InStr(str2, Chr$(10)) Then
sVal = Left(str2, InStr(str2, Chr$(10)) - 1)
sVal = Replace(sVal, Chr$(13), "")
str2 = Mid(str2, InStr(str2, Chr$(10)) + 2)
A(nvalues) = Val(sVal)
'MsgBox sVal
nvalues = nvalues + 1
End If
timeout = timeout - 1
Wend
For n = 1 To 1
Next n
If timeout <= o Then nvalues = nvalues + 1000
GPIBReadValues = nvalues
End Function