Microsoft KB Archive/67315

= How to Use CALL INTERRUPT to Diagnose COM &quot;Device I/O&quot; Error =

Article ID: 67315

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q67315



SUMMARY
This article contains a code example showing how to obtain and decode the information contained within the communications line-status and modem-control registers. The contents of the registers is found by calling ROM BIOS Interrupt 14h, with function 3. This information is helpful in pinpointing the cause of communications port (COM1 or COM2), errors such as &quot;Device I/O&quot; errors.

The information in this article is also included in the Help file provided with the Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0.



MORE INFORMATION
Calling ROM BIOS Interrupt 14h with function 3h is helpful in finding whether a &quot;Device I/O&quot; error stems from problems such as break, framing, or overrun problems during communications. If you are trying to pinpoint the underlying cause of a communications error, you should call the interrupt from within an ON ERROR GOTO handler in your Basic program. The code sample below demonstrates how the communications port status can be checked when a &quot;Device I/O&quot; error is generated.

For more information on how to overcome communications-related errors, query on the following words in the Knowledge Base:

Device I/O and solve and common and communications and port and problems

Information on ROM BIOS Interrupt 14h with function 3h can be found in the following books:

&quot;The New Peter Norton Programmer's Guide to the IBM PC & PS/2; the Ultimate Reference Guide to the Entire Family of IBM Personal Computers&quot; by Peter Norton and Richard Wilton, published by Microsoft Press (1985). See page 230.

&quot;The Programmer's PC Sourcebook&quot; by Thom Hogan, published by Microsoft Press (1988). See page 220.

Code Example
To try this example in VBDOS.EXE:


 * 1) From the File menu, choose New Project.
 * 2) Copy the code example to the Code window.
 * 3) Press F5 to run the program.

To run this program in the VBDOS.EXE environment, you must invoke the VBDOS.EXE environment with the /L switch to load the default Quick library:

VBDOS.EXE /L (for Visual Basic for MS-DOS)

To run the following sample program in the QB.EXE or QBX.EXE environment, the quick library QB.QLB (or QBX.QLB, if using Basic PDS for MS-DOS) must be loaded as follows:

QB /L QB.QLB (The MS-DOS command line if using QuickBasic)

QBX /L QBX.QLB (The MS-DOS command line if using Basic PDS)

To make an .EXE file from MS-DOS, the compiled program must be linked with the library QB.LIB (or QBX.LIB, if using Basic PDS). ' Use the following include file for Visual Basic for MS-DOS: REM $INCLUDE: 'VBDOS.BI' ' Use the following include file for QuickBasic for MS-DOS: REM $INCLUDE: 'qb.bi' ' Use the following include file for Basic PDS for MS-DOS: REM $INCLUDE: 'qbx.bi'

DECLARE SUB GetPortStatus (MessageCount%) DIM SHARED InRegs AS RegType, OutRegs AS RegType DIM SHARED StatusMessage(15) AS STRING * 35 CLS ON ERROR GOTO ErrorHandler: ERROR 57     ' This statement forces a &quot;Device I/O&quot; error.

' The following code (REMARKed out) is a sample routine that reads ' communications port input. Remove the ERROR 57 line above and the ' REMARKs in this section of code to run the sample when data is being ' sent from another device to COM1. It is unlikely that the following ' code segment will generate a &quot;Device I/O&quot; error. The code is merely ' included as an indication of where the communications routine is ' located relative to the rest of the code. It is recommended that you ' replace the following code segment with your own communications ' routine, especially if your code leads to &quot;Device I/O&quot; or other ' communications related errors.

' OPEN &quot;COM1:300,N,8,1,BIN,CD0,CS0,DS0,OP0,RS,TB2048,RB2048&quot; FOR _ RANDOM AS #1

' WHILE LOC(1)=0 ' WEND

' WHILE NOT EOF(1) '   a$ = INPUT$(LOC(1),1) ' WEND

Done: ' CLOSE #1 END

ErrorHandler: IF ERR = 57 THEN CALLGetPortStatus(LastMessage%) FOR i% = 0 TO LastMessage% - 1 PRINT StatusMessage(i%) NEXT i%  END IF   RESUME Done:

REM $STATIC SUB GetPortStatus (MessageCount%) MessageCount% = 0 InRegs.AX = &H300  ' Load the service number 3h in the ' high byte of AX. ' Call ROM BIOS Interrupt 14h. CALL Interrupt(&H14, InRegs, OutRegs)

' Decode the upper 8 bits of AX containing line-status ' register information:

IF OutRegs.AX AND 2 ^ 8 THEN StatusMessage(MessageCount%) = &quot;Data ready&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 9 THEN StatusMessage(MessageCount%) = &quot;Overrun error&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 10 THEN StatusMessage(MessageCount%) = &quot;Parity error&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 11 THEN StatusMessage(MessageCount%) = &quot;Framing error&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 12 THEN StatusMessage(MessageCount%) = &quot;Break-detect error&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 13 THEN StatusMessage(MessageCount%) = _ &quot;Transfer holding register empty&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 14 THEN StatusMessage(MessageCount%) = &quot;Transfer shift register empty&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 15 THEN StatusMessage(MessageCount%) = &quot;Time-out error&quot; MessageCount% = MessageCount% + 1 END IF

' Decode the lower 8 bits of the AX register containing ' modem-status information:

IF OutRegs.AX AND 2 ^ 0 THEN StatusMessage(MessageCount%) = &quot;Delta clear-to-send&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 1 THEN StatusMessage(MessageCount%) = &quot;Delta data-set-ready&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 2 THEN StatusMessage(MessageCount%) = &quot;Trailing-edge ring detector&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 3 THEN StatusMessage(MessageCount%) = _ &quot;Delta receive line signal detect&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 4 THEN StatusMessage(MessageCount%) = &quot;Clear-to-send&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 5 THEN StatusMessage(MessageCount%) = &quot;Data-set-ready&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 6 THEN StatusMessage(MessageCount%) = &quot;Ring indicator&quot; MessageCount% = MessageCount% + 1 END IF  IF OutRegs.AX AND 2 ^ 7 THEN StatusMessage(MessageCount%) = &quot;Received line signal detect&quot; MessageCount% = MessageCount% + 1 END IF END SUB

Additional query words: VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 7.00 7.10 serial

Keywords: KB67315

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.