![]() |
<< Index >> |
FutureBasic |
open "C" | statement | |
|
This statement opens a serial communications port (the modem port or the printer port) so that your program can write to or read from a serial device. The optimal values for the various parameters depend on the device and the desired communications protocol; see the device's manual for more information. The parameters are interpreted as follows:
Set this either to
Set this to one of the following values: 110; 300; 1200; 1800; 2400; 3600; 4800; 7200; 9600; 19200; 38400; 57600, 115200, 230400.
Set this to one of the following values:
Set this to one of the following values:
Set this to one of the following values:
Set this to a number in the range 1 through 32,768. This parameter indicates how many bytes to allocate for an input buffer. The input buffer stores data that is being received, even when the program is not reading it, allowing the program to process data while data is being received in the background. The default value for (portID,1)
.
Reading Data
To read incoming data from an open serial port, use the same commands that you would use to read data from a file; e.g.,
There are basically three ways to check whether there is any data available in the buffer:
(portID,1)
. This will return zero if no data is available to read; otherwise, it returns the number of bytes waiting to be read.
read# portID,stringVar$;0
statement. By specifying ";0
", you instruct the read#
statement to return immediately if there is no data available; if there is data, the statement reads all the characters currently in the input buffer (up to the maximum allowable length of len(stringVar$)
after the (portID )
function. It will either return one character from the buffer, or a null string if the buffer was empty.
gFBHasComTB% //true if comm toolbox is used...
gFBSerialPortCount% //number of com port
gFBSerialName$(n) //serial port name
gFBSerialInName$(n) //input buffer name
gFBSerialOutName$(n) //output buffe name
gOSXSerialInited //[!]0 if serial inited under MacOS X
fn FBInitSerialPorts
, you may refer to gFBSerialPortCount%
for the total number of devices (maximum 8). gFBSerialOutName$(n)
contains the name of the device. With this in mind, the serial ports can best be referred to by name rather than number when multiple ports are present or when USB devices are in use for the purpose of emulating serial ports.fn FBInitSerialPorts
, subsequent calls may be needed to refresh the list after devices are removed/added. gFBSerialportCount%
must be set to zero prior to any subsequent calls to fn FBInitSerialPorts
.
gFBSerialportCount% = 0
// This is for MacOS X
if system (_sysVers) => 1000
gOSXSerialInited =
_false
end if
See also
close; HandShake; loc; lof; input#; read#; read file; print#; write; write file