Serial Port Support

NI-VISA

Serial Port Support

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.

How Serial Ports Are Numbered

Platform Method
Windows Vista/XP/2000 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 x86 ASRL1-ASRL4 access /dev/ttyS0 – /dev/ttyS3.
VxWorks x86 ASRL1-ASRL2 access /tyCo/0 – /tyCo/1.

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.

Example

Note  This example shows C source code. There is also an example in Visual Basic syntax.

#include "visa.h"
int main(void)
{

ViStatus
ViSession
ViSession
ViChar
ViChar
ViUInt32
ViFindList
status;
defaultRM;
instr;
rsrcName[VI_FIND_BUFLEN];
intfDesc[VI_FIND_BUFLEN];
retCount;
flist;
/* For checking errors */
/* Communication channels */
/* Communication channel */
/* Serial resource name */
/* Port binding description */
/* To hold number of resources */
/* 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;

}