The task of developing custom applications that access custom hardware can be daunting for even the most seasoned application developer and especially for someone who has just learned developing applications using Visual Basic and similar RAD tools. Here in this article I present an alternative way that may help even the non-programmers to do what they want. That is to develop a custom UI and then access a specific piece of hardware that is connected to their machine.
Programming Custom Hardware for Windows (Page 1 of 4 )
I don't assume the reader to be aware of Port Access in Windows NT/2000/XP or even Windows 98 but I do assume that he knows what he?s trying to do. The First step would be to understand that why such a framework that allows one to support accessing hardware from RAD tools is needed and then later see what advantages it has got. Finally we would get into developing such a Framework.
Anyone who has programmed in basic and used the INPUT and OUTPUT statements would expect them to run in the Visual Basic environment too but fortunately or unfortunately it is not the case. The Visual Basic language doesn't support for direct hardware access and if the application (no matter what language is used to develop it) won't be able to access hardware directly if it's running on a secure system from the Windows NT family (i.e. NT, 2000, XP etc). These functions are crucial for PC hardware developers and programmers because they allow you to read and write to ports in environments like DOS or Windows 95 and 98. Thus without INPUT or OUPUT you can't read from or write to your device.
Fortunately the concept of dynamic link libraries or DLLs comes to rescue. DLLs allow VB to link to them (you can write a DLL in any language like Delphi, Borland C++ or Microsoft's Visual C++) during run-time (dynamically). VC++ has port I/O (input and output) read/write functions. Also VC++ compiler allows you to create DLLs apart from executable EXE files. Thus you can
Write VC++ code that uses these read/write functions
Compile it into a DLL (instead of an executable EXE file) file
Call your functions from VB
Make use of the facilities that a DLL provides; Like notifying you and providing you with a place to put your code that executes when a process loads it or unloads it.
Modify the DLL to make any desirable changes to the behavior of functions and you need not build the whole application again.
The list is very long and for more details on features of DLLs you can refer to DLLs, Processes, and Threads section in the MSDN library.
Now lets suppose that you're a developer willing to develop an application that needs to communicate to a hardware port, say for acquisition card, or perhaps a motor controller or even a robotic arm that you've just created! And you've never written an application that does so. Further you just have programmed in Visual Basic.
At this point the major challenges that you have are:
How do I access these ports?
What should I do so that my applications run on Windows NT family of operating systems, as they'd do on Windows 95 or 98?
I'm emphasizing on the difference between the two operating system families because they've a very different way to treat port I/O, as we'll see shortly.
So now we know that what we intend to develop and more importantly why. So let's get started!
Before you get started, you'll probably want to download the support files for this article: