Page 200 of 346 Start Back Next End ZBasic System Library 188 ZBasic Microcontrollers 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, 8, etc. (Com1, Com2, Com7, Com8, etc., respectively). All ZBasic 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. Tthe supported baud rates for software-based channels are listed in the table below. 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. Also, for ZX devices running at 7.37MHz, the maximum software-based channel baud rate is 9600. For generic target devices, the set of desired software-based channel baud rates must be explicitly specified as part of the device configuration and will be a subset of the rates in the table below; the baud rates that are attainable with a specified accuracy are dependent on the operating frequency. Supported Baud Rates for Channels 3-6 300 600 1200 2400 4800 9600 19200 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.