Microsoft KB Archive/28149

= &quot;Device I/O Error&quot; Error 57 with OPEN COM1: ; Use ON ERROR GOTO =

Article ID: 28149

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 2.0
 * Microsoft QuickBasic 2.01
 * Microsoft QuickBasic 3.0
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b

-



This article was previously published under Q28149



SUMMARY
When using the COM1: or COM2: serial communications port, a &quot;Device I/O Error&quot; (Error 57) normally occurs due to parity, framing, or data overrun problems.

Sometimes, the &quot;Device I/O Error&quot; occurs in compiled QuickBasic programs more often than in the Microsoft GW-Basic Version 3.20 or other Basic interpreters, especially when the programs are compiled with any of the event-trapping options (/V or /W).

To alleviate this problem, trap the error 57 in an ON ERROR GOTO error-handler routine and RESUME execution of your program.

This information applies to QuickBasic Versions 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 and to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2.



MORE INFORMATION
The following should be checked when you get communication errors:

 Because a &quot;Device I/O Error&quot; normally occurs due to parity, framing, or data overrun problems, the following items must be checked:

 The communications cable should be checked for bad connections. The communications parameters specified in the OPEN &quot;COM&quot; statement must match the device and software on the other end of the communication line.  If the signal time per bit differs between transmitter and receiver, such as when the processor clocks are slightly off, you can get a &quot;framing error.&quot; Run tests on more than one computer system to see if the problem is a framing error specific to a given system. A &quot;Device I/O Error&quot; is also sometimes generated when there is information received prior to OPENing the file. The only control that you have is to trap the error with ON ERROR GOTO and then RESUME or RESUME NEXT. If a given program works successfully under the GW-Basic or IBM BasicA Interpreter, but not under QuickBasic (compiled as .EXE or in QB.EXE editor), the problem may be due to parity or framing differences between the products.</li></ol>

In the following code example, to simulate a full duplex-modem transmission, press CTRL+A and CTRL+B to send a 128-byte packet consisting of all 128 extended ASCII codes. If the people on each computer simultaneously press CTRL+A or CTRL+B, 128-byte packets are sent and verified on each end.

You need a null modem cable consisting of at least the following line connections:

2 - 3

3 - 2

7 - 7

Code Example
OPEN &quot;com1:9600,n,8,,cs0,ds0,cd0,BIN,rb16000&quot; FOR RANDOM AS #1 ON ERROR GOTO etrap CLS GOSUB helpme

myconst$ = &quot;&quot; FOR n = 128 TO 255     'set up a standard packet to send and receive myconst$ = myconst$ + CHR$(n) NEXT

capture = 0  'don't capture any data buff$ = &quot;&quot;   'set up buffer dummyvar = FRE(&quot;&quot;)

top: IF LOC(1) > 0 THEN i$ = INPUT$(1, #1) PRINT i$; IF i$ = CHR$(128) THEN capture = 1      'turn it on  IF capture = 1 THEN buff$ = buff$ + i$  IF i$ = CHR$(255) THEN capture = 0                           'turn it off GOSUB checkit END IF END IF

o$ = INKEY$ IF o$ <> &quot;&quot; THEN IF o$ = CHR$(1) THEN 'CTRL+A will send chars one at a time PRINT #1, &quot;&quot; FOR n = 128 TO 255 PRINT #1, CHR$(n); NEXT ELSEIF o$ = CHR$(2) THEN 'CTRL+B will send chars all at one PRINT #1, &quot;&quot; PRINT #1, myconst$; ELSEIF o$ = CHR$(3) THEN END ELSEIF o$ = CHR$(4) THEN PRINT : PRINT &quot;Performing garbage collection on String Heap...&quot;; dummyvar = FRE(&quot;&quot;) PRINT &quot;Done&quot;: PRINT ELSEIF o$ = CHR$(27) THEN GOSUB helpme ELSE PRINT #1, o$; PRINT o$; 'local echo END IF END IF

GOTO top

etrap: PRINT &quot;The error number is err #&quot;; ERR RESUME

checkit: IF myconst$ = buff$ THEN PRINT &quot;Packet Sent OK&quot; ELSE PRINT &quot;Error in Sending Packet&quot; END IF buff$ = &quot;&quot; RETURN

helpme: PRINT PRINT &quot;CTRL+A - Send a 128-byte Extended Ascii Packet one Byte at a time&quot; PRINT &quot;CTRL+B - Send a 128-byte Extended Ascii Packet all at once&quot; PRINT &quot;CTRL+C - End Program&quot; PRINT &quot;CTRL+D - Perform Garbage Collection on the String Heap&quot; PRINT &quot;ESC - Display this Help Message&quot; PRINT RETURN

Additional query words: QuickBas BasicCom

Keywords: KB28149

-

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

© Microsoft Corporation. All rights reserved.