Jump to navigation Jump to search
Revision as of 06:38, 4 October 2009 by
The OPEN COM statement is used to access a comuter's Serial port COM1 or COM2 address using an OPEN statement.
- Syntax: OPEN "COMn: Speed, Parity, Bits, Stopbit, Options" FOR mode AS #f LEN = bytesize
- COM can only be 1 or 2 as OPEN cannot open other COM port numbers.(See Windows System Components list)
- Four commas are required after the Speed, Parity, Bits, and Stopbit, even if no other Options are used.
- Speed(baud rate): 75, 110, 150, 300, 600, 1200, 1800, 2400 or 9600 maximum.
- Parity: N (none), E (even), O (odd), S (space) or M (mark). Note: If 8 bits use parity N for numerical data!
- Bits = number of bits/byte: Valid numbers: 5, 6, 7 or 8
- Stopbit = number of stop bits: Valid numbers: 1, 1.5 or 2
- Other OPEN options are optional and in any order separated by commas within the OPEN STRING command.
- Additional Options
- * ASC : ASCII byte mode. End of line = CHR$(13). End of file = CHR$(26)
- * BIN : Binary byte mode. Default mode if ASC is not used(option not required).
- Below m is the timeout in milliseconds 1 to 65535. 0 is ignore timeout. Default m = 1000 :
- CDm : Time until timeout of DCD (Carrier Detect) line in. CD0 ignores timeouts.
- CSm : Time until timeout of CTS (Clear to Send) line in. CS0 ignores timeouts.
- DSm : Time until timeout of DSR (Data Set Ready) line in. DS0 ignores timeouts.
- OPm : Time until data lines become active. If timeout then OPEN fails! OP0 ignores timeouts.
- If any timeouts occur the OPEN will fail or port access will stop!
- RBs : Size of receive buffer when used. Default when not used = 512 bytes
- TBs : Size of transmit buffer when used. Default when not used = 512 bytes
- RS : Supress detection of RTS (Ready to Send) line. No timeout.
- INPUT mode can use INPUT # or INPUT$. OUTPUT mode can use PRINT # or PRINT #, USING.
- RANDOM or BINARY modes can use INPUT #, INPUT$, PRINT #, GET or PUT. Binary cannot set the buffer size!
- Note: If random use LEN = to set size of random buffer(default LEN = 128). Use multiples of 128 for larger buffers.
- OPEN AS number can use a FREEFILE value. Numbers used by files already open cannot be used by the OPEN COM statement!
- NOTE: NT or XP computers need a program like PortTalk to access COM or other ports!
Example: Opening COM port 1 with the OP0 no line timeout option and setting the buffer sizes using LEN =.
- OPEN "COM1: 9600, N, 8, 1, OP0" FOR RANDOM AS #1 LEN = 2048 ' input and output buffersize