The maximum number of serial ports that NI-VISA currently supports on any platform is 256. The default numbering of serial ports is system dependent, as shown in the following table.

Table 8. How Serial Ports Are Numbered
Platform Method
Windows 7/Vista/XP/Server 2008 R2/Server 2003 R2 All COM and LPT ports are automatically detected when you call viFindRsrc(). The VISA interface number may not equal the COM port number.
LabVIEW RT All COM ports are automatically detected when you call viFindRsrc().
LabVIEW PDA All COM ports are automatically detected when you call viFindRsrc().
Mac OS X All COM ports are automatically detected when you call viFindRsrc().
Linux ASRL1-ASRL4 access /dev/ttyS0 – /dev/ttyS3.

If you need to know programmatically which ASRL INSTR resource maps to which underlying Serial port, the following code will retrieve and display that information.

C Examples

#include "visa.h"
int main(void)
{
ViStatus     status;                    /* For checking errors */
ViSession    defaultRM;                 /* Communication channels */
ViSession    instr;                     /* Communication channels */
ViChar       rsrcName[VI_FIND_BUFLEN];  /* Serial resource name */
ViChar       intfDesc[VI_FIND_BUFLEN];  /* Port binding description */
ViUInt32     retCount;                  /* To hold number of resources */
ViFindList   flist;                     /* To hold list of resources */ 

/* Begin by initializing the system */
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS) {

        /* Error Initializing VISA...exiting */
        return -1;
    }
    status = viFindRsrc (defaultRM, "ASRL?*INSTR", &flist, &retCount, rsrcName);
    while (retCount--) {
        status = viOpen (defaultRM, rsrcName, VI_NULL, VI_NULL, &instr);
        if (status < VI_SUCCESS)
            printf ("Could not open %s, status = 0x%08lX\n",rsrcName, status);
        else
            {
            status = viGetAttribute (instr, VI_ATTR_INTF_INST_NAME, intfDesc);
            printf ("Resource %s, Description %s\n", rsrcName, intfDesc);
            status = viClose (instr);
            }
        status = viFindNext (flist, rsrcName);
    }
    viClose (flist);
    viClose (defaultRM);
    return 0;
}

Visual Basic Example

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          As ViStatus
   Dim dfltRM        As ViSession
   Dim sesn          As ViSession
   Dim fList         As ViFindList
   Dim rsrcName      As String * VI_FIND_BUFLEN
   Dim instrDesc     As String * VI_FIND_BUFLEN
   Dim nList         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