using software to control lights, motors, and such

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 60
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 1
chunalt787 chunalt787 is offline Offline
Junior Poster in Training

using software to control lights, motors, and such

 
0
  #1
Dec 22nd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 71
Reputation: shaikh_mshariq is an unknown quantity at this point 
Solved Threads: 1
shaikh_mshariq's Avatar
shaikh_mshariq shaikh_mshariq is offline Offline
Junior Poster in Training

Re: using software to control lights, motors, and such

 
0
  #2
Dec 23rd, 2008
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.
Ideas are the building blocks of Ideas

Jason Zebehazy
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: using software to control lights, motors, and such

 
0
  #3
Dec 23rd, 2008
> 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/to...p?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).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC