COM Statements Action Enable, disable, or suspend event trapping at the COM port. Syntax COM( n%) ON COM( n%) OFFn%) COM( n%) STOP Remarks The argument n% specifies the number of the COM (serial) port; n% can be either 1 or 2. COM( n%) ON enables communications-event trapping on COM port n%. If a character arrives at a communications port after a COM( n%) ON statement, the routine specified in the ON COM statement is executed. COM( n%) OFF disables communications-event trapping on COM port n%. No communications trapping takes place until another COM( n%) ON statement is executed. Events occurring while trapping is off are ignored. COM( n%) STOP suspends communications-event trapping on COM port n%. No trapping takes place until a COM( n%) ON statement is executed. Events occurring while trapping is suspended are remembered and processed when the next COM( n%) ON statement is executed. However, remembered events are lost if COM( n%) OFF is executed When a communications-event trap occurs (that is, the GOSUB operation is performed), an automatic COM( n%) STOP is executed so that recursive traps cannot take place. The RETURN statement from the trapping routine automatically executes a COM( n%) ON statement unless an explicit COM( n%) OFF was performed inside the routine. For more information, see Chapter 9, "Event Handling" in the Programmer's Guide. See Also ON event Example The following example opens COM1 and then monitors the COM1 port for input. It uses the ON COM statement to trap communications events. CLS ' Set up error handling in case COM1 doesn't exist. ON ERROR GOTO ErrHandler OPEN "COM1.9600,N,8,1,BIN" FOR INPUT AS #1 COM(1) ON ' Turn on COM event processing. ON COM(1) GOSUB Com1Handler' Set up COM event handling. ' Wait for a COM event to occur or a key to be pressed. DO . LOOP WHILE INKEY$ = "" COM(1) OFF' Turn off COM event handling. CLS END Com1Handler. PRINT A$; "Something was typed on the terminal attached to COM1." RETURN ErrHandler. SELECT CASE ERR CASE 68. PRINT "COM1 is unavailable on this computer.". END CASE ELSE. END END SELECT