EnumSerialPorts Method

Refreshes information about serial ports and returns their number.

Syntax

Visual Basic
Function EnumSerialPorts() As Long 
Visual C++ (MFC)
long EnumSerialPorts();
Visual C++ (#import)
LONG EnumSerialPorts();

Parameters

None.

Errors

The method may throw exception. Use GetLastError method to get the error code.

Remarks

To retrieve information about each serial port, use GetSerialPort.

Code Example

'---------------------------------------------------------------------
' Visual Basic 6 Example
'---------------------------------------------------------------------
On Error GoTo ErrorHandler
	Dim i As Integer
	Dim nPorts As Integer
	Dim PortName As String

	nPorts = FTSPCControl1.EnumSerialPorts()
	For i = 0 To nPorts
		PortName = FTSPCControl1.GetSerialPort(i)

	' Todo: add your code

	Next i
	Exit Sub

	ErrorHandler:
		Dim err_code As Integer
		err_code = FTSPCControl1.GetLastError
		MsgBox "ErrorCode = " & CStr(err_code) & " - " & _
			Err.Description, vbCritical, "Error!"


/////////////////////////////////////////////////////////////////////
// C++ Example
/////////////////////////////////////////////////////////////////////
CString PortName;

try
{
	long nPorts = m_SPCControl1.EnumSerialPorts();
	for (int i = 0; i < nPorts i++)
	{
		PortName = m_SPCControl1.GetSerialPort(i);
		// Todo: add your code
	}
}
catch(COleDispatchException* E)
{
	MessageBox(E->m_strDescription, mbCaption, MB_OK | MB_ICONERROR);
}