Microsoft KB Archive/43746

= QuickBasic Program to Send a Break through COM1 Port =

Article ID: 43746

Article Last Modified on 11/21/2006

-

APPLIES TO


 * 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
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q43746



SUMMARY
Below is a Microsoft QuickBasic program that sends a Break through COM1 using the OUT statement. To cause a Break condition to be output on the communications line, the Line-Control Register must be read in, the Break bit set (bit number 6), and the register rewritten to the port. The Line-Control Register is an 8250 register at I/O port address 3FB hex. More information concerning the Line-Control Register and other 8250 registers can be found on Pages 177-181 in &quot;8088 Assembler Language Programming: The IBM PC,&quot; 2nd edition, by David C. Willen and Jeffrey I. Krantz (published by SAMS, 1988).



MORE INFORMATION
A simple outline of the program below is as follows:


 * 1) Get current Line-Control Register -- value% = INP(&H3FB)
 * 2) Set the Break bit, bit 6, 2^6= 64 -- value% = value% OR 64
 * 3) Rewrite Line-Control Register -- OUT &H3FB, value%

The following program executes correctly in Microsoft QuickBasic Compiler Versions 4.00, 4.00b, and 4.50, Microsoft Basic Compiler Versions 6.00 and 6.00b, and Microsoft Basic PDS Version 7.00: ' ' SETBREAK.BAS: ' ' This is a sample QuickBasic program that reads the Line-Control ' Register for the communications port (address &H3FB), sets the ' Break, and puts it back to the port. This causes a Break to be sent ' through the communications port. ' '

DECLARE SUB IntToBin (byte%, bin$) DECLARE SUB BreakWord (dataword%, highbyte%, lowbyte%) CLS

OPEN &quot;com1:9600,n,8,,CS0,DS0,CD0,RB8192,TB8192&quot; FOR RANDOM AS 1

LineContlReg1% = INP(&H3FB)                       'Get line control 'register

CALL BreakWord(LineContlReg1%, high1%, low1%) CALL IntToBin(LineContlReg1%, LCR1$) PRINT &quot;---BEFORE SETTING BREAK---&quot; PRINT &quot;Line-Control Register (LCR) : &quot;; LineContlReg1% PRINT &quot;LCR representation in binary: &quot;; LCR1$ PRINT

LineContlReg2% = LineContlReg1% OR 64             'Set Break -- 6th 'bit

CALL BreakWord(LineContlReg2%, high2%, low2%) CALL IntToBin(LineContlReg2%, LCR2$) PRINT &quot;---AFTER SETTING BREAK---&quot; PRINT &quot;Line-Control Register (LCR) : &quot;; LineContlReg2% PRINT &quot;LCR representation in binary: &quot;; LCR2$

OUT &H3FB, LineContlReg2%   'Reset the Line-Control Register to send 'a Break

END

'____________________________________________________________________ ' '    BreakWord takes an integer argument and returns two integers '    representing the high and low bytes of the original. '____________________________________________________________________ ' SUB BreakWord (dataword%, highbyte%, lowbyte%) IF dataword% < 0 THEN highbyte% = (dataword% + 2 ^ 16) \ 256  'check for high BIT 'set ELSE highbyte% = dataword% \ 256             'integer divide off 'low byte END IF

lowbyte% = dataword% AND 255               'AND off the top byte END SUB

'____________________________________________________________________ ' '   IntToBin takes an INTEGER argument and produces a '    binary string representation of the INTEGER. '____________________________________________________________________ ' SUB IntToBin (byte%, bin$) bin$ = &quot;&quot; temp% = byte%

FOR i = 0 TO 7 IF temp% AND 1 THEN bin$ = &quot;1&quot; + bin$ ELSE bin$ = &quot;0&quot; + bin$ END IF   temp% = temp% \ 2 NEXT

END SUB

Additional query words: QuickBas BasicCom

Keywords: KB43746

-

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

© Microsoft Corporation. All rights reserved.