C++/using c++ to use parallel or serial port
how can we use c++/c to use parallel and serial ports??
are there any special classes defined for use of them or special programming
The answer depends on what operating system (if any) you are using.
You will often find parallel and serial ports can be opened like files, using the (system specific) device name instead of a file pathname (e.g. "LPT1", "COM2" etc. on a Windows system).
This means you can open and read/write to such devices just as you would a file: Using C++ (file) IOStream classes, using C fxxx functions (e.g. fopen) or using system specific API functions such as the Win32 function CreateFile et. al.
For further control you will have to use system-specific functionality such as the Win32 Comm functions (SetCommState etc.). or UN*X ioctl.
As to special classes - no not in the standard C++ library (C of course does not support classes).
As to special programming techniques - well there will be considerations because you are sending/receiving data through a device which - especially in the case of serial ports - can be quite slow. Hence handling data should be tackled with care - maybe having a queues of sent/received data from which bytes are sent/received in small chunks at regular intervals (if for example you are using a reactive system such as a GUI program) or on a separate thread.
There may be special steps needed to set up the device into the required mode (e.g. serial port bit rate, data bits, start and stop bits, parity etc.).
You may need to follow or define a specific protocol to initiate a connection with some other device or computer - depending on what you are trying to do. However these sorts of things are not just limited to serial / parallel port usage - you have to perform similar steps with for example setting up a network conversation using sockets.
Additional care will probably need to be taken in the face of error conditions (again, similar to network programming) as there are more ways for operations to fail - e.g. someone trips over the cable or turns off the device at the other end...
Note that in modern desktop and server operating systems you cannot access the hardware that supports the ports directly - the operating system controls such access through the use of device drives and a higher level set of application programming interfaces (usually sets of functions together with various types) like the Win32 functions mentioned above.
On the other hand if you are targeting small, embedded devices then maybe you can access the hardware directly - and how you do this depends on the hardware. Sometimes on such a system you would use C or C++ in an unhosted mode with very limited library support - so you would effectively have to supply functionality such as file and port access yourself (or someone else on the team will). Even with some OS support you may still prefer to access the hardware on such systems directly for the added degree of control it affords. If you are interested in these types of scenarios then you might be interested in a report by the ISO C++ standard committee on C++ performance which has sections on using C++ on embedded systems and a hardware addressing interface.
Other possible useful links are:
1/ There is an old MS technical article titled "Serial Communications in Win32" by Allen Denver from December 1995 which shows the basics of using serial ports with Win32. It uses the Win32 APIs throughout - so you will see CreateFile rather than fopen, or std::fstream for example. Try http://msdn.microsoft.com/en-us/library/ms810467.aspx
to read this article.
There is of course the standard reference documentation for all Microsoft development topics on the MSDN site at http://msdn2.microsoft.com/
, including specifically in the online copy of the MSDN library at http://msdn.microsoft.com/library/default.aspx
(links seem ok at time of writing but may vary over time...).
2/ For information on hardware port interfacing - with some background to doing so under MS Windows NT/2000/XP - try http://www.beyondlogic.org/
and specifically http://www.beyondlogic.org/porttalk/porttalk.htm
. This should give you more than enough information to be going on with although not specifically C/C++.
Hope this is of some help.