Serial Port Support Example (VB)

NI-VISA

Serial Port Support Example (Visual Basic)

Note  The Visual Basic examples in the NI-VISA Help use the VISA data types where applicable. This feature is available only on Windows. To use this feature, select the VISA library (visa32.dll) as a reference from Visual Basic. This makes use of the type library embedded into the DLL.

Private Declare Function viGetAttrString Lib "VISA32.DLL" Alias "#133" (ByVal vi As ViSession, ByVal attrName As ViAttr, ByVal strValue As Any) As ViStatus

Private Sub vbMain()

Dim stat
Dim dfltRM
Dim sesn
Dim fList
Dim rsrcName
Dim instrDesc
Dim nList
As ViStatus
As ViSession
As ViSession
As ViFindList
As String * VI_FIND_BUFLEN
As String * VI_FIND_BUFLEN
As Long
stat = viOpenDefaultRM(dfltRM)
If (stat < VI_SUCCESS) Then

Rem Error initializing VISA ... exiting
Exit Sub

End If

Rem Find all Serial instruments in the system
stat = viFindRsrc(dfltRM, "ASRL?*INSTR", fList, nList, rsrcName)
If (stat < VI_SUCCESS) Then

Rem Error finding resources ... exiting
viClose (dfltRM)
Exit Sub

End If

While (nList)

stat = viOpen(dfltRM, rsrcName, VI_NULL, VI_NULL, sesn)
If (stat < VI_SUCCESS) Then

Debug.Print "Could not open resource", rsrcName, "Status", stat

Else

stat = viGetAttrString(sesn, VI_ATTR_INTF_INST_NAME, instrDesc)
Debug.Print "Resource", rsrcName, "Description", instrDesc
stat = viClose(sesn)

End If

stat = viFindNext(fList, rsrcName)
nList = nList - 1

Wend
stat = viClose(fList)
stat = viClose(dfltRM)

End Sub