Difference between revisions of "LOC"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
imported>Clippy
Line 17: Line 17:
 
:OPEN "COM1: 9600,N,8,1," FOR RANDOM AS #1 LEN = 2048 'input and output
 
:OPEN "COM1: 9600,N,8,1," FOR RANDOM AS #1 LEN = 2048 'input and output
 
::DO: t$ = INKEY$ ' get any transmit keypresses from user
 
::DO: t$ = INKEY$ ' get any transmit keypresses from user
:::IF LEN(t$) THEN PRINT #1, t$ ' send byte to UART transmit buffer"
+
:::IF [[LEN]](t$) THEN PRINT #1, t$ ' send byte to UART transmit buffer"
 
:::IF LOC(1) THEN ' check UART receive buffer for data"
 
:::IF LOC(1) THEN ' check UART receive buffer for data"
 
::::r$ = INPUT$(1, 1)          ' get one byte from receive buffer"
 
::::r$ = INPUT$(1, 1)          ' get one byte from receive buffer"
::::IF LEN(r$) THEN PRINT r$; ' print characters consecutively"
+
::::PRINT r$; ' print characters consecutively to screen"
 
:::END IF     
 
:::END IF     
 
::LOOP UNTIL t$ = CHR$(27) ' Escape exit and CLOSE #1"
 
::LOOP UNTIL t$ = CHR$(27) ' Escape exit and CLOSE #1"
 +
 +
 +
''See also:'' [[PRINT]], [[PRINT (file statement)]]
  
  

Revision as of 03:32, 15 September 2009

The LOC function returns the status of a Serial(COM) port receive buffer.


Syntax: status% = LOC(open_number)


  • The parameter used is the number used in the port OPEN AS statement.
  • Returns 0 if the buffer is empty. Any value above 0 indicates COM has received data.
  • Use it in conjunction with INPUT$ to get the data bytes received.
  • Can also be used for the current position in a file routine. See: SEEK


Example: Reading and writing from a COM port opened in Basic.


OPEN "COM1: 9600,N,8,1," FOR RANDOM AS #1 LEN = 2048 'input and output
DO: t$ = INKEY$ ' get any transmit keypresses from user
IF LEN(t$) THEN PRINT #1, t$ ' send byte to UART transmit buffer"
IF LOC(1) THEN ' check UART receive buffer for data"
r$ = INPUT$(1, 1) ' get one byte from receive buffer"
PRINT r$; ' print characters consecutively to screen"
END IF
LOOP UNTIL t$ = CHR$(27) ' Escape exit and CLOSE #1"


See also: PRINT, PRINT (file statement)


Navigation:

Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage