168 of 307
ZBasic System Library 158 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. The supported channel numbers are 1-8 but not all devices support the entire range. Also, you must have previously called ComChannels() in order to use channels 4-6. The supported baud rates for Com1, Com2, Com7 and Com8 (channels 1, 2, 7 and 8) are the standard rates from 300 to 460,800 while the supported rates for Com3 to Com6 (channels 3-6) 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 queues specified for the receive and transmit channels 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. 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. Hardware UART Assignment ZX Model Com1 Com2 Com7 Com8 ZX-24, ZX40, ZX-44, ZX-24e USART0 - - - ZX-24a, ZX40a, ZX-44a, ZX-24ae USART0 - - - ZX-24p, ZX-40p, ZX-44p, ZX-24pe USART0 USART1 - - ZX-24n, ZX-40n, ZX-44n, ZX-24ne USART0 USART1 - - ZX-328n, ZX-328l, ZX-32n, ZX-32l, ZX-328nu USART0 - - - ZX-1281, ZX-1281n USART1 USART0 - - ZX-1280, ZX-1280n USART0 USART1 USART2 USART3 ZX-128e, ZX-128ne, ZX-1281e, ZX-1281ne USART0 USART1 - -