Foreword
Most of today's PC's are independent of the old DOS operating System at the user level, even though some underlying code has evolved from DOS routines. The widespread adoption of Windows has brought increases in user comfort. On the other hand, many hobbyists regret that numerous broad possibilities, which were not a problem under DOS, have now disappeared. A Windows program cannot exercise full control over the Computer in the same way as a DOS program.
Under DOS, a large number of very simple applications were developed that provided direct access to the PC interfaces. LEDs and simple switches could be connected directly to the COM interface, for example, without any additional resources, and simple circuits could also be directly controlled. Under Windows, this simple approach appears to be blocked. However, we would not take the tronble of making this long introdnction if there were no solutions available. The objective of this book is to demonstrate the possibilities of direct access to interfaces under Windows.
The aim of this book is, among other things, to encourage the use of readily available and cost-effective control circuitry. The text has been developed from an older DOS-only work, and beside the older applications there are some new project possibilities that arise under Windows. In general, oniv Windows 95/98 is used in this book. The preferred programming languages are Visual Basic and Delphi, which are the Windows successors to GW Basic and Q Basic, and Turbo Pascal. Many existing DOS programs can be relatively easily ported to the Windows environment.
We wish our readers every success. Hans-Joachim Berndt and Burkhard Kainka
Introduction
Every computer experiment in real time process control or supervision requires a suitable connection to the outside world. A program must be able to record external information, to capture data control external equipment. Data can be in either, binary (0/1) Boolean (true/false), or in analogue (continuously varying signal) format.
The gateway to the outside world has traditionally been through interfaces. Industrial standard PC's, i.e. IBM PC's and clones, are obliged to follow the format of established interfaces, such as:
- Industrial interface cards installed in the computer, which have the highest throughput but are also the most expensive.
- Standart PC interfaces connecting the computer to external interface circuits. Usually for example, RS232 serial interfaces are used, which are relatively cheap to build.
- Independent single processor interfaces controlling complex tasks and having extensive data reduction capabilities, and without any raw data exchange with the PC. The application program must in this case, also comply with the system promgramming requirements and the user must also deal with the programming of these microcontroller systems.
- The presently available PC interfaces: the serial interface, the printer interface and often the joystick interface can be directly used as outside world connections. Thus in many cases there is need to use additional hardware.
The availability of directly connected interfaces is quite useful, particularly for simple experiments. For example, they can be used with the serial Interface without any further amplification for directly driving LED's, and they have very interesting project possibilities. The printer interface provides a large number of high-speed direct connections.
Many limitations can be overcome with simple additional circuits. Voltage recording is possible with only a few extra components if somewhat more complex programming and slightly lower execution speed are acceptable. In addition, projects with many I/O lines are possible without any significant additional effort.
Generally, the methods introduced in this book use few additional components, but are complimented with somewhat more demanding programs, so the PC's CPU has to work a little harder. The reader needs to be experienced with a programming language and have some electronics knowledge. Most of the circuits are so simple they can be easily built on experimental boards. All projects in this book are described completely and are easy to experiment with. In addition they provide a basis for the readers own developments. The more complex applications require some use of appropriate measuring instruments, i.e. the reader should for example have an oscilloscope.
The programming languages used in this bock are those designed for the Windows 95/98 operating systems, i.e. Visual Basic 5, and Delphi 3 & 4. All program code can be found on the CD and in the book.
1.1 PORT.DLL
The specific problem under Windows is input from the PC interface, so a universal DLL has been devised, written in Delphi 3. A DLL (Dynarnic Link Library, a Windows function library) is a set of routines which can be called from Visual Basic procedures and loaded and linked into a user application at run time. These can also be provided for other programming languages, and exclusively for this book a PORT.DLL has been developed, which can he found on the CD. Once the DLL is copied into the Windows System directory it can be used by every program. Alternatively it can be consolidated into the program directory of an *.exe file. PORT.DLL has the following functions:
- Opens the interface
- Controls serial data transmission
- Interface input
- General port I/O
- Timing function accurate to milliseconds
- Timing function in microsecond clock ticks
- Sound card access
- Joystick input
The DLL can be used with many programming systems. Due to this, and in this book, any program language can use its functions calls, for example it can be called from C++. The DLL can also be used in Word or Excel macros (see Chapters 12 and 14).
The development of a generalised DLL enables access to any hardware and in certain ways is contrary to the Windows philosophy, where all hardware access is under driver control. A driver always applies to a well-known piece of equipment, and for minor hardware experiments, there is actually no requirement for it. Correct driver development is also very complex, so that in practice only large Companies can undertake it. Under DOS and also in other programming languages there are port commands (GWBASIC: INP and OUT, in Turbo Pascal: PORT [..]), and with these one can directly access PC hardware. Under Windows 3.1, the limitations were relaizively minor, so that one can easily pass over this. Even Delphi 1 still had the old PORT command.
Under Windows 95, it became more difficult. Visual Basic 5 no longer provides direct access options for the general port addressing. In Delphi 3 direct port access is possible but only using inline assembler coding. Such coding is utilised in the DLL, and general access to the ports is made possible, even in Visual Basic. Though new port commands are provided it is not always possible to use them directly from the operating system. Accordingly, ordinary open commands must he used before anything is done with the corresponding hardware.
Under Windows NT it seems there is no possibility left for the hobbyist developer. The primary aim in Windows NT development was sedurity such that no direct hardware access is permitted. The only route left is the normal way using drivers therefore any new hardware needs to be accessed over the serial interface. In this manner all accesses are also possible under Windows NT as ordinary system calls are used in the DLL.
Generally it must be stressed that this book describes the experimental work with PC interfaces. All introduced programs were developed under Windows 95 and Windows 98 using the 32 bit programming systems, Visual Basic and Delphi 4. There is always a risk that programs may not function correctly on certain computers. For example, an interface could be installed differently on that particular computer, or a new Windows version could be encountered which uses a different way of handling the interfaces. The Reader should never try to develop professional industrial controls using these experimental methods. If this advice is not followed, it could easily happen that the Readers telephone will never stop ringing, with furious callers every day, and the only way left is to escape to a far and lonely island! |