Global TMW:
Login  |  Register          Free Newsletter Subscription
Subscribe
Email
Print
Reprint
Learn RSS

Control I/O Ports from Windows NT

A shareware ActiveX control lets you control plug-in cards and other peripherals.

Peter A. Bates, University of Central Lancashire, Preston, UK -- Test & Measurement World, 4/15/2000

Download the author's complete paper, "LabView Peeking and Poking Using Windows NT,"as a zipped Word document.

Writing a driver or other control software for a PC peripheral under DOS, Windows 3.1x, and Windows 95/98 is relatively easy. These operating systems give you direct access to the PC’s I/O ports through programming commands called peek and poke. Unfortunately, if you make a programming error and write data to the wrong address, you can cause the system to crash. Windows NT is less likely to crash, but you pay a price for added stability—you must conform to rules for controlling mapped I/O ports and you lose direct access to those ports.

To control I/O ports under Windows NT, application software must communicate through a kernel device driver. You could write your own kernel device driver or write a dynamic link library (DLL) to access a kernel device driver. It’s a lot easier, though, to use an ActiveX control, and its associated DLL, to gain access to I/O ports. The ActiveX control is available as inexpensive shareware.1 This control works with any language that includes an ActiveX container. As an alternative, you can write code that directly calls the control’s DLL.

Using the ActiveX control and its associated DLL, I wrote a LabView program that controls a digital I/O card. You can use the control and its DLL with nearly any high-level language you wish. If you want the details of programming with the ActiveX control, download my complete paper, “LabView Peeking and Poking Using Windows NT,” above.

Keep in mind that some I/O cards come with a Windows NT driver, so you may not need the shareware control. If your I/O card lacks a Windows NT driver, or if you’ve designed a custom I/O card, then use the ActiveX control to avoid writing your own kernel device driver.

Before you can use the control, you must install it on a PC. From the shareware site, download the file TVicPort.zip. The zip file contains many files, but you need just three—TVicPort.ocx (the ActiveX control), TVicPort.dll (the interface to the kernel-mode device driver), and vicport.sys (the kernel-mode device driver). My paper explains where to place these files and how to register the OCX file—the ActiveX control—with Windows NT.

After you install the control, you must link it to an application-development program such as LabView, HP VEE, TestPoint, Visual Basic, Visual C++, Delphi, and so on. Each language has its own procedure for adding a registered ActiveX control to an application, so consult the appropriate manuals or help files for instructions.

The control provides procedures—called methods—that read data from and write data to a PC’s memory and I/O ports. The control includes methods called “Open” and “Close” that, as you’d expect, open and close the device driver. I also used the “Port” method, which sends data to and reads data from I/O ports.

My application used a digital I/O card containing an 8255 programmable peripheral interface chip. The IC includes three 8-bit parallel I/O ports and an internal register. (The 8255 chip comes in several equivalent variations: 8255A, 8255A-5, 82C55, and so on.)

TMW00_042F4Fig1.gif (14871 bytes)
Figure 1. This LabView program controls a digital I/O card through the TVicPort ActiveX control.

Before you can use the ActiveX control to perform any actions on an I/O card, you must know the port addresses the card uses. An 8255 chip requires four contiguous addresses; the three lowest addresses control the three 8-bit I/O ports (A, B, and C), and the highest address controls an internal register. My card was set up for addresses 300 hex through 303 hex, or 768 through 771. The data sheet for the 8255 chip, or the manual for your I/O card, will provide more information about addressing and controlling the ports.2To verify that you can manually control your I/O card using the ActiveX control, write a simple test program that will exercise the ports. I wrote a LabView program, shown in the diagram in Figure 1. The left-most box containing TVicPortLib sets up the DTVicPort control and the following box opens the TVicPort driver so software can use it. The four-layer box addresses the register in the 8255 chip at address 771, and loads the register with the value 128. This value configures ports A, B, and C as output ports. Finally, the four-layer box inside the frame—a while loop—transfers the value from a slide control to the eight pins on port-A of the 8255 chip. The while loop continuously updates port A with the slider’s setting. An On/Off control in the while-loop frame terminates the program and causes it to close the driver.

TMW00_042F4Fig2.gif (11281 bytes)
Figure 2. This front panel, which operates the program in Figure 1, tests the LabView code, the I/O port, and the digital I/O card.

The LabView program in Figure 1 corresponds to the instrument “panel” shown in Figure 2. The “TVP” box represents an ActiveX container that links the control to the LabView code. The slider control can move from 0 to 255, the range of values 8 bits will represent. To check the output from the 8255, you can use a set of eight LEDs connected to the port-A pins through buffers, inverters, or transistors.

To test the 8255 as an input device, write 155 to address 771, the 8255 chip’s register. This value configures ports A, B, and C as input ports. A set of pull-up resistors and DIP switches connected to ground will supply logic levels to port A for testing. Now use a while loop to obtain data from port A and display it. My LabView test program read data from port A and displayed it on a waveform chart. Changing the switch settings changed the displayed waveform trace value, indicating that the test program properly controlled the 8255 chip’s input ports. After you confirm proper operation of the ActiveX control, you can incorporate it in actual applications. T&MW

FOOTNOTES

1. You can download TVicPort version 3 from www.entechtaiwan.com.  Price: $50 (US).

2. You can download an 8255 data sheet at developer.intel.com/design/periphrl/datashts/231256.htm.

FOR FURTHER READING

Freeman, Michael T., “Create Your Own ActiveX Controls,” Test & Measurement World , September 1998. p. 39.

Peter Bates is a senior lecturer in applied physics and is the coursse leader of the MSc in PC Interfacing and Software Applications program at the University of Central Lancashire, Preston, UK. E-mail: p.a.bates@uclan.ac.uk.

Email
Print
Reprint
Learn RSS

Talkback

We would love your feedback!

Post a comment

» VIEW ALL TALKBACK THREADS

Related Content

Related Content

 

By This Author

There are no other articles written by this author.

Sponsored Links



 
Advertisement
SPONSORED LINKS

More Content

  • Blogs
  • Podcasts

Blogs


Sorry, no blogs are active for this topic.

» VIEW ALL BLOGS RSS

Podcasts

Advertisements





NEWSLETTERS

Click on a title below to learn more.

Test Industry News (3 Times Per Month)
Machine-Vision & Inspection (Monthly)
Communications Test (Monthly)
Design, Test & Yield (Monthly)
Automotive, Aerospace & Defense (Monthly)
Instrumentation (Monthly)
Resource Center E-Alert (Monthly)
©2008 Reed Business Information, a division of Reed Elsevier Inc. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy
Please visit these other Reed Business sites