About PortController
Introduction
Purchasing PortController
Redistributing PortController
License Agreement
Support
Getting Started
How to Use PortController
PortController Sample Projects
Handling PortController Errors
Reference
Properties
AvailableSystemPorts
BaudRate Property
Break Property
BytesUsedRQ Property
BytesUsedTQ Property
Cd Property
Cts Property
DataBits Property
Dsr Property
Dtr Property
DtrDsr Property
EnableReadOnEventChar Property
EventChar Property
ForceBeginInvokeEventFiring Property
IsOpen Property
IsFileTransferInProgress Property
Parity Property
PortHandle Property
PortName Property
ReceiveBufferSize Property
Ring Property
Rts Property
RtsCts Property
StopBits Property
SystemPorts Property
TraceOutput Property
TransmitBufferSize
XoffByte Property
XonByte Property
XonXoff Property
Methods
CancelFileTransfer Method
ClearRQ Method
ClearTQ Method
Close Method
GetErrorStatus Method
Open Method
Read Method
ReadBinary Method
ReceiveFileXModem Method
ReceiveFileXModemCRC Method
ReceiveFileYModem Method
ReceiveFileZModem Method
SendFileXModem Method
SendFileXModem1k Method
SendFileYModem Method
SendFileZModem Method
SimulateReceivedXoff Method
SimulateReceivedXon Method
Write Method
WriteBinary Method
Events
OnBreakSignal Event
OnCdToggle Event
OnCtsToggle Event
OnDataReceived Event
OnDsrToggle Event
OnError Event
OnEventCharReceived Event
OnFileTransferComplete Event
OnFileTransferStatusUpdate Event
OnRing Event
OnTQEmpty Event

About PortController Errors

PortController notifies your application of any errors it encounters by throwing an exception with a description of the error. The following examples show how to handle these exceptions in your code.

Note that, for simplicity, the examples in the reference section do not include error handling constructs. You may examine the Test Panel sample project for examples of error handling in Visual Basic, C#, and C++.

Visual Basic

PortController errors are handled in Visual Basic using either structured exception handling similar to C# and C++, or by using the familiar unstructured On Error Goto construct. When using structured handling, you must specifically reference the Exception variable as type System.Exception. This is because PortController.NET includes "Windows.h", which globally defines its own exception type and Visual Basic's indifference to case will cause it to default to the exception type. The following example traps an error and displays the error message using structures exception handling:

Try
    myPortController.Open("COM1")
Catch ex As System.Exception
    MsgBox(ex.Message)
End Try
When using unstructured (VB6 style) exception handling, detailed error 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

C#

PortController errors are handled in C# using standard try/catch blocks. The following code traps an error and displays a description in a message box:

try
{
    myPortController.Open("COM1");
}
catch(Exception Ex)
{
    MessageBox.Show(Ex.Message);
}

C++

PortController errors are handled in C++ using standard try/catch blocks. The following code traps an error and displays a description in a message box:

try
{
    myPortController->Open("COM1");
}
catch(Exception *Ex)
{
    MessageBox::Show(Ex->Message);
}