Liberty BASIC Help Online

OPEN "COMn:..."
OPEN "COMn:baud,parity,data stop{,options}" for random as #handle
The OPEN "COMn:" statement opens a serial communications port for reading and writing.  This feature uses Microsoft Windows' own built-in communications API, so if you have a multiport communications card and a WIndows driver to support that card, you should be able to use any port on the card.
The simplest form for this command is:
    OPEN "COMn:baud,parity,data,stop" for random as #handle
Allowable choices for baud are:
    75 110 150 300 600 1200 2400 1800 2400 4800 9600 19200 38400 57600 115200
Allowable choices are parity are:
    NNo parity
    EEven parity
    OOdd parity
    SSpace parity
    MMark parity
Allowable choices for data are:
    5bits long
    6bits long
    7bits long
    8bits long
Allowable choices for stop are:
    1stop bit
    2stop bits
Additional optional parameters can be included after the baud, parity, data and stop information:
    CSnSet CTS timeout in milliseconds (default 1000 milliseconds)
    DSnSet DSR timeout in milliseconds (default 1000 milliseconds)
    PEEnable parity checking
    RSDisable detection of RTS (request to send)
Other defaults:
    DTR detection is disabled
    XON/XOFF is disabled
    binary mode is the default
To set the in and out communications buffers (each port has its own), set the variable Com (notice the uppercase C) to the desired size before opening the port.  Changing the variable after opening a port does not affect the size of the buffers for that port while it is open.
    'set the size of the communications buffers
    '(in and out) to 16K each
    Com = 16384
Usage Notes:
To open com port 2 at 9600 baud, 8 data bits, 1 stop bit, and no parity, use this line of code:
    open "com2:9600,n,8,1" for random as #commHandle
It is recommended that you set the the timeout on the DSR line to 0 so that your program doesn't just freeze when waiting for data to come in.  To do this, we can add a ds0 (for DSR 0 timeout) as below.  Notice we use a different communications speed in this example.
    open "com2:19200,n,8,1,ds0" for random as #commHandle
Remember that when a modem dials and connects to another modem, it negotiates a cpnnectopm speed.  In the case of 14400 speed modems, you need to specify 19200 as the connection speed and let the modems work it out between themselves during the connect.  This is because 14400 is not a baud rate supported by Windows (and you'll find that QBASIC doesn't directly support 14400 baud either).
Once the port is open, sending data is accomplished by printing to the port (ATZ resets modems that understand the Hayes command set):
    print #commHandle, "ATZ"
To read from the port you should first check to see if there is anything to read.  This is accomplished in this fashion:
    numBytes = lof(#commHandle)
Then read the data using the input$() function.
    dataRead$ = input$(#commHandle, numBytes)
Putting the lof( ) and input$( ) functions together on one line, it looks like this:
    dataRead$ = input$(#commHandle, lof(#commHandle))
When you're all done, close the port:
    close #commHandle
Liberty BASIC 3 has added the ability to disable DSR checking by specifying a zero or non value using the DS switch:&n