The text of a manual · part 16 of 19
PDT 3200 Run-Time Library Reference Manual: Chapter 3 Serial Communications, pages 137 to 144
Pages 137 to 144 of 168, from PDT 3200 Run-Time Library Reference Manual
The original document is the PDF (949 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Symbol PDT-3200
Page 137
Chapter 3 Serial Communications Chapter Contents PORT Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 SIO_AutoClose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 SIO_Close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 SIO_FileTransfer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10 SIO_FlushComm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 SIO_GetComm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13 SIO_GetCommError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 SIO_Keyflush . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 SIO_Keyhit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 SIO_Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 SIO_Read. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19 SIO_SetComm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 SIO_Ticks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21 SIO_Time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22 SIO_Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23
3-1
Page 138
PDT 3200 Run-Time Library Reference Manual
3-2
Page 139
Chapter 3: Serial Communications
This chapter describes the various serial communications function calls.
PORT Data Structure The Þrst step in accessing a serial port is to open the port by calling the SIO_Open() function. SIO_Open() returns a pointer to a PORT variable loaded with default values. Most of the serial communication functions use the PORT data structure described below.
PORT->baseaddr DOS base address for the communications port in question. For communications port 1 this is usually 3f8h, and for communications port 2 it is 2f8h.
PORT->portid Communications port number (COM1, COM2, etc.). Currently only communications ports 1 and 2 are supported by SIO. The numbering begins at 0 (i.e., the port ID of COM1 is 0, COM2 is 1, etc.). Use the following constant values when dealing with port numbers: SIO_COM1 SIO_COM2 communications port 1. communications port 2.
PORT->databits The number of data bits the communications port uses to transfer data. Use the following bit constants with SIO_SetComm() and SIO_GetComm() to set and read this parameter: SIO_FIVE_DATABITS SIO_SIX_DATABITS SIO_SEVEN_DATABITS SIO_EIGHT_DATABITS
Five data bits. Six data bits. Seven data bits. Eight data bits.
PORT->stopbits The number of stop bits the communications port uses to transfer data. Use the following constants with SIO_SetComm() and SIO_GetComm() to set and read this parameter: SIO_ONE_STOPBIT SIO_ONE5_STOPBITS
One stop bit. One and one-half stop bits. 3-3
Page 140
PDT 3200 Run-Time Library Reference Manual
SIO_TWO_STOPBITS
Two stop bits.
PORT->parity The parity the communications port uses to transfer data. The default is no parity. Use the following constants to assign parity values with SIO_SetComm(): SIO_NO_PARITY SIO_ODD_PARITY SIO_EVEN_PARITY SIO_MARK_PARITY SIO_SPACE_PARITY
No parity. Odd parity. Even parity. Mark parity (parity bit always on). Space parity (parity bit always off).
PORT->breakbit Status of the BREAK signal. This Þeld is TRUE if the communications port in question has asserted the BREAK signal. Otherwise, this bit is FALSE.
PORT->baudrate The baud rate the communications port uses to transfer data. Use the following constants with SIO_SetComm() and SIO_GetComm() to set and read this parameter. Note that the baud rate is stored as a long. SIO_BAUD_300 SIO_BAUD_1200 SIO_BAUD_2400 SIO_BAUD_4800 SIO_BAUD_9600 SIO_BAUD_19K SIO_BAUD_38K SIO_BAUD_56K SIO_BAUD_115K
300 baud. 1200 baud. 2400 baud. 4800 baud. 9600 baud. 19200 baud. 38400 baud. 57600 baud. 115200 baud.
PORT->DTR Status of the Data Terminal Ready (DTR) signal. This Þeld is TRUE if the communications port in question has asserted DTR. Otherwise, this bit is FALSE.
3-4
Page 141
Chapter 3: Serial Communications
PORT->RTS Status of the Ready To Send (RTS) signal. This Þeld is TRUE if the communications port in question has asserted the RTS signal. Otherwise, this bit is FALSE.
PORT->GPO1 Status of the General Purpose Output 1 (GPO1) signal. This Þeld is TRUE if the communications port in question has asserted the GPO1 signal. Otherwise, this bit is FALSE.
PORT->GPO2 Status of the General Purpose Output 2 (GPO2) signal. This Þeld is TRUE if the communications port in question has asserted the GPO2 signal. Otherwise, this bit is FALSE. Note that this bit acts as a master interrupt enable signal, and should not be modiÞed if using interrupts.
PORT->CTS Status of the Clear To Send (CTS) signal. This Þeld is TRUE if the CTS input signal is asserted for the communications port in question. Otherwise, this bit is FALSE.
PORT->DSR Status of the Data Set Ready (DSR) signal. This Þeld is TRUE if the DSR input signal is asserted for the communications port in question. Otherwise, this bit is FALSE.
PORT->RI Status of the Ring In (RI) signal. This Þeld is TRUE if the RI input signal is asserted for the communications port in question. Otherwise, this bit is FALSE.
PORT->DCD Status of the Data Carrier Detect (DCD) signal. This Þeld is TRUE if the DCD input signal is asserted for the communications port in question. Otherwise, this bit is FALSE.
PORT->protocol The Þle transfer protocol the communications port uses for SIO_FileTransfer() API calls. If a protocol routine is called directly, this parameter is ignored. Use the following constants to set and read this parameter: 3-5
Page 142
PDT 3200 Run-Time Library Reference Manual
SIO_PACKNAK SIO_XMODEM SIO_ASCIIDUMP
Symbol ACK/NAK protocol. Xmodem checksum or CRC protocol with 256 byte blocks. Outputs time-delayed ASCII packets.
PORT->commstatus The bits in this WORD describe the status of the communications port. Never write to this variable, as this makes its contents invalid. The following bit masks can be ANDed to PORT->commstatus in an if statement to ascertain the communications port status. The recommended method is to call SIO_GetCommError(), which returns commstatus and clears any pending errors. New characters came into the communications port before existing characters were read. Old characters were discarded. When interrupts are enabled, this means the read buffer is full. SIO_ERR_PARITY A parity error occurred on the communications port. SIO_ERR_FRAMING A framing error (start/stop bit) occurred. SIO_ERR_BREAK_DETECT A break signal was detected on the communications port. SIO_ERR_WRITEBUFFERFULL The write buffer is full. With interrupts off, this means the last character sent to the UART hasnÕt been dispatched. With interrupts on, it indicates the write buffer is full. SIO_ERR_READBUFFERFULL The read buffer is full. With interrupts off, this error should never occur. With interrupts on, it indicates the read buffer is full. SIO_ERR_OVERRUN
3-6
Page 143
Chapter 3: Serial Communications
PORT->interrupts The bits in this BYTE describe the state of interrupts for the communications port. Writing to this value has no effect on the actual state of the communications port interrupts. If a value is written to this variable, the existing status of the communications port is lost and must be accessed by directly checking the PIC and the UART in question. The following bit masks can be ANDed to PORT->interrupts in an if statement to identify which interrupts are active: SIO_INTR_NONE SIO_INTR_READ SIO_INTR_WRITE
No interrupts are active for this communications port. Read interrupts are active for this communications port. Write interrupts are active for this communications port.
PORT->ShowRx() A pointer to a user-deÞned function that displays Þle-receive progress to the user. This function provides a way to embed a progress indicator in the existing Þle transfer protocols. No method currently exists for communicating information (Þle size, number of bytes transferred, etc.) between the Þle-transfer routines and the user function. Generally, this routine is called in the Þle-transfer routine when one packet is successfully received.
PORT->ShowTx() A pointer to a user-deÞned function that displays Þle-transmit progress to the user. This function provides a way to embed a progress indicator in the existing Þle-transfer protocols. No method currently exists for communicating information (Þle size, number of bytes transferred, etc.) between the Þle-transfer routines and the user function. Generally, this routine is called in the Þle-transfer routine when one packet is successfully sent and acknowledged.
3-7
Page 144
PDT 3200 Run-Time Library Reference Manual
SIO_AutoClose sio.h Syntax void SIO_AutoClose (BOOL bEnable);
Description Enables or disables automatic closing of the communications port upon exit. By default, an open port is closed automatically when a program terminates, either by normal exit or by CTRL-BREAK. In the default case, SIO_Close() does not need to be called. If AutoClose is set to FALSE, SIO_Close() must be called prior to exiting the program. This function must be called prior to calling SIO_Open().
Parameters bEnable
Indicates whether to perform automatic close. TRUE closes the communications port upon exit. FALSE does not close the communications port on exit.
Returns None.
Sample See SIO_Open().
3-8