CommEvent
Retrieves a numerical event code indicating the most recent communications event or error.
MSComm32 and SComm64 have the same behavior.
 |
|
Syntax |
n = SComm1.CommEvent |
|
|
|
|
value |
A numeric expression containing the numeric event code being one of the following |
|
|
SCommLib.OnCommConstants. |
|
|
1 |
comEvSend |
There are fewer than SThreshold number of characters in the transmit buffer. |
|
2 |
comEvReceive |
There are more than RThreshold number of characters in the receive buffer. |
|
3 |
comEvCTS |
Change in Clear To Send line.
|
|
4 |
comEvDSR |
Change in Data Set Ready line. |
|
5 |
comEvCD |
Change in Carrier Detect line.
|
|
6 |
comEvRing |
Ring detected. Some hardware may not support this event. |
|
7 |
comEvEOF |
End Of File character received.
|
|
|
|
|
|
|
|
|
|
1001 |
comEventBreak |
A Break signal was received.
|
|
1004 |
comEventFrame |
The hardware detected a framing error.
|
|
1006 |
comEventOverrun |
The hardware could not receive data fast enough and some was lost |
|
1008 |
comEventRxOver |
Receive Buffer Overflow. There is no room in the receive buffer. Some data was lost |
|
1009 |
comEventRxParity |
Parity Error. The hardware detected a parity error. |
|
1010 |
comEventTxFull |
Transmit Buffer Full. The transmit buffer was full while trying to queue a character. |
|
1011 |
comEventDCB |
An error occurred while setting up the Windows Com driver. |
Example |
|
|
If SComm1.CommEvent > 1000 then
MessageBox.Show ("A communications ERROR occurred")
End If |
|
|
|
 |
Remarks:
The CommEvent property returns a number so, in Visual Basic, you can write code like this:-
If SComm1.CommEvent = 2 Then
Textbox1.AppendText( SComm1.Input )
End If
If you prefer to use the constant names instead of the numbers - to make your code easier to read - then you can rewrite the above example like this
If SComm1.CommEvent = SCommLib.OnCommConstants.comEvReceive then
Textbox1.AppendText( SComm1.Input )
End If
Note that the syntax is the same as MSComm32 except SCommLib instead of MSCommLib
Info for C# Developers.
Visual Basic, a weakly typed language, can directly compare numbers against the constant name as shown in the above example. But developers using C#, a stronger typed language, (if they want to use constant name instead of numbers) will need to explicitly cast the constant name to a number value. For example:
if ( SComm1.CommEvent == (short) SCommLib.OnCommConstants.comEvReceive )
{
Textbox1.AppendText( SComm1.Input );
}
Notice the cast to (short). MSComm32 was written many years ago and the numeric constants inside MSComm, such as the CommEvent property, are 16bit integers. Our SComm64 is a new component and we could have used .Net int integer instead. But to maintain code compatibility with MSComm32 we decided to use the same short integer types as MSComm32.
|