Page 85 of 346 Start Back Next End ZBasic System Library 73 ZBasic Microcontrollers ComChannels Type Subroutine Invocation ComChannels(chanCount, maxSpeed) Parameter Method Type Description chanCount ByVal Byte The total desired number of software-based serial channels. maxSpeed ByVal int8/16 The desired maximum baud rate to be supported. Discussion In addition to the serial channels implemented in hardware on the processor (e.g. Com1), ZBasic can support up to four additional serial communication channels that are implemented in the system software. The software-based serial channels are numbered Com3 through Com6. However, by default, only one additional channel, Com3, is supported. If you want to use serial channels 4 through 6 you must call this subroutine first to specify the maximum number (generally, up to 4) that you want to have available. This subroutine must be called only when there are no open software-based serial channels (COM3 through COM6). If it is called when one or more channels are already open, it will have no effect. For native mode devices, the upper limit of the chanCount parameter may be lower than 4 if the Option ComChannels directive is used. If the value of chanCount exceeds the upper limit the call will fail silently. After ComChannels() has been invoked, the serial channels that will be available depends on the value specified by the chanCount parameter. If the value 2 is specified, for example, channels Com3 and Com4 will be available. Once the number of software-based serial channels has been established you may then use DefineCom(), OpenCom(), and CloseCom() to manage the available channels by specifying the appropriate channel number in those calls. In addition to specifying the total number of software-based serial channels that you want, you must also specify the maximum baud rate that you wish to utilize. The supported rates are 300, 600, 1200, 2400, 4800, 9600 and 19,200 baud but see below for additional discussion about the maximum baud. Because the COM3 to COM6 serial channels are implemented in software, when one or more of the channels is open there will be a certain amount of processing overhead that will reduce the speed at which program instructions will be executed. Moreover, the processing overhead is higher when supporting higher baud rates as compared to lower baud rates and the overhead is higher when supporting a larger number of channels. It is prudent, therefore, to choose the lowest baud rate and lowest number of channels that is practical for your application. Also note that when supporting two or more channels, there is a small possibility that incoming characters might not be properly recognized at the highest rate. The probability of not being able to properly synchronize on the incoming character’s start bit increases with each additional channel that is supported. For this reason, it is recommended that the maximum baud rate be limited to 9600 when configured for 2 or more channels. For devices operating at speeds between 7.37MHz and 14.7456MHz, the number of software- implemented serial channels should be limited to two and the maximum speed should be limited to 9600 baud. At slower speeds, further reductions in the channel use and maximum speed may be necessary. Resource Usage The software-implemented serial channels utilize the Serial Timer for the bit rate timing. No other use of the Serial Timer should be attempted when serial channels 3-6 are open. The “Busy” flag for the timer used to implement the software serial channels will be set to True when one or more of the software- implemented serial channels is open.