4-13
Return value: unsigned char value
This function returns the current byte from sn_in_buf, and increments the in_tail pointer. Once again, this
function assumes that serhitn has been called, and that there is a character present in the buffer.
getsersn
Arguments: COM c, int len, char* str
Return value: int value
This function fills the character buffer str with at most len bytes from the input buffer. It also stops
retrieving data from the buffer if a carriage return (ASCII: 0x0d) is retrieved.
This function makes repeated calls to getser, and will block until len bytes are retrieved. The return value
indicates the number of bytes that were placed into the buffer.
Be careful when you are using this function. The returned character string is actually a byte array
terminated by a null character. This means that there might actually be multiple null characters in the byte
array, and the returned value is the only definite indicator of the number of bytes read. Normally, we
suggest that the getsers and putsers functions only be used with ASCII character strings. If you are working
with byte arrays, the single-byte versions of these functions are probably more appropriate.
Miscellaneous Serial Communication Functions
One thing to be aware of in both transmission and receiving of data through the serial port is that TERN
drivers only use the basic serial-port communication lines for transmitting and receiving data. Hardware
flow control in the form of CTS (Clear-To-Send) and RTS (Ready-To-Send) is not implemented. There
are, however, functions available that allow you to check and set the value of these I/O pins appropriately
for whatever form of flow control you wish to implement. Before using these functions, you should once
again be aware that the peripheral pin function you are using might not be selected as needed. For details,
please refer to the NEC V25 User’s Manual.
char sn_cts(void)
Retrieves value of CTS pin.
void sn_rts(char b)
Sets the value of RTS to b.
Completing Serial Communications
After completing your serial communications, there are a few functions that can be used to reset default
system resources.
sn_close
Arguments: COM *c
Return value: none
This closes down the serial port, by shutting down the hardware as well as disabling the interrupt.
clean_sern
Arguments: COM *c
Return value: none
This flushes the input buffer by resetting the tail and header buffer pointers.