You are here:

C++/Device Programming

Advertisement


Question
What additional skill and devices are required for activating any electronic devices with the help of c++ programming.
Please give me a programming example and concept ,atleast for swithching On/Off an electronic bulb with the help of programming language.

I will be highly obliged.

Answer
Note this is no longer an area of my expertise - I have not looked into this sort of thing for about 10 years. I also am _not_ going to develop any software for you for free or without more concrete information on the device setup. Anyhow here are some pointers:

There is _no_ direct support for controlling I/O devices in C++. Normally you rely on the services of other functions of the operating system, system monitor or software development kit (SDK) provided for the device for use on the platform in question.

How you would go about doing such a thing also depends on the programming model of the I/O device you need to talk to.

The most obvious method of turning a bulb on and off is to change the state of a bit representing the state of an output line in the I/O device in question. Generally such devices have a low voltage and current output so even turning on and off a LED will require some power electronics (a couple of resistors and a small general purpose transistor such as a BC109).  Alternatively you could purchase some sort of industrial I/O board.

What options are available depend on the system in question. PCs for example have PC style I/O - serial, parallel, PS/2, USB, Firewire, IDE, Ethernet etc, as well as PCI slots for boards. Your best bet is probably to purchase a separate I/O board or device and hope that it comes with drivers and SDK for your operating system (you can of course check this in the product description). Of course if you are good at electronics then maybe you can concoct a simple device to work with a serial or parallel port. For example you could use one of a serial ports handshaking lines as your digital output then use the serial I/O support APIs in your operating system to change the state of this line - see for example the Win32 API function EscapeCommFunction under Device IO of the Microsoft 32-bit Windows Platform SDK (see http://www.msdn.microsoft.com/).

Popular modern options include PCI cards and serial or USB devices that provide digital I/O lines and other I/O functions - often with their own microcontrollers. Try typing something like "PC digital IO boards" You might also try adding "low cost" or "cheap" if the items you find initially are a little on the pricy side.

So once you have your device and your LED (or lamp) the next thing you need is the software to drive it. You start by either finding the relevant system API functions to call (as in the EscapeCommFunction for Win32 operating systems), or you use the SDK (usually a library or some such) that comes with the device or board. One class of device I found connected via the serial port and you sent it command character strings to control it across the serial link - I suppose it also sent its data back as character strings. Again you would refer to the documentation to determine what strings to send and expect to receive. The good point about this is that you could use some serial terminal communications program to connect to the device and control it manually to get used to how it functions before you start writing code in C++ - which by the way would entail opening the com port as a file and writing and reading the various strings to and from the device.

However you control the device you would probably wrap the whole thing in a class that represented the device in your application - possibly with a second class that used and instance of the device class to represent your lamp or LED. Note that I suggest you start with a LED rather than a incandescent bulb - they probably require less power.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ralph McArdell

Expertise

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.

Experience

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 http://www.open-std.org/jtc1/sc22/wg21/.

Education/Credentials

©2016 About.com. All rights reserved.