QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The LOC function returns the status of a serial (COM) port received buffer or the current byte position in an open file.

Syntax

bytes% = LOC(fileOrPortNumber%)

Example(s)

Reading and writing from a COM port opened in Basic.


OPEN "COM1: 9600,N,8,1,OP0" FOR RANDOM AS #1 LEN = 2048 ' random mode = input and output
  DO: t$ = INKEY$ ' get any transmit keypresses from user
    IF LEN(t$) THEN PRINT #1, t$ ' send keyboard byte to transmit buffer
    bytes% = LOC(1) ' bytes in buffer
    IF bytes% THEN ' check receive buffer for data"
      r$ = INPUT$(bytes%, 1)          ' get bytes in the receive buffer
      PRINT r$; ' print byte strings consecutively to screen"
    END IF    
  LOOP UNTIL t$ = CHR$(27) 'escape key exit
CLOSE # 

See Also