174 of 318
ZBasic System Library 164 ZX Microcontroller Family OpenCom Type Subroutine Invocation OpenCom(channel, baud, inQueue, outQueue) Parameter Method Type Description channel ByVal Byte The serial channel to open. baud ByVal Long The desired baud rate. inQueue ByRef array of Byte The queue for incoming characters. outQueue ByRef array of Byte The queue for outgoing characters. Discussion This subroutine prepares a serial channel for use. If the specified channel number is invalid, the call has no effect. Serial channels are either implemented in hardware (using an onboard UART) or in software. Depending on the device one, two or four hardware-based serial channels are supported, denoted by the channel numbers 1, 2, 7 and 8 (Com1, Com2, Com7 and Com8, respectively). All ZX devices can support as many as four software-based serial channels, denoted by the channel numbers 3-6 (Com3, Com4, Com5 and Com6). Note, however, that you must have previously called ComChannels() in order to use channels 4-6. The supported baud rates for the hardware-based channels are the standard rates from 300 to 460,800 while the supported rates for software-based channels range from 300 to 19,200. However, if ComChannels() has been invoked, the maximum rate for channels 3-6 will be limited to that specified in the description of ComChannels(). Moreover, for channels 3-6 the baud rate for any given channel must be an integral divisor of the maximum rate. The transmit and receive queues specified for the channel each must have been previously initialized by calling OpenQueue(). If you set up a transmit-only or receive-only serial channel you may use the value 0 for the unused queue. If you provide the value 0 for both queues, the channel will not be opened. After opening the channel, flow control may be configured for either the transmit side, the receive side or both. See the description of the ControlCom() subroutine for more information. Example Dim outQueue(1 to 40) as Byte Call OpenQueue(outQueue, SizeOf(outQueue)) Call ComChannels(2, 9600) Call DefineCom(4, 0, 12, &H08) Call OpenCom(4, 9600, 0, outQueue) The code above prepares Com4 as a transmit-only serial channel. If you wanted reception as well, you would have to declare and initialize a second queue and define the receive pin. Resource Usage The hardware UARTs are assigned to channel numbers as shown in the table below.