Welcome to Keith’s RS232 library page

 

(This page was last updated on Thursday, October 15, 1998)

Important!!!!!

A small bug in the library was discovered by Elias Gil in my sendByte function. If you try to send more than one byte of data at the same time, data loss could happen. To fix the problem replace the sendByte function (in rs232.c) with the code below.

 

//////////////////////////////////////////////////////////////

//

//

//

//////////////////////////////////////////////////////////////

void sendByte(char *port, byte databyte)

{

//if the global uart is the same port ... (this will be

// for opening more than 1 port in future releases)

if( strncmp(port, (*globalUart).port, strlen(port)))

{

//wait until transmitting holding register empty.

// We can do nothing while waiting so NULL.

// was 0x04 (bit 2) which should have been !0x20 (bit 5)

// this was suggested by Elias Gil on 16 Aug 98

//***********************************

//Elias Gil

//Zapex Research (Israel) Ltd

//Tel: (972) 9 8658624

//Fax: (972) 9 8851112

//e-mail: gile@zapex.co.il

//***********************************

while( !(0x20 & INPORT((*globalUart).portid+LSR)) )

NULL;

 

//send the byte ...

OUTPORT((*globalUart).portid+TX, databyte);

}

else

{

printf("ERROR: %s: line %i:", __FILE__, __LINE__);

printf("ports must be equal\n");

exit(EXIT_FAILURE);

}

}

 

Introduction

The intent of this library is to make using the COM port under DOS, Windows 95, and Windows NT easy to use. Most of the information used to make this library was found online at http://www.senet.com.au/~cpeacock/. This page is by Craig Peacock and is very useful for interfacing to the PC. If you would like to find out more on how the serial port works please visit Craig’s page. 

I originally made this library for a school project I was working on and decided that other people might be interested in it. I already had some code I used a long time ago that used #define statements to change all of the setting such as baud rate and port (i.e. COM1). This got to be a pain to use, as you would have to figure out the new setting and recompile the code every time a small setting changed. It also didn’t save the current port setting (except interrupt vector) which is not a good idea. 

To use the serial port, you only need to use five functions. They are to open and close the COM port, see if data is available, and to send and receive a byte of data. There are other useful functions in the library such as detecting the UART chip you have and showing the status of all of the COM ports on your system.  

The files rs232.c and rs232.h are the library files (they contain all of the RS232 functions). The files freecomm.c and freecomm.h contain a sample program using the RS232 library. Please not that you need to declare the global structures that contain all of the port information as well as the receiver buffer. This is shown in http://www.ent.ohiou.edu/~welker/rs232/freecomm.h.

 

Compilers…

I use Borland C++ 3.1 for DOS to compile the RS232 library. I am in the process of getting the RS232 library to compile under Microsoft Visual C++ with the help of Jon Monroe. If you get it to compile under any other compiler or need help to do so email me.

 

Notes for Windows NT

This library has been tested under Windows NT 4.0 and it did work. You need to know which COM port(s) are open to use it properly. If you try and open a port that is in use a message will pop up that says (or similar for another port):

 

 

If this happens, you should terminate as the program will no longer work as intended. As long as you pick a port that is available, the code will work as if it was in DOS.

 

Downloading

Download the entire package in one zip file: http://www.ent.ohiou.edu/~welker/rs232/rs232.zip

(Last updated 10 October 1998)

 

View the project code revision and wish list: http://www.ent.ohiou.edu/~welker/rs232/rs232.txt

(Last updated 3 September 1998)

 

Please note that this document is still under development. Any comments or suggestions are appreciated. My email address is below.

 

Contact Information

 

Keith Welker

Keith.welker@iname.com (preferred)

Or keith.welker@usa.net

http://www.ent.ohiou.edu/~welker/rs232/ (This Document)

http://www.ent.ohiou.edu/~welker/index.cgi (My homepage)