About PortController
Introduction
Purchasing PortController
Redistributing PortController
License Agreement
Support
Getting Started
How to Use PortController
Using PortController with Visual Basic
Using PortController with Visual C++
Using PortController with Delphi
How to Use Events
Handling Events in Visual Basic
Handling Events in Visual C++
Handling Events in Delphi
PortController Sample Projects
Reading and Writing Binary Data
Handling PortController Errors
Reference
Properties
BaudRate Property
Break Property
BytesUsedRQ Property
BytesUsedTQ Property
Cd Property
Cts Property
DataBits Property
Dsr Property
Dtr Property
DtrDsr Property
EnableReadOnEventChar Property
EventChar Property
Parity Property
PortHandle Property
PortName Property
Ring Property
Rts Property
RtsCts Property
StopBits Property
XonXoff Property
Methods
ClearRQ Method
ClearTQ Method
Close Method
GetErrorStatus Method
Open Method
Read Method
ReadBinary Method
Write Method
WriteBinary Method
SendXoff Method
SendXon Method
Events
BreakSignal Event
CdToggle Event
CtsToggle Event
DataReceived Event
DsrToggle Event
Error Event
EvtCharReceived Event
Ring Event
TQEmpty Event

About PortController Errors

The PortController notifies your application of any errors it encounters through the IErrorInfo interface. Because this is the standard method to communicate error information from a COM object. Visual Basic, Visual C++ and Delphi have built in support for this interface.

Note that, for simplicity, the examples in the reference section do not include error handling constructs. You may examine the TestPanel sample project for examples of error handling in VB, VC++ and Delphi.

Visual Basic

PortController errors are handled in Visual Basic using the familiar On Error Goto construct. When an error occurs, detailed information can be found in the application's global Err object. For example, the following code traps an error and displays a description in a message box:

Private Sub MySub()
    On Error GoTo MyErrorHandler
    myPortController.Open "COM1"
    Exit Sub

MyErrorHandler:
    MsgBox Err.Description
End Sub

Visual C++

The wrapper class that Visual Studio creates when adding PortController to your project uses the older MFC TRY/CATCH/END_CATCH exception handling macros instead of the C++ try/catch constructs. This means that in most cases, you will want to use the same TRY/CATCH/END_CATCH macros when trapping for PortController exceptions. The following example catches any errors and displays a description of the error in a message box:

void MyFunc()
{
    TRY
    {
        m_myPortController.Open("COM1", "9600,8,N,1");
    }

    CATCH(CException, e)
    {
        char lpszError[1024];
        e->GetErrorMessage(lpszError, 1024);

        AfxMessageBox(lpszError);
    }
    END_CATCH
}

If you are not using PortController through the automatically generated wrapper class, you may use the normal C++ try/catch construction to trap errors.

Delphi

PortController errors are handled via ordinary try/except Delphi block. Detailed information about error is passed by Exception object in the on..do statement. The following code traps possible exception and displays a description of error:

procedure MyProc;
  try
    myPortController.Open('COM1', '9600,8,N,1');
  except
    on Exc: Exception do
      ShowMessage(Exc.Message);
  end;
end;