Managing Ports and Transfers in .NET// Define a delegate class to handle ErrorReceived events.
internal delegate void SerialErrorReceivedEventHandlerDelegate(object sender,
SerialErrorReceivedEventArgs e);// Create an instance of the delegate.private SerialErrorReceivedEventHandler SerialErrorReceivedEventHandler1;SerialErrorReceivedEventHandler1 =
new SerialErrorReceivedEventHandler(ErrorReceived);
The application can assign the delegate as the handler routine that will execute
when an ErrorReceived event occurs on the port:AddHandler myComPort.ErrorReceived, SerialErrorReceivedEventHandler1
myComPort.ErrorReceived += SerialErrorReceivedEventHandler1;