Main Page   Compound List   File List   Compound Members   File Members  

serapi.c File Reference

Serial API - implementation. More...

#include "serapi_t.h"
#include "serapi.h"
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

Go to the source code of this file.

Functions

unsigned int initSerial (int port)
 This function inits the serial port. More...

void deinitSerial (int port)
 After work done call this function. More...

void setParam (int port, unsigned long baudrate, unsigned int databits, char parity, unsigned int stopbits, unsigned int flowCtrl)
 This funtion sets important parameters like baudrate and so on. More...

void enableRS485 (int port, unsigned int activityMode)
 This funtion enables the RS485 mode. More...

byte blockedSend (int port, byte b)
 Puts a byte into the output buffer. More...

bool unblockedSend (int port, byte b)
 Place a byte in the output buffer if there is room. More...

unsigned int sendBlock (int port, byte far *dataBlock, unsigned int length)
 This function writes a block of data to the serial port buffer. More...

byte blockedReceive (int port)
 Reads a byte from the receiver buffer. More...

byte unblockedReceive (int port)
 Returns the next byte available in the receive buffer, without removing it from the buffer. More...

bool byteAvail ()
 Returns true if the unblockedReceive function determined that there's a byte. More...

unsigned int receiveBlock (int port, byte far *dataBlock, unsigned int length)
 Read up to a maximum number of bytes from the serial port. More...

void flushOutBuffer (int port)
 Wait for all output in the output buffer to be transmitted. More...

void deleteOutBuffer (int port)
 Remove all data from the output buffer. More...

void deleteInBuffer (int port)
 Remove all data from the receive buffer. More...

statusPtr getStatus (int port, byte statByte)
 Returns the status of the seril port. More...


Variables

statusPtr statusp = &status


Detailed Description

Serial API - implementation.

Author:
Christian Decker (cdecker@teco.edu)

Development System: Turbo C++ 3.0

Licence: GPL

This API was developed for easy handling the Fossil functions of the SC12 by Beck GmbH. The code was inspired from a snippet which I found in the examples delivered with the original API descriptions from Beck.

This API contains functions for initializing and deinitializing a serial port. Furthermore there are functions for setting parameters of the interface like baudrate, parity etc. and for sending and receiving bytes or whole data blocks.

For all macros used here look at serapi_t.h.

See also:
http://www.beck-ip.com/ , http://www.teco.edu/~cdecker/ , cdecker@teco.edu

Definition in file serapi.c.


Function Documentation

byte blockedReceive ( int port )
 

Reads a byte from the receiver buffer.

Wait for a byte to arrive if none is available.

Parameters:
port   is one of COM or EXT
Returns:
returns the byte received

Definition at line 238 of file serapi.c.

byte blockedSend ( int port,
byte b )
 

Puts a byte into the output buffer.

If there's room in the output buffer then the functions returns to the caller. Otherwise it waits for room. This can be dangerous when used in combination with flow control.

Parameters:
port   is one of COM or EXT
b   is the byte to send
Returns:
the function returns status code
See also:
getStatus for further work with the status codes

Definition at line 190 of file serapi.c.

bool byteAvail ( )
 

Returns true if the unblockedReceive function determined that there's a byte.

Attention: You shouldn't use this function for testing whether there's a byte. For this use the

See also:
getStatus(...)
Returns:
returns true if unblockedReceive(...) function determined that there's a byte
See also:
unblockedReceive to determine whether there's a byte

Definition at line 270 of file serapi.c.

void deinitSerial ( int port )
 

After work done call this function.

Parameters:
port   is one of COM or EXT

Definition at line 64 of file serapi.c.

void deleteInBuffer ( int port )
 

Remove all data from the receive buffer.

Parameters:
port   is one of COM or EXT

Definition at line 316 of file serapi.c.

void deleteOutBuffer ( int port )
 

Remove all data from the output buffer.

Parameters:
port   is one of COM or EXT

Definition at line 305 of file serapi.c.

void enableRS485 ( int port,
unsigned int activityMode )
 

This funtion enables the RS485 mode.

Parameters:
port   is one of COM or EXT
activityMode   is one of TX_ENABLE_LOW or TX_ENABLE_HIGH

Definition at line 177 of file serapi.c.

void flushOutBuffer ( int port )
 

Wait for all output in the output buffer to be transmitted.

Parameters:
port   is one of COM or EXT

Definition at line 294 of file serapi.c.

statusPtr getStatus ( int port,
byte statByte )
 

Returns the status of the seril port.

If no statByte is given (statByte == NO_STATUS) the functions fills the status struct with the actual values getting from the serial port. If a statByte is given the functions ignores the serial port and fills the status struct with the values computing from the statByte.

Parameters:
port   is one of COM or EXT
statByte   is an given status byte (use NO_STATUS if you don't want to use a given status byte)
Returns:
returns a pointer to the struct containing the status
See also:
statusStr

Definition at line 327 of file serapi.c.

unsigned int initSerial ( int port )
 

This function inits the serial port.

You must call this function first, if you want to work with one of the ports.

Parameters:
port   is be one of COM or EXT
Returns:
returns 0x1954 if success

Definition at line 51 of file serapi.c.

unsigned int receiveBlock ( int port,
byte far * dataBlock,
unsigned int length )
 

Read up to a maximum number of bytes from the serial port.

This is an unblocking read.

Parameters:
port   is one of COM or EXT
dataBlock   is a far pointer to a dataBlock of bytes
length   maximum number of bytes to transfer
Returns:
number of bytes transfered.

Definition at line 279 of file serapi.c.

unsigned int sendBlock ( int port,
byte far * dataBlock,
unsigned int length )
 

This function writes a block of data to the serial port buffer.

It's unknown whether this is blocking or unblocking.

Parameters:
port   is one of COM or EXT
dataBlock   is a far pointer to a dataBlock of bytes
length   maximum number of bytes to transfer
Returns:
number of bytes actually transfered

Definition at line 222 of file serapi.c.

void setParam ( int port,
unsigned long baudrate,
unsigned int databits,
char parity,
unsigned int stopbits,
unsigned int flowCtrl )
 

This funtion sets important parameters like baudrate and so on.

Parameters:
port   is one of COM or EXT
baudrate   is one of 300, 600, 1200, 2400, 4800, 9600, 19200, 28800, 38400, 57600, 115200
databits   is one of 7 or 8
parity   is one of N(one), O(dd), E(ven)
stopbits   is one of 1 or 2 (only if no parity is set)
flowCtrl   is one of TRANSMIT_XONXOFF,RECEIVE_XONXOFF,RTSCTS or NO_FLOWCTRL(default)

Note:

If no valid baudrate is given, then 2400 is assumed. If no valid databits are given, then 8 databits are assumed. If no valid parity is given, then no parity is assumed. If no valid stopit is given, then one stopbit is assumed.

Definition at line 75 of file serapi.c.

byte unblockedReceive ( int port )
 

Returns the next byte available in the receive buffer, without removing it from the buffer.

After calling this function you have to call the byteAvail function to test if the returned byte is really the byte.

Parameters:
port   is one of COM or EXT
Returns:
the received byte if the byteAvail() function returns true.
See also:
byteAvail for whether there is a byte available or not

Definition at line 250 of file serapi.c.

bool unblockedSend ( int port,
byte b )
 

Place a byte in the output buffer if there is room.

Do not wait for the byte actually being transmitted.

Parameters:
port   is one of COM or EXT
b   is the byte to send
Returns:
not equal 0 if byte was placed in the buffer or 0 if byte was not accepted

Definition at line 204 of file serapi.c.


Variable Documentation

statusPtr statusp = &status
 

Definition at line 41 of file serapi.c.


Generated at Fri Oct 26 12:43:45 2001 for SerialAPI by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001