I just finished with my first year of Computer Science in college and over the break I wanted to learn how to do output from a computer using a C++ program to control different I/O hardware. I was thinking I would start somewhere simple with something such as turning on and off a light out of a serial port or making a motor turn. Does anyone have any suggestions on where to start such as a good website or mabye even something like which port is the simplest to output from and the like.

Thanks

May be this content will help to you.

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.

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.

> from a computer using a C++ program to control different I/O hardware.
Do you mean from the same computer as you use for browsing the web (with it's fancy OS and all)?

Or perhaps something at the other end of the scale.
http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=2735
This is just one of MANY small programmable devices.

Right at the bottom, you'll have a few K of memory, no OS and probably only be able to use a C program to write very simple programs.

Then there's a near continuum of improving features (more CPU bits, faster processor, more memory, a range of OS possibilities) all the way up to your desktop PC (and way beyond it as well).

Respected People
I am a 3rd year software engineering student. I am preparing for my 7th sem project.
I need help in reference to this above discussion , how we can control other hardware ware like motors, light bulbs, or like giving a outside source of battery for the functioning just need to know how can I complete the circuit by giving instructions from an program that is giving signals.
Which language will be useful and how I can use it… Is java can be useful? Further I have a hardware like intel core duo 2 processor laptop. So I really need your help if any one can help me regarding the same… I want to talk to some one personally my e mails [email removed]. Its my personal project… Further can you please explain this (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.)
Shashank Singh

Respected People
I am a 3rd year software engineering student. I am preparing for my 7th sem project.
I need help in reference to this above discussion , how we can control other hardware ware like motors, light bulbs, or like giving a outside source of battery for the functioning just need to know how can I complete the circuit by giving instructions from an program that is giving signals.
Which language will be useful and how I can use it… Is java can be useful? Further I have a hardware like intel core duo 2 processor laptop. So I really need your help if any one can help me regarding the same… I want to talk to some one personally my e mails shashanksingh333@rediffmail.com. Its my personal project… Further can you please explain this (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.)
Shashank Singh

If you looking for a real time Operating System to your project, then try something
like ReactOS and a embedded linux board, one of my friend brought a embedded linux
board around 125$.In that way the kernel gives the real time scheduling to your
program and it's IO operations while in the background you still can run fancy
X-windows or web browser,or your application GUI.

Or on your conventional x86 computer you can install real time linux package
or patch your kernel source tree and recompile it.like this,in debian,
https://www.osadl.org/Realtime-Preempt-Kernel.kernel-rt.0.html
then you can specially request the real time scheduling to your application
from the kernel.

Programming language:
I've used assembler, Fortran, Basic, and C. Choose a language you know and can connect to the software driver you need to interface with the hardware.

Operating system:
Anything the software driver will work on.

Hardware:
Usually you need a computer interface that converts the computer signal onto an electrical signal in some manner. Many times that comes in the form of a hardware board added to the computer the converts a binary value into electrical currents.

Many times the device you want to control is computer ready. You plug the cable in, send a value, the device works.

The hardest part is deciding what value to use and where to send it -- usually explained in the manual.

you'd have to learn program software that would be able to control microcontrollers or microprocessors, PICs or whatever those chips 8051,8059,8057 meant
i had microprocessors this sem which has ended, and in the book it was said there are 3rd party APIs that directly communicate with these chips via an interface of sort

so maybe some ASM will be required but i don't know really. You should check out some Evil Genius series of books. they have great stuff about all this
search one for the electronics

you'd have to learn programming software that would be able to control microcontrollers or microprocessors, PICs or whatever those chips 8051,8059,8057 meant
i had microprocessors this sem which has ended, and in the book it was said there are 3rd party APIs that directly communicate with these chips via an interface

so maybe some ASM will be required but i don't know really. You should check out some Evil Genius series of books. they have great stuff about all this
search one for the electronics

Some years ago we controlled external devices by sending a signal out the serial port to a PLC which, in turn, turned on/off switches to the device.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.