You are here:

C++/Accessing a RS232 port via C/C++


I'm trying to send information over a RS232
serial port via a C/C++ program but can't seem
to find any libraries that work. I've tried
including both dos.h and bios.h but the compiler
didn't like either. What library should I be
using and where can I find it? I'm on a SuSE
Linux machine if that helps.

Thanks so much in advance,

So, you are trying to use MS-DOS/PC-DOS specific feature (as indicated by your use of dos.h and bios.h) with a UN*X style operating system. Now that I have mentioned this fact (which presumably you were not aware of - that certain features supplied with development systems are vendor specific or at least platform specific) does it explain why your approach fails?

The answer is to use the RS232 device names as defined for your Linux system - these will be in the /dev directory such as /dev/ttyS0 (the exact name will depend on your version of Linux and the type of the serial port).

Under UN*X style OSes such as Linux you can open, read and write to devices as you can files (in fact you can do this with MS operating systems as well). For lower level control you use the ioctrl system function and the termios functions (these are specifically for asynchronous communication devices) - you can look these up using the man utility on your Linux system:

      man termios

You might also like to read the man p age on the setserial utility.

I suggest you also read the Linux serial port and programming HOWTO documents (should be available with the SuSE distribution and online) and then search the internet for further information if this does not suffice as you have given no indication as to what you whish to do with your serial port. Note all available Linux HOWTOs are listed online at, other Linux documentation can be accessed through the Linux Documentation Project homepage at  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2017 All rights reserved.