Sie sind auf Seite 1von 66

DriverLINX

Digital I/O Programming Guide

Information in this document is subject to change without notice. The software described is this document is furnished under a license agreement. The software may be used or copied only in accordance with the terms of the agreement. SCIENTIFIC SOFTWARE TOOLS, INC. SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RELATED TO THE USE OF THIS PRODUCT. THIS PRODUCT IS NOT DESIGNED WITH COMPONENTS OF A LEVEL OF RELIABILITY SUITABLE FOR USE IN LIFE SUPPORT OR CRITICAL APPLICATIONS. This document may not, in whole or in part, be copied, photocopied, reproduced, translated or reduced to any electronic medium or machine readable form without prior written consent from Scientific Software Tools, Inc.

DriverLINX Digital I/O Programming Guide  Copyright 1996 - 1998, Scientific Software Tools, Inc. All rights reserved. Fourth Printing. SST 07-0698-1

LabOBJX, SSTNET and DriverLINX are registered trademarks and DriverLINX/VB is a trademark of Scientific Software Tools, Inc. Microsoft and Windows are registered trademarks and Visual C++ and Visual Basic are trademarks of Microsoft Corporation. Borland is a registered trademark and Borland C++ is a trademark of Borland International, Inc. All Keithley product names are trademarks or registered trademarks of Keithley Instruments, Inc. All other brand and product names are trademarks or registered trademarks of their respective companies.

Contents
Preface 5
Software License and Software Disclaimer of Warranty............................................................5 About DriverLINX.....................................................................................................................7 About This Programming Guide ................................................................................................7 Conventions Used in This Manual .............................................................................................9

Why Use a Digital I/O Device Driver

11

Using Direct Hardware I/O ......................................................................................................11 Advantages of Device Drivers..................................................................................................11

Introducing DriverLINX

13

About DriverLINX...................................................................................................................13 DriverLINX Hardware Model..................................................................................................13 DriverLINX Driver ....................................................................................................13 Logical Devices .........................................................................................................13 Logical Subsystems....................................................................................................14 Logical Channels........................................................................................................14 DriverLINX Programming Model............................................................................................14 Logical Device Descriptors........................................................................................15 Service Requests ........................................................................................................15 C/C++ Interface .........................................................................................................16 Control Interface ........................................................................................................16 Summary ..................................................................................................................................16

Digital I/O and DriverLINX

17

Digital I/O Hardware Description ............................................................................................17 Mapping Logical Channels to Digital Hardware Channels ......................................................18 Properties of Logical Channels ..................................................................................18 Combining or Splitting Logical Channels ..................................................................19 Implementation Notes ................................................................................................20

Configuring Digital I/O Hardware

22

Using the DriverLINX Control Panel.......................................................................................22 The Device Property Page .........................................................................................23 The Digital Input Property Page ................................................................................24 The Digital Output Property Page..............................................................................27 Using DriverLINX to Dynamically Configure Ports................................................................28

DriverLINX Digital I/O Programming Guide

Contents  3

Programming Digital I/O with DriverLINX

29

DriverLINX Digital I/O Operations ........................................................................................ 29 Using DriverLINXs Service Requests.................................................................................... 30 Properties Common to All Service Requests ............................................................ 30 Using Events to Control Service Requests ................................................................ 31 Events for Digital I/O................................................................................................ 31 Specifying Digital I/O Channels in a Service Request .............................................. 32 Specifying Data Buffers in a Service Request........................................................... 33 Interfacing to DriverLINX ...................................................................................................... 33 Opening and Closing a DriverLINX Device Driver ................................................................ 35 Configuring a Logical Device ................................................................................................. 36 Initializing the Device ............................................................................................................. 37 Initializing a Digital Subsystem............................................................................................... 39 Determining the Digital Port Configuration ............................................................................ 40 Configuring a Digital Port at Run Time .................................................................................. 41 Reading or Writing a Single Value.......................................................................................... 43 Reading or Writing Specific Digital Bits................................................................................. 46 Rapidly Transferring a Block of Digital Data ......................................................................... 49 Performing Background Digital I/O ........................................................................................ 53

Glossary of Terms Index

61 67

4  Contents

DriverLINX Digital I/O Programming Guide

Preface

Software License and Software Disclaimer of Warranty


This is a legal document which is an agreement between you, the Licensee, and Scientific Software Tools, Inc. By opening this sealed diskette package, Licensee agrees to become bound by the terms of this Agreement, which include the Software License and Software Disclaimer of Warranty. This Agreement constitutes the complete Agreement between Licensee and Scientific Software Tools, Inc. If Licensee does not agree to the terms of this Agreement, do not open the diskette package. Promptly return the unopened diskette package and the other items (including written materials, binders or other containers, and hardware, if any) that are part of this product to Scientific Software Tools, Inc. for a full refund. No refunds will be given for products that have opened disk packages or missing components.

Licensing Agreement
Copyright. The software and documentation is owned by Scientific Software Tools, Inc. and is protected by both United States copyright laws and international treaty provisions. Scientific Software Tools, Inc. authorizes the original purchaser only (Licensee) to either (a) make one copy of the software solely for backup or archival purposes, or (b) transfer the software to a single hard disk only. The written materials accompanying the software may not be duplicated or copied for any reason. Trade Secret. Licensee understands and agrees that the software is the proprietary and confidential property of Scientific Software Tools, Inc. and a valuable trade secret. Licensee agrees to use the software only for the intended use under this License, and shall not disclose the software or its contents to any third party. Copy Restrictions. The Licensee may not modify or translate the program or related documentation without the prior written consent of Scientific Software Tools, Inc. All modifications, adaptations, and merged portions of the software constitute the software licensed to the Licensee, and the terms and conditions of this agreement apply to same. Licensee may not distribute copies, including electronic transfer of copies, of the modified, adapted or merged software or accompanying written materials to others. Licensee agrees not to reverse engineer, decompile or disassemble any part of the software. Unauthorized copying of the software, including software that has been modified, merged, or included with other software, or of the written materials is expressly forbidden. Licensee may not rent, transfer or lease the software to any third parties. Licensee agrees to take all reasonable steps to protect Scientific Software Tools software from theft, disclosure or use contrary to the terms of the License. License. Scientific Software Tools, Inc. grants the Licensee only a non-exclusive right to use the serialized copy of the software on a single terminal connected to a single computer. The Licensee may not network the software or use it on more than one computer or computer terminal at the same time. Term. This License is effective until terminated. This License will terminate automatically without notice from Scientific Software Tools, Inc. if Licensee fails to comply with any term or condition of this License. The Licensee agrees upon such termination to return or destroy the written materials and all copies of the software. The Licensee may terminate the agreement by returning or destroying the program and documentation and all copies thereof.

DriverLINX Digital I/O Programming Guide

Preface  5

Limited Warranty
Scientific Software Tools, Inc. warrants that the software will perform substantially in accordance with the written materials and that the program disk, instructional manuals and reference materials are free from defects in materials and workmanship under normal use for 90 days from the date of receipt. All express or implied warranties of the software and related materials are limited to 90 days. Except as specifically set forth herein, the software and accompanying written materials (including instructions for use) are provided as is without warranty of any kind. Further, Scientific Software Tools, Inc. does not warrant, guarantee, or make any representations regarding the use, or the results of the use, of the software or written materials in terms of correctness, accuracy, reliability, currentness, or otherwise. The entire risk as to the results and performance of the software is assumed by Licensee and not by Scientific Software Tools, Inc. or its distributors, agents or employees. EXCEPT AS SET FORTH HEREIN, THERE ARE NO OTHER WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE, THE ACCOMPANYING WRITTEN MATERIALS, AND ANY ACCOMPANYING HARDWARE.

Remedy. Scientific Software Tools entire liability and the Licensees exclusive remedy shall be, at Scientific Software Tools option, either (a) return of the price paid or (b) repair or replacement of the software or accompanying materials. In the event of a defect in material or workmanship, the item may be returned within the warranty period to Scientific Software Tools for a replacement without charge, provided the licensee previously sent in the limited warranty registration card to Scientific Software Tools, Inc., or can furnish proof of the purchase of the program. This remedy is void if failure has resulted from accident, abuse, or misapplication. Any replacement will be warranted for the remainder of the original warranty period. NEITHER SCIENTIFIC SOFTWARE TOOLS, INC. NOR ANYONE ELSE WHO HAS BEEN INVOLVED IN THE CREATION, PRODUCTION, SALE OR DELIVERY OF THIS PRODUCT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, OR INCIDENTAL DAMAGES (INCLUDING DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION AND THE LIKE) ARISING OUT OF THE USE OF OR THE INABILITY TO USE SUCH PRODUCT EVEN IF SCIENTIFIC SOFTWARE TOOLS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR LIMITATIONS ON DURATION OF AN IMPLIED WARRANTY, THE ABOVE LIMITATIONS MAY NOT APPLY TO LICENSEE. This agreement is governed by the laws of the Commonwealth of Pennsylvania.

6  Preface

DriverLINX Digital I/O Programming Guide

About DriverLINX
Welcome to DriverLINX for Microsoft Windows, the high-performance realtime data-acquisition device drivers for Windows application development. DriverLINX is a language- and hardware-independent application programming interface designed to support hardware manufacturers high-speed analog and digital data-acquisition boards in Windows. DriverLINX is a multiuser and multitasking data acquisition resource manager providing more than 100 services for foreground and background data acquisition tasks. Included with your DriverLINX package are the following items:

       

The DriverLINX DLLs and drivers supporting your data acquisition hardware Learn DriverLINX, an interactive learning and demonstration program for DriverLINX that includes a Digital Storage Oscilloscope Source code for the sample programs The DriverLINX Application Programming Interface files for your compiler DriverLINX On-line Help System DriverLINX 4.0 Installation and Configuration Guide DriverLINX Technical Reference Manual Supplemental Documentation on DriverLINX and your data acquisition hardware

About This Programming Guide


The purpose of this manual is to help you quickly learn to program DriverLINX for digital I/O operations with your hardware.

  

For help installing and configuring your hardware and DriverLINX, please see the hardware manuals that accompanied your board and the DriverLINX 4.0 Installation and Configuration Guide for your version of Windows. For more information on the DriverLINX API, please see the DriverLINX Technical Reference Manual. For additional help programming your board, please examine the source code examples on the Distribution Disks.

This manual is divided into the following chapters: Why Use a Digital I/O Device Driver Brief discussion of why modern operating systems require device drivers. Introducing DriverLINX Presents a quick overview of DriverLINXs hardware and programming model. Digital I/O and DriverLINX Describes how DriverLINXs hardware model supports digital I/O boards.

DriverLINX Digital I/O Programming Guide

Preface  7

Configuring Digital I/O Hardware Using the DriverLINX Control Panel to configure digital I/O boards. Programming Digital I/O with DriverLINX Using DriverLINX for digital I/O tasks.

8  Preface

DriverLINX Digital I/O Programming Guide

Conventions Used in This Manual


The following notational conventions are used in this manual:

      
Code

Itemized lists are identified by a round bullet (). Numbered lists indicate a step-by-step procedure. DriverLINX Application Programming Interface and Windows macro and function names are set in bold when mentioned in the text. DriverLINX indicates the exported function name of the device driver DLL while DriverLINX indicates the product as a whole. DriverLINX Application Programming Interface identifiers, menu items, and Dialog Box names are italicized when mentioned in the text. Italics are used for emphasis. Source code and data structure examples are displayed in Courier typeface and bounded by a box with a single line.


Tables

Tables of information are bounded by a box with a double line.

Concept

Important concepts and notes are printed in the left margin.

DriverLINX Digital I/O Programming Guide

Preface  9

Why Use a Digital I/O Device Driver

Using Direct Hardware I/O


Most digital I/O ports are very simple devices to program. For years, most engineers wrote directly to the I/O hardware using the CPUs I/O instructions (inp and outp) or using Peek and Poke statements in Basic. This was simple, fast, and efficient and required a minimal learning curve. Under Windows 3.x, C/C++ developers could use these same techniques for most ports despite Microsofts strong recommendation against doing so. Visual Basic programmers, however, found that Microsoft had removed all direct I/O statements from the language, but they quickly discovered they could replace the missing statements with calls to simple DLLs. With the arrival of Windows NT, direct hardware I/O in user applications is not physically possible. Hardware I/O in DOS and Win16 apps may appear to execute, but the CPU never actually executes the I/O instructions. In Win32 applications hardware I/O instructions generate a privileged instruction exception and terminate the offending app. To perform user-level I/O in Windows NT and future versions of Windows 95, the operating system requires that applications communicate with the hardware using a device driver. Modern device drivers are effectively trusted operating system extensions that have more privileges than ordinary user-mode applications, DLLs, and services.

Advantages of Device Drivers


Using device drivers to control hardware offers an application in a modern multitasking, multithreaded operating system several advantages and one major disadvantage. The application advantages of the device driver model are

 

hardware-independent access to boards belonging to a class of devices, resource sharing of a single physical device among multiple applications and/or threads,

DriverLINX Digital I/O Programming Guide

Why Use a Digital I/O Device Driver  11

 

resource arbitration when multiple device users contend for the same hardware resources, and system security either at the logical level of authorized device users or at the physical level of preventing misuse of a device.

The main disadvantage of the device driver model is the extra overhead the system requires to communicate device requests between the application, the device driver, and the hardware. For device requests, such as acquiring a million data samples in one request, the overhead is negligible, but for acquiring one sample using a million separate requests, the time penalty is significant. For this reason, developers must often redesign the protocols and algorithms that worked well in a single-tasking OS, such as DOS, for use in a multitasking system, such as Windows NT.

12  Why Use a Digital I/O Device Driver

DriverLINX Digital I/O Programming Guide

Introducing DriverLINX

About DriverLINX
The DriverLINX Distribution Disks contain many sample programs for a variety of hardware devices. Many samples won't work with digital I/O devices. Welcome to DriverLINX for Microsoft Windows. DriverLINX is a language and hardware-independent, high-performance, real-time, data-acquisition device driver for 16 and 32-bit Windows 3.x, Windows 95 and Windows NT. DriverLINX supports an abstract hardware model for generalized data-acquisition hardware that includes analog and digital I/O as well as counter/timer functions. This chapter briefly surveys the DriverLINX hardware and programming model. The DriverLINX Technical Reference Manual included with the DriverLINX package is the complete, board-independent specification for the abstract DriverLINX hardware model. Whether or not youre familiar with DriverLINX programming, this guide will ease your learning curve by focusing on just the digital I/O subsystem programming model.

DriverLINX Hardware Model


DriverLINX Driver
Each DriverLINX driver supports one or more models of a device series in a manufacturers product line. You can control multiple products from different series by opening several DriverLINX drivers. You can program each product using different Service Requests for each overlapping data-acquisition task.

Logical Devices
A single DriverLINX driver can support multiple boards from its list of supported models. During configuration, you assign each physical device a Logical Device number that you use to identify a particular board to DriverLINX. At run time, applications can determine the manufacturer, model name, I/O address, and hardware resources of a Logical Device by consulting DriverLINXs Logical Device Descriptor.

DriverLINX Digital I/O Programming Guide

Introducing DriverLINX  13

Logical Subsystems
DriverLINX treats all data-acquisition devices uniformly as abstract hardware consisting of seven possible subsystems.

     

DEVICEthe physical hardware considered as a whole. AI (Analog Input)the A/D converters, multiplexers, and associated hardware. AO (Analog Output)the D/A converters and associated hardware. DI (Digital Input)the digital input ports and associated hardware. DO (Digital Output)the digital output ports and associated hardware. CT (Counter/Timer)the counter/timer channels and associated hardware.

DriverLINXs Logical Device Descriptor contains properties specifying which Logical Subsystems are available for a particular device.

Logical Channels
The subsystems, except DEVICE, consist of one or more data channels known as Logical Channels. Usually a Logical Channel corresponds to one hardware channel, but, for some boards, DriverLINX may use multiple Logical Channel numbers to access a group of hardware channels using different data widths. DriverLINX records the number of Logical Channels and their capabilities in the Logical Device Descriptor.

DriverLINX Programming Model


Programming DriverLINX for data-acquisition tasks differs from the approach you may have used previously. Most vendors data-acquisition packages consist of thick documents describing hundreds of hardware-specific calls to configure and program a data-acquisition board. DriverLINX, in contrast, uses a board-independent data structure approach to specifying the parameters for a data-acquisition task. All data-acquisition tasks in DriverLINX use the same, simple three-step protocol: 1. 2. 3. Decide how you want to acquire data. Specify your task by filling the fields of a data structure known as the Service Request. Pass the Service Request to DriverLINX which setups the hardware and acquires the data for you.

The power of the Service Request approach is that you use the same structure for all data-acquisition tasks on any supported hardware. Once you understand how to program one type of device, you can use that knowledge to program any other supported device. To notify an application of the progress or error conditions detected during a dataacquisition task, DriverLINX sends the application a series of messages just as Windows sends messages to an apps message loop. This feature allows an app to

14  Introducing DriverLINX

DriverLINX Digital I/O Programming Guide

overlap data processing with data acquisition and easily synchronize the two activities. Most data-acquisition drivers manage a hardware board exclusively for one application. DriverLINX, however, manages the subsystems of a hardware board as a shared resource that multiple applications or threads can share. If your hardware board has the necessary features, DriverLINX supports running multiple, independent tasks concurrently on one board.

Logical Device Descriptors


DriverLINX doesnt require that applications reference or use the LDD to program dataacquisition tasks. For writing hardware-independent applications, you may need to know the hardware specifications of the board your program is controlling. DriverLINX makes this information available to your program with another device-independent data structure known as the Logical Device Descriptor (LDD). The LDD contains information about number and types of data channels on the board, the allowed operating modes and commands, and many other details. For more information, see the DriverLINX Technical Reference Manual.

Service Requests
The DriverLINX Technical Reference Manual defines the DriverLINX Specification for all data-acquisition boards. Using DriverLINX for a specific board requires learning just the supported properties for the board. The most important DriverLINX concept to understand is the Service Request. This is the data structure, or form, that you use to specify all data-acquisition tasks. As much as is possible, DriverLINX treats all data-acquisition tasks as similar using the same concepts and properties to define each possible task. The key to learning how to specify a Service Request is first learning the major groups of a Service Request, and then learning the properties for each group.

A Service Request consists of four major property groups:

   

Request Groupspecifies the target Logical Device and Logical Subsystem of a task and the data-acquisition mode and operation to perform. Events Groupspecifies how DriverLINX should time or pace data acquisition, when DriverLINX should start acquisition, and when it should end. Select Groupspecifies the Logical Channels to acquire and the number and length of data buffers to acquire. Results GroupDriverLINX uses these properties to return result codes and single data values.

You can fill out Service Requests either interactively using the Edit Service Request Dialog Box in DriverLINX or programmatically by assigning values to the required properties in each group.

DriverLINX Digital I/O Programming Guide

Introducing DriverLINX  15

C/C++ Interface
If youre using C/C++, the Service Request is a C data structure type definition. Create an instance of the data structure, set all fields to zero, and then assign the proper values to each needed property in the groups. After setting up the Service Request, pass the address of the Service Request to DriverLINX for execution.

Control Interface
If youre using the Visual Basic custom control (VBX) or ActiveX (OLE or OCX) version of DriverLINX, the Service Request is an instance of the control on your form or dialog. Assign the proper values to the needed properties for your task. Then tell DriverLINX to execute the Service Request by calling the Refresh method for the control.

Summary
DriverLINX provides a hardware-independent, abstract model of data-acquisition hardware consisting of seven possible Logical Subsystems. Each Logical Subsystem treats data-acquisition tasks as conceptually similar. Developers program dataacquisition tasks by setting up the properties in the Request, Event, and Select Groups of a Service Request. The DriverLINX Technical Reference Manual defines the DriverLINX Specification for all data-acquisition boards. Using DriverLINX for a particular board requires learning the supported properties for the hardware.

16  Introducing DriverLINX

DriverLINX Digital I/O Programming Guide

Digital I/O and DriverLINX

Digital I/O Hardware Description


Most digital I/O boards either use or emulate one or more Intel 8255 Programmable Peripheral Interface chips. This chip contains 24 digital I/O lines configured as 3 individual ports

       

Port Aconfigurable as either an 8-bit data output latch/buffer or an 8bit data input latch. Port Bconfigurable as either an 8-bit data output latch/buffer or an 8bit data input buffer. Port Cconfigurable as an 8-bit data output latch/buffer, an 8-bit data input buffer, or as two 4-bit ports (Port Cu and Cl).

The 24 digital lines are programmable in two groups of 12 Group APort A and Port Cu Group BPort B and Port Cl

The Intel 8255 chip has three operational modes Basic (Mode 0)supports simple input or output without control and status signals. Outputs are latched and inputs are not latched. Strobed (Mode 1)supports input or output for Group A and B using Port C for control and status signals. The 8-bit inputs and outputs are latched. Bidirectional (Mode 2)supports bidirectional input and output only for Group A using 5 lines of Port C for control and status bits. The 8-bit inputs and outputs are latched.

Many 8255 emulations, however, only support the Basic mode (Mode 0). For more information, see the Intel 8255A Programmable Peripheral Interface data sheet and your digital I/O hardware Users Guide. Each 8255 chip occupies 4 consecutive I/O addresses. The first three locations address Ports A, B, and C, and the fourth location addresses a hardware control port.

DriverLINX Digital I/O Programming Guide

Digital I/O and DriverLINX  17

Mapping Logical Channels to Digital Hardware Channels


DriverLINX maps the hardwares digital I/O channels to consecutive Logical Channels. The following table shows the correspondence between the hardware channels (designated as A, B, C for programmable channels, I or O for fixed channels, and S for switch-selected channels) and Logical Channels.

Logical Channel
PIO-12 PIO-24 PCI-PIO24 PIO-96 PCI-PIO96 PIO-SSR-24 PIO-SSR-48 PIO-SSR-120 PIO-HV Intel 8255 PIO-32IN PIO-32IO PIO-32OUT PDISO-8 REL-16

0
A A A A A A A A O A I I O O O

1
B B B B B B B B I B I I O I O

2
C C C C C C C C S C I O O

10 11 12 13 14

A A

B B

C C

A A

B B

C C

A A

B B

C C

A A

B B

C C A B C A B C A B C

I O O

Properties of Logical Channels


Most digital I/O boards allow applications to program a channel as either input or output, but a few boards fix the channels as input or output. The following table indicates if a Logical Channel is programmable (RW) or fixed (r or rw). The programmable channels and hardware for most fixed digital channels allow applications to read back the last value written to an output channel (rw). If the hardware doesnt support this feature, DriverLINX emulates output channel readback in software.

Logical Channel
PIO-12 PIO-24 PCI-PIO24 PIO-96

0
R W R W R W R

1
R W R W R W R

2
R W R W R W R

10 11 12 13 14

18  Digital I/O and DriverLINX

DriverLINX Digital I/O Programming Guide

W PCI-PIO96 PIO-SSR-24 PIO-SSR-48 PIO-SSR-120 PIO-HV Intel 8255 PIO-32IN PIO-32IO PIO-32OUT PDISO-8 REL-16 R W R W R W R W R W R W r r rw rw rw

W R W R W R W R W R W R W r r rw r rw

W R W R W R W R W R W R W r rw rw

W R W

W R W

W R W

W R W

W R W

W R W

W R W

W R W

W R W

R W R W

R W R W

R W R W R W R W R W R W R W R W R W R W R W

r rw rw

Combining or Splitting Logical Channels


DriverLINX also supports bitlevel I/O using masks. See Reading or Writing Specific Digital Bits on page 46. DriverLINX supports a software extension to Logical Channel addressing that allows applications to combine adjacent Logical Channels into a single channel or split a Logical Channel into smaller addressable parts. For instance, applications can address individual bits on the digital I/O board or read and write multiple channels with a single operation. To use the Logical Channel addressing extensions, form a 16-bit Logical Channel address by combining the channel number of an addressable unit with a size field as follows:

0
15 MSB

Size Code
14 13 12 11 10 9 8

Channel Number
7 6 5 4 3 2 1 0 LSB

DriverLINX Digital I/O Programming Guide

Digital I/O and DriverLINX  19

The following table specifies the 3-bit size codes:

Size Code
0 1 2 3 4 5 6 7

Unit
native bit half nibble nibble byte word dword qword

Bits
varies with hardware 1 2 4 8 16 32 64

Native units refer to the hardware-defined digital channel size. For most boards, this is the same as an 8-bit byte. When using extended Logical Channel addressing, DriverLINX groups digital bits in units defined by the size code and then assigns consecutive channel numbers starting from zero. For instance, an Intel 8255 with three 8-bit ports would have the following channel addresses for each size code:

Unit
native bit half nibble nibble byte word

Channels
0..2 0..23 0..11 0..5 0..2 0..1

Address (dec)
0..2 4096..4119 8192..8203 12288..12293 16384..16386 20480..20481

Address (hex)
0..2 1000..1017 2000..200B 3000..3005 4000..4002 5000..5001

Implementation Notes

 

For extended Logical Channel addressing of unit sizes less than the native size, DriverLINX only supports single-value transfers. For block I/O transfers, DriverLINX only allows Logical Channel addressing at unit sizes equal or larger than the native size. Note that extended Logical Channels may not map to consecutive physical channels. Because DriverLINX uses the CPUs block I/O instructions for polled, block I/O transfers, some bytes wont represent I/O ports. For buffered interrupt transfers, DriverLINX requires transfers to use native addressing or larger sizes. DriverLINX will map extended Logical Channels to consecutive I/O ports even if the physical port addresses arent consecutive.

20  Digital I/O and DriverLINX

DriverLINX Digital I/O Programming Guide

When using size codes larger than the native addressing unit, you may not be able to address all hardware ports if the number of available digital I/O lines is not an integral multiple of the size unit.

DriverLINX Digital I/O Programming Guide

Digital I/O and DriverLINX  21

Configuring Digital I/O Hardware

Using the DriverLINX Control Panel


Windows NTs security features require that users installing or configuring device drivers log on under an administrative account. To configure a Logical Device, use the DriverLINX icon in the Windows Control Panel application. The DriverLINX Configuration Panel displays a tree list of all the installed DriverLINX drivers on your system and the configured Logical Devices under each driver. If you need assistance in installing your hardware or using the DriverLINX Control Panel, please read the manufacturers hardware manual or see the DriverLINX 4.0 Installation and Configuration Guide.

Use the Configuration Panel to tell DriverLINX the model of the board youve installed, its base I/O address, and the interrupt channel youve assigned to the board, if it has one. You can also instruct DriverLINX to initialize the hardware into a custom configuration of input and output ports and default output values. This may be useful if you connect your hardwares outputs to external devices that expect high logic signals, rather than the default low logic signals, as their starting state.

22  Configuring Digital I/O Hardware

DriverLINX Digital I/O Programming Guide

Your applications can also program DriverLINX to display the Configure DriverLINX Device dialog at run-time (see Configuring a Logical Device on page 36).

Pushing the Setup button on the DriverLINX Configuration Panel displays a Configure DriverLINX Device dialog box for configuring the selected Logical Device. The tabbed dialog box has a page for each Logical Subsystem that your board supports. Select and complete each property page to configure the Logical Device.

The Device Property Page

To successfully configure your hardware, enter the following required fields on the Device page:

  

Modelselect the model name that matches the installed board. The selection, Intel 8255, will work with most digital boards that use an 8bit ISA interface. Addressenter the base I/O address that you set on the boards jumpers or dip switch. This address must not conflict with any other device in your system.

The following fields should usually be left with their default values: Detectwhen checked, this instructs DriverLINX to attempt to detect and test the installed hardware during driver loading. For simple digital I/O boards, DriverLINX may not use any detection protocols so this switch may have no effect. You may need to disable detection if your hardware has malfunctioning I/O ports that youre not using or if the hardware testing algorithms interfere with permanently attached equipment.

DriverLINX Digital I/O Programming Guide

Configuring Digital I/O Hardware  23

Calibratewhen checked, DriverLINX performs hardware calibration if the device supports this feature. This switch has no effect for digital I/O boards.

At this point, you may either select OK and accept default initialization or advance to the Digital Input and Digital Output Property Pages.

The Digital Input Property Page

The Configuration properties have no effect if youre hardware has a fixed configuration.

This page allows you to assign an interrupt channel to your board, if it supports interrupts, and to modify DriverLINXs default hardware initialization. DriverLINX disables options not supported by your hardware. Enter the selections for the following fields:

  

Channelsshows the available Logical Channels for digital input and selects the Logical Channel for the Configuration properties. Interruptspecifies the interrupt channel youve assigned to your hardware. If youre not using interrupts, select none. DMA levelspecifies the DMA channel youve assigned to your hardware. Most digital I/O boards dont use DMA.

DriverLINX configures and initializes all Logical Channels when the operating system loads the kernel mode device driver, usually at boot time. At run time, the hardware effects of a Device Initialization operation depend on the number of times apps have concurrently opened the DriverLINX device driver.

 

If one application has opened the device, DriverLINX will reconfigure and reinitialize the hardware. If other applications are sharing the device, DriverLINX does not change the hardware configuration or initialization status.

Statically Configure Digital Ports


To initialize output ports with user-defined values, see Statically Initialize Digital Output Ports on page 27. Many digital I/O boards based on Intel 8255-style chips support reconfiguring the digital channels as either inputs or outputs (see Properties of Logical Channels on page 18 for a table listing boards with configurable or static ports). By default DriverLINX automatically configures all channels as inputs to emulate the power off/on behavior of 8255 chips. If you wish to initialize one or more configurable channels as outputs when the DriverLINX driver loads, you may do so with the following properties:


24  Configuring Digital I/O Hardware

Setuptells DriverLINX to configure the Logical Channel selected in the Channels list box as input (1) or output (0). DriverLINX ignores

DriverLINX Digital I/O Programming Guide

this property if Initialize isnt checked. Certain Logical Channels on some boards support additional configuration values (see Definition of Configuration Values on page 25).

Initializewhen checked, this property indicates that DriverLINX should automatically configure this channel as specified in the Setup property. If unchecked, DriverLINX ignores the value of the Setup property.

To configure the ports at run time, see Configuring a Digital Port at Run Time on page 41.

Configuration Example
To configure Logical Channel 2 as an output port, perform the following steps: 1. 2. 3. Select 2 (bits 0-7) in the Channels list box. Enter 0 in the Configuration Setup edit box. Click the Initialize check box.

Repeat steps 1 to 3 for every Logical Channel that requires user-defined configuration. After completing all Property Pages, press OK to save your configuration.

Definition of Configuration Values


Digital I/O boards that use the Intel 8255 design support 8-bit (byte) channels in groups of 3. You can program the first two channels as either all inputs or all outputs, but you can program each half (4 bits, or a nibble) of the third channel in a group separately as input or output. Bit 0 encodes the port direction (input or output). Bits 3 and 4 encode the Group mode. Bits 1 and 2 are unused for Ports A and B. The Intel 8255-based digital boards often support three modes of operationbasic I/O (Mode 0), strobed I/O with handshaking (Mode 1), and bidirectional I/O (Mode 2). The 8255 supports all three modes for Group A (Ports A and Cu) and the first two modes for Group B (Ports B and Cl). To use these options, encode the mode and port direction in the Configuration Setup property for the Logical Channel corresponding to Ports A or B.

Bit 4
0 0 0 0 1 1

Bit 3
0 0 1 1 0 0

Bit 2
x x x x x x

Bit 1
x x x x x x

Bit 0
0 1 0 1 0 1

Meaning
Mode 0, output port Mode 0, input port Mode 1, output port Mode 1, input port Mode 2, output port Mode 2, input port

The following boards and Logical Channels support Modes.

Model
PIO-12 PCI-PIO24

Logical Channels
0, 1 0, 1

DriverLINX Digital I/O Programming Guide

Configuring Digital I/O Hardware  25

PIO-96 Intel 8255 DASCard-PIO12

0, 1, 3, 4, 6, 7, 9, 10 0, 1 0, 1

Nibble programming of Port C is only available using static configuration.

Port C of an 8255 chip doesnt support modes, but it does support nibble programming of the I/O direction. To setup the third channel in each group of 3, use the following definition for the Configuration Setup property:

Bit 2
0 0 1 1 1 1

Bit 1
x x 0 0 1 1

Bit 0
0 1 0 1 0 1

Meaning
All 8 bits are output. All 8 bits are input. All 8 bits are output. Low 4 bits are input. High 4 bits are output. Low 4 bits are output. High 4 bits are input. All 8 bits are input.

The following boards and Logical Channels support nibble programming:

Model
PIO-12 PIO-24 PCI-PIO24 PIO-96 PCI-PIO96 PIO-SSR-24 PIO-SSR-48 PIO-SSR-120 Intel 8255 DASCard-PIO12

Logical Channels
2 2 2 2, 5, 8, 11 2, 5, 8, 11 2 2, 5 2, 5, 8, 11, 14 2 2

Note: Some special considerations apply when transfer data to or from a port with one nibble configured for input and the other for output.

 

When writing data, DriverLINX ignores the nibble data for the input nibble. When reading data, DriverLINX returns both nibbles. The input nibble has new input data while the output nibble has the last data written.

As an alternative, DriverLINX allows applications to explicitly specify masks or access subdivisions of a port. See Reading or Writing Specific Digital Bits on page 46 or Combining or Splitting Logical Channels on page 19.

26  Configuring Digital I/O Hardware

DriverLINX Digital I/O Programming Guide

The Digital Output Property Page

This page allows you to define output values for initializing the ports, and it allows you to define interrupt resources if you didnt define them on the Digital Input Property Page. By default DriverLINX sets output values to zero. To change the defaults, modify the following fields:

  

Channelsshows the available Logical Channels for digital output and selects the Logical Channel for the Initialization properties. Valuespecifies the output value DriverLINX uses to initialize the port selected in the Channels list box. DriverLINX ignores this property if Initialize isnt checked. Initializewhen checked, this property indicates that DriverLINX should automatically initialize this channel as specified in the Value property.

If you specify an initialization value for an input port, DriverLINX ignores the initialization value. However, if you dynamically reconfigure an input port for output, DriverLINX will write the initialization value, or the last output value if previously reconfigured, to the output port. DriverLINX configures and initializes all Logical Channels when the operating system loads the kernel mode device driver, usually at boot time. At run time, the hardware effects of a Device Initialization operation depend on the number of times apps have concurrently opened the DriverLINX device driver.

 

If one application has opened the device, DriverLINX will reconfigure and reinitialize the hardware. If other applications are sharing the device, DriverLINX does not change the hardware configuration or initialization status.

Statically Initialize Digital Output Ports


To initialize Logical Channel 2 with all bits at logic high, perform the following steps: 1. 2. 3. Select 2 (bits 0-7) in the Channels list box. Enter 255 (Dec) or 0xFF (Hex) in the Initialization Value edit box. Click the Initialize check box.

DriverLINX Digital I/O Programming Guide

Configuring Digital I/O Hardware  27

Repeat steps 1 to 3 for every Logical Channel that requires user-defined initialization. After completing all Property Pages, press OK to save your configuration.

Using DriverLINX to Dynamically Configure Ports


DriverLINX lets you dynamically reconfigure digital I/O ports at run time using the a Digital Setup Event. See Configuring a Digital Port at Run Time on page 41. Note that dynamic reconfiguration of a digital I/O port has some potential limitations. Digital I/O ports based on 8255 chips automatically reset the states of all I/O lines when software reprograms the chip. DriverLINX quickly tries to re-establish the initialization or last values written to the output ports, but the reprogramming process may cause the outputs to transiently change state, or glitch.

28  Configuring Digital I/O Hardware

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Operations


The DriverLINX API is available as a C/C++, VBX, or ActiveX interface. See Interfacing to DriverLINX on page 33. This chapter describes how to control your digital I/O board using the DriverLINX API. After providing background information about using Service Requests for digital I/O operations, this chapter presents DriverLINX procedures in C/C++ and Visual Basic for the following digital I/O operations:

      

Connecting to a deviceDriverLINX requires applications to open, select, and close drivers for specific boards. See Opening and Closing a DriverLINX Device Driver on page 35. Configuring a deviceDriverLINX allows your application to display the Configure DriverLINX Device dialog box for users. See Configuring a Logical Device on page 36. Device initializationDriverLINX initializes all subsystems on a board. See Initializing the Device on page 37. Subsystem initializationDriverLINX initializes a single, specified subsystem. See Initializing a Digital Subsystem on page 39. Single value I/ODriverLINX synchronously reads or writes a single value to an I/O port. See Reading or Writing a Single Value on page 43. Masked, single value I/ODriverLINX synchronously reads or writes only the selected bits of an I/O port. See Reading or Writing Specific Digital Bits on page 46. Block transfer on an I/O portDriverLINX synchronously transfers a block of data to or from an I/O port. See Rapidly Transferring a Block of Digital Data on page 49.

If the board has the necessary hardware, the DriverLINX API also supports the following digital I/O operations:

Dynamic port configurationDriverLINX dynamically reconfigures a programmable digital I/O port as input or output or changes the

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  29

hardwares operating mode. See Statically Configure Digital Ports on page 24, Determining the Digital Port Configuration on page 40, and Configuring a Digital Port at Run Time on page 41.

Buffered I/O on one or more portsDriverLINX asynchronously transfers values between data buffers and one or more I/O ports. See Performing Background Digital I/O on page 53.

Most digital I/O operations are synchronous. DriverLINX doesnt return control back to the calling application until the I/O transfer has completed. Buffered I/O operations, however, are asynchronous. DriverLINX initiates the I/O operation and then immediately returns control back to the calling application. Both DriverLINX and the host application run concurrently. DriverLINX can support asynchronous mode only if

 

the digital I/O board supports interrupts you have configured the board to use an available interrupt.

Using DriverLINXs Service Requests


All digital I/O operations use the Service Request to pass your task specification to DriverLINX. If youre using C/C++, the Service Request is a data structure defined in the include file, drvlinx.h. If youre using the ActiveX (OCX) control to program DriverLINX, the Service Request is an instance of the control with member variables that you setup. Whatever language youre using, the principles of setting up a Service Request are the same, although the syntax varies slightly with each language. This manual will use the Service Request terminology displayed in the Edit Service Request Dialog box. See the DriverLINX Technical Reference Manual or the example programs for the language-specific syntax.

Properties Common to All Service Requests


All Service Requests require that the application define the following properties:

 

Devicespecifies the Logical Device number of a configured device as the target of this Service Request. Subsystemspecifies the primary Logical Subsystem that is the target of this Service Request.

30  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

 

Modesuggests the hardware technique (Other, Polled, Interrupt, DMA) that DriverLINX should use for this Service Request. Operationspecifies the primary command to execute for this Service Request.

The additional Service Request groups and properties depend on the selected subsystem, operation, and task your application intends to perform.

Using Events to Control Service Requests


A few Service Request operations dont use events. DriverLINX uses the concept of an event to logically control the processing of a Service Request task. For all tasks, DriverLINX requires your application to specify an event for three event classes.

  

Timingspecifies the timing, or pacing, clock DriverLINX uses to acquire a series of samples during processing a Service Request. Startspecifies when DriverLINX starts acquiring data for this Service Request. Stopspecifies when DriverLINX stops acquiring data for this Service Request.

The example Service Request above defines a synchronous (polled) digital read of one sample (no timing event) on Logical Device 0 that starts immediately (on software Command) and ends when DriverLINX reads all, i.e., one, sample (on Terminal count). The DriverLINX Technical Reference Manual defines an extensive set of possible events for a wide variety of hardware and data-acquisition protocols. A DriverLINX driver for a specific manufacturers product, however, uses only a few of the defined events. The DriverLINX Technical Reference Manual describes the Logical Device Descriptor. DriverLINX tries to define events as hardware independent and to allow each event to be used as a timing, start, or stop event whenever logical. Some hardware boards, however, dont support events that are common to the majority of similar products, or they support only a subset of the events parameters. To allow applications to handle hardware-dependent features, DriverLINX publishes board-specific information for applications in the Logical Device Descriptor.

Events for Digital I/O


DriverLINXs digital I/O operations only use the following events:


DriverLINX Digital I/O Programming Guide

Noneindicates that the event is unspecified and unneeded.

Programming Digital I/O with DriverLINX  31

    

Digital Setupspecifies how to configure a programmable digital channel. Commandindicates that the Service Request starts or stops on software command. Terminal countindicates that the Service Request completes when the hardware has transferred all samples into or out of the data buffers. Digitalspecifies a digital input channel to read and a masked set of bits to compare to a pattern. Use as a timing, start, or stop event. Ratespecifies the operating parameters for an internal or external hardware clock.

The following table defines the events DriverLINX allows for each event class and mode.

Mode
Other Polled

Timing
None Digital Setup None

Start
None None Command Digital Command Digital

Stop
None None Terminal count Command Digital Terminal count

Interrupt

Rate Digital

Specifying Digital I/O Channels in a Service Request


Most Service Request operations require your application to specify one or more Logical Channels for reading or writing. Depending on the task and operation, your application can specify a single Logical Channel, a consecutive range of Logical Channels (Start/Stop), or a random list of Logical Channels.

32  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

DriverLINX simulates simultaneous digital I/O transfers using a fast software loop.

When specifying more than one Logical Channel, all Logical Channels must specify the same size addressable unit, such as native or byte. For buffered interrupt operations, DriverLINX can transfer one Logical Channel at each interrupt or transfer all specified Logical Channels at each interrupt. The Simultaneous property tells DriverLINX to transfer either one channel (unchecked or false) or all channels (checked or true) at each interrupt.

Specifying Data Buffers in a Service Request


DriverLINX can transfer multiple samples in one Service Request by using data buffers.

 

For untimed I/O transfers using fast CPU block I/O instructions, applications can specify one Logical Channel and one buffer as long as 128 KB. For timed I/O transfers using external interrupts, applications can specify multiple Logical Channels and up to 255 fixed-length buffers of arbitrary size.

To transfer only a single value in a Service Request, see Reading or Writing a Single Value on page 43.

Interfacing to DriverLINX
To use DriverLINX, applications must incorporate the DriverLINX API into their code. Applications can then control multiple DriverLINX drivers and multiple Logical Devices using DriverLINXs API. The DriverLINX API supports multiple languages as well as both Win16 and Win32 application development. DriverLINX supports three different language interfaces.

 

C/C++a data structure and function call API available for both 16and 32-bit C/C++ applications. VBX16-bit Visual Basic Custom Control that supports the Visual Basic 1.0, or higher, control standard. Some C/C++ compilers and 16bit Delphi 1.0 can also use this interface.

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  33


A specific DriverLINX driver may not be available on all platforms.

ActiveXor OLE 2.0 Custom Control (OCX) in both 16- and 32-bit interfaces. Visual Basic 4.0, Microsoft Visual C++ 4.0, Delphi 2.0, and most new language tools support 32-bit ActiveX controls.

The DriverLINX language interfaces bind to either DrvLNX16.DLL or DrvLNX32.DLL. These DLLs are operating system independent and allow you to run your binary application on either Win 3.x, Win 95, or Win NT as long as you have installed the correct version of DriverLINX for your hardware and operating system.

Interface with C/C++


To use the C/C++ interface, 1. Add the following C header files in your program after including the standard Windows definitions:
/* DriverLINX API */ /* DriverLINX error codes and macros */ /* OEM-specific vendor and model codes */

#include drvlinx.h #include dlcodes.h #include kmbpio.h

2.

Add the following import library to your project or linkers list of libraries, for 16-bit applications, DRVLNX16.LIB for 32-bit applications, DRVLNX32.LIB

 

Note that some compiler tools, such as Borland C/C++, use a library file format that is not compatible with Microsofts format. Please check DLAPI subdirectory where you installed DriverLINX for library files compatible with your compiler. If present, youll have to rename them to the above library names. If not present, most compilers provide a tool to create a linking library given a DLL. Please consult your compiler vendors documentation for assistance.

Interface with the Custom Control


Visual Basic Custom Control To use the Visual Basic Custom Control (VBX), add the file, DRVLNXVB.VBX to your project. You may also want to add the following files to your project to define symbolic names for the DriverLINX constants.

  

DRVLNXVB.BAS DLCODES.BAS PIOCODES.BAS

ActiveX Control To add the ActiveX Custom Control (OCX) to your project, see the instructions for your compiler. The name of the 16-bit control is DLXOCX16.OCX, while the 32-bit control is DLXOCX32.OCX. You may also want to add symbolic constant definitions to your project. Look on the DriverLINX Distribution Disks or SSTs Web site to see if files exist for your compiler.

34  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Opening and Closing a DriverLINX Device Driver


To communicate with a physical device, applications must first open a device driver. With DriverLINX, applications can either specify the name of a specific driver or they can supply a blank name. In this case, or if the app specifies an unknown name, DriverLINX will display the Open DriverLINX dialog requesting the user to select a driver to open.

Applications should close the device driver when they no longer need its services. Closing a DriverLINX driver stops all active tasks and unloads it from memory.

Open a Driver in C/C++


To load and prepare a DriverLINX driver for application use, call the following function:
HINSTANCE DLLAPI OpenDriverLINX (const HWND hWnd, LPCSTR name);

Parameter
hWnd Name

Type/Description
HWND Specifies one of the callers Window handles. LPCSTR Specifies the name of the DriverLINX driver to load. If NULL, DriverLINX displays the Open DriverLINX dialog box.

This function returns an instance handle that the application can use to identify the DriverLINX driver for the SelectDriverLINX and CloseDriverLINX function calls.

Open a Driver with the Custom Control


To load and prepare a DriverLINX driver for application use with either the VBX or OCX control, simply set the Req_DLL_name property to the name of the desired driver.

Close a Driver in C/C++


To stop all active tasks and unload a DriverLINX driver, call the following function:
VOID DLLAPI CloseDriverLINX (const HINSTANCE hDLL);

Parameter
hDLL

Type/Description
HINSTANCE Specifies the instance handle returned by an OpenDriverLINX call.

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  35

Close a Driver with the Custom Control


To stop all active tasks and unload a DriverLINX driver, simply set the Req_DLL_name property to a null string.

Configuring a Logical Device


Changing a devices configuration has no effect until after you reboot the OS. Users should normally configure Logical Devices using the DriverLINX Control Panel (see Configuring Digital I/O Hardware on page 22). However, if you want your application to manage device configuration, the app can pop up the Configure DriverLINX Device dialog box after opening a Logical Driver.

To configure a device, setup the Service Request Group as follows:

Device
<Logical Device>

Subsystem
DEVICE

Mode
OTHER

Operation
CONFIGURE

The other properties of a Service Request are unused and should be set to zero.

36  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Configure a Device Using C/C++


//********************************************** // Use this procedure to configure the hardware //********************************************** UINT ConfigDevice (LPServiceRequest pSR, UINT Device) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DEVICE; pSR->mode = OTHER; pSR->operation = CONFIGURE; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Configure a Device Using Visual Basic


'Use this procedure to configure the hardware Sub ConfigDevice(dl As Control, Dev As Integer) With dl .Req_device = Dev .Req_subsystem = DL_DEVICE .Req_mode = DL_OTHER .Req_op = DL_CONFIGURE .Refresh End With End Sub

Initializing the Device


Device initialization is the first step, after loading a DriverLINX driver, that all applications should perform. Device initialization cancels all active Service Requests on the device that the current process started and does a software reset of all subsystems. Because DriverLINX supports sharing hardware devices among multiple processes, the additional effects of device initialization vary.

If the application is the only process using the device, DriverLINX reconfigures and reinitializes the hardware to the user-defined state. If you dont define initialization values for output ports, DriverLINX writes zeros to output ports when the driver first loads and the last known output value at any other Device Initialization. If multiple processes are sharing the device, DriverLINX does not reconfigure or reinitialize the hardware state. If another process is executing a Service Request on the device, DriverLINX returns a Device Busy error to app requesting initialization.

 

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  37

To initialize a device, setup the Service Request Group as follows:

Device
<Logical Device>

Subsystem
DEVICE

Mode
OTHER

Operation
INITIALIZE

The other properties of a Service Request are unused and should be set to zero.

38  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Initialize the Device Using C/C++


#include <windows.h> #include "drvlinx.h" #include "dlcodes.h" //********************************************** // Use this procedure to initialize the hardware //********************************************** UINT InitDevice (LPServiceRequest pSR, UINT Device) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DEVICE; pSR->mode = OTHER; pSR->operation = INITIALIZE; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Initialize the Device Using Visual Basic


'Use this procedure to initialize the hardware Sub InitDevice(dl As Control, Dev As Integer) With dl .Req_device = Dev .Req_subsystem = DL_DEVICE .Req_mode = DL_OTHER .Req_op = DL_INITIALIZE .Refresh End With End Sub

Initializing a Digital Subsystem


Applications may perform a subsystem initialization at any time to abort all outstanding Service Requests owned by the calling process. Usually applications dont need to call this service.

To initialize a subsystem, setup the Service Request Group as follows:

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  39

Device
<Logical Device>

Subsystem
<Logical Subsystem>

Mode
OTHER

Operation
INITIALIZE

The other properties of a Service Request are unused and should be set to zero.

Initialize a Subsystem Using C/C++


//********************************************** // Use this procedure to initialize a subsystem //********************************************** UINT InitDigitalInput (LPServiceRequest pSR, UINT Device) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DI; pSR->mode = OTHER; pSR->operation = INITIALIZE; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Initialize a Subsystem Using Visual Basic


'Use this procedure to initialize a subsystem Sub InitDigitalInput(dl As Control, Dev As Integer) With dl .Req_device = Dev .Req_subsystem = DL_DI .Req_mode = DL_OTHER .Req_op = DL_INITIALIZE .Refresh End With End Sub

Determining the Digital Port Configuration


Most digital I/O boards support reconfiguration of digital ports as inputs or outputs. Applications can detect at run time how DriverLINX or other applications have configured the Logical Channels using the following simple algorithm: For each Logical Channel of a device, 1. 2. 3. Read Logical Channel data value. Write data value to Logical Channel. If write succeeds, the Logical Channel is an output port. If write fails, the Logical Channel is an input port.

This algorithm wont disturb the current state of any Logical Channel.

40  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Detect Port Configuration Using C/C++


UINT IOConfig[NCHAN]; void DetectPortConfig (LPServiceRequest DriverLIXNSR1, UINT nChan) { UINT chan; BYTE data; for (chan = 0; chan < nChan; ++chan) { // In order not to change the current data of each channel, // which may be written by other programs, read it first then // write it back data = ReadChannel(DriverLINXSR1, chan); WriteChannel(DriverLINXSR1, chan, data); // if a channel has an error when executing a write operation // then we know this channel is configured as an input channel // otherwise it is configured as an output channel switch (DriverLINXSR1->result) { case NoErr: IOConfig[chan] = 0; break; case InvalidOpErr: IOConfig[chan] = 1; break; default: DriverLINXSR1->operation = MESSAGEBOX; DriverLINX(DriverLINXSR1); // show error message } // switch } // for }

For the subroutines, ReadChannel and WriteChannel, see Read or Write a Single Value Using C/C++ on page 44.

Detect Port Configuration Using Visual Basic


Sub DetectPortConfig(dl) Dim chan%, Data% For chan = 0 To PIO.nChan - 1 ' In order not to change the current data of each channel, ' which may be written by other programs, read it first then ' write it back Data = ReadChannel(DriverLINXSR1, chan) WriteChannel DriverLINXSR1, chan, Data 'if a channel has an error when executing a write operation 'then we know this channel is configured as an input channel 'otherwise it is configured as an output channel If dl.Res_result = DL_NoErr Then PIO.IOConfig(chan) = 0 ElseIf dl.Res_result = DL_InvalidOpErr Then PIO.IOConfig(chan) = 1 Else dl.Req_op = DL_MESSAGEBOX 'Show Error Message dl.Refresh End If Next End Sub

For the subroutines, ReadChannel and WriteChannel, see Read or Write a Single Value Using Visual Basic on page 45.

Configuring a Digital Port at Run Time


See Configuring Digital I/O Hardware on page 22 to statically configure ports. Some digital I/O boards support dynamically reconfiguring ports as either input or output at run time. To change a ports configuration, setup the Service Request as follows: Device Subsystem Mode Operation

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  41

<Logical Device>

Digital Input or Digital Output

OTHER

CONFIGURE

And specify a Digital Setup Event for the timing event as follows:

Channel
<Logical Channel>

Mode
DIO_BASIC or DIO_STROBED or DIO_BIDIRECTIONAL

For a list of error codes, see the DriverLINX Technical Reference Manual.

The Logical Channel in the Digital Setup Event specifies the channel you want to reconfigure. To configure as an input channel, set the subsystem to digital input. To configure as an output channel, set the subsystem to digital output. If the port doesnt support dynamic reconfiguration, DriverLINX will return an error code for Operation Not Supported. If the port youre configuring is already an input, DriverLINX reports no error. Note that reconfiguring Intel 8255 PPI chips will reinitialize the values on the other output ports of the chip. DriverLINX will rewrite the last known output values to the ports, but any equipment attached to the ports may respond to transient changes on the outputs, or glitches.

42  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Configure a Port Using C/C++


//*************************************************** // Use this procedure to configure a specific channel // either as an input channel or as an output channel // at runtime //*************************************************** UINT InitDIOPort (LPServiceRequest pSR, UINT Device, SubSystems subsys, UINT chan) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = subsys; pSR->mode = OTHER; pSR->operation = CONFIGURE; pSR->timing.typeEvent = DIOSETUP; pSR->timing.u.diSetup.channel = chan; pSR->timing.u.diSetup.mode = DIO_BASIC; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Configure a Port Using Visual Basic


'Use this procedure to configure a specific channel 'either as an input channel or as an output channel 'at runtime Sub InitDIOPort(dl As Control, subsys As Integer, ByVal chan As Integer) With dl .Req_subsystem = subsys .Req_mode = DL_OTHER .Req_op = DL_CONFIGURE .Evt_Tim_type = DL_DIOSETUP .Evt_Tim_dioChannel = chan .Evt_Tim_dioMode = DL_DIO_BASIC .Evt_Str_type = DL_NULLEVENT .Evt_Stp_type = DL_NULLEVENT .Sel_chan_N = 0 .Refresh End With End Sub

Reading or Writing a Single Value


Applications can read or write a single value for a digital I/O port using DriverLINXs extended Logical Channel addressing. See Combining or Splitting Logical Channels on page 19.

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  43

To transfer a single value, setup the Service Request Group as follows:

Device
<Logical Device>

Subsystem
<Logical Subsystem>

Mode
POLLED

Operation
START

Setup the Events Group as follows:

Timing
None

Start
None or Command

Stop
None or Terminal count

For a Start Event, None or Command are equivalent as are None or Terminal Count for a Stop Event. Start on Command and stop on Terminal Count tells DriverLINX to transfer the data once. Select Channels Setup the Select Group Channels as follows:

Number of channels
1

Start Channel
<Logical Channel>

Format
native

Select Buffers Single-value transfers use ioValue property in the Service Request instead of a buffer to hold the data. Set the number of Buffers to zero. For output, assign the output value to the ioValue property in the Results Group. For input, read the input from the ioValue property after executing the Service Request.

Read or Write a Single Value Using C/C++


Write a Single Value

44  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

//******************************************* // Use this procedure to write a single value // to a specific channel //******************************************* UINT WriteChannel (LPServiceRequest pSR, UINT Device, UINT Channel, DWORD Value) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DO; pSR->mode = POLLED; pSR->operation = START; pSR->channels.nChannels = 1; pSR->channels.chanGain[0].channel = Channel; pSR->status.typeStatus = IOVALUE; pSR->status.u.ioValue = Value; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Read a Single Value


//************************************* // Use this procedure to read one value // from a specific channel //************************************* DWORD ReadChannel (LPServiceRequest pSR, UINT Device, UINT Channel) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DI; pSR->mode = POLLED; pSR->operation = START; pSR->channels.nChannels = 1; pSR->channels.chanGain[0].channel = Channel; if (DriverLINX(pSR) != NoErr) { // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); return (DWORD)-1; } return pSR->status.u.ioValue; }

Read or Write a Single Value Using Visual Basic


Write a Single Value

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  45

'Use this procedure to write one sample 'to a specific channel Sub WriteChannel(dl As Control, Channel As Integer, ByVal Value As Integer) Dim Res% With dl .Req_subsystem = DL_DO .Req_mode = DL_POLLED .Req_op = DL_START Evt_Tim_type = DL_NULLEVENT .Evt_Str_type = DL_NULLEVENT .Evt_Stp_type = DL_NULLEVENT .Sel_buf_N = 0 .Sel_chan_format = DL_tNATIVE .Sel_chan_N = 1 .Sel_chan_start = Channel .Res_Sta_ioValue = Value .Refresh End With End Sub

Read a Single Value


'Use this procedure read one sample 'from a specific channel Function ReadChannel(dl As Control, Channel As Integer) As Integer ' Setup for polled digital input of 1 sample Dim DIValue As Long With dl .Req_subsystem = DL_DI .Req_mode = DL_POLLED .Req_op = DL_START .Evt_Tim_type = DL_NULLEVENT .Evt_Str_type = DL_NULLEVENT .Evt_Stp_type = DL_NULLEVENT .Sel_buf_N = 0 .Sel_chan_format = DL_tNATIVE .Sel_chan_N = 1 .Sel_chan_start = Channel .Refresh End With If dl.Res_result = DL_NoErr Then DIValue = dl.Res_Sta_ioValue End If ReadChannel = DIValue End Function

Reading or Writing Specific Digital Bits


Applications can write specific bits to a digital I/O port using a Digital Event to supply a bit mask. Use this technique to set single bits in an output port or to share an output port between threads or processes.

46  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Setting up masked I/O is similar to single value transfers. First, setup the Service Request Group as follows:

Device
<Logical Device>

Subsystem
<Logical Subsystem>

Mode
POLLED

Operation
START

Setup the Events Group as follows:

Timing
None

Start
Digital

Stop
None or Terminal count

For a Stop Event, None or Terminal Count are equivalent. Start Event Setup the Digital Event as follows:

Channel
<Logical Channel>

Mask
<bit mask>

Match
<unused>

Pattern
<unused>

DriverLINX composes the new output value for the port as new value = (old value AND NOT Mask) OR (user value AND Mask). Select Channels Setup the Select Group Channels as follows:

Number of channels
1

Start Channel
<Logical Channel>

Format
native

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  47

Select Buffers Single-value transfers use ioValue property in the Service Request instead of a buffer to hold the data. Set the number of Buffers to zero. For output, assign the value to write to the ioValue property in the Results Group. For input, read the input from the ioValue property after executing the Service Request.

48  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Write a Masked Value Using C/C++


//***************************************************** // Use this procedure to read one value from a specific // channel //***************************************************** UINT WriteBits (LPServiceRequest pSR, UINT Device, UINT Channel, UINT Value, UINT Mask) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DO; pSR->mode = POLLED; pSR->operation = START; pSR->start.typeEvent = DIEVENT; pSR->start.u.diEvent.channel = channel; pSR->start.u.diEvent.Mask = Mask; pSR->start.u.diEvent.Match = FALSE; pSR->start.u.diEvent.Pattern = 0; pSR->channels.nChannels = 1; pSR->channels.chanGain[0].channel = Channel; pSR->status.typeStatus = IOVALUE; pSR->status.u.ioValue = Value; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Write a Masked Value Using Visual Basic


Sub WriteBits(dl As Control, Channel As Integer, ByVal Value As Integer, ByVal Mask As Integer) Dim Res% ' Setup for polled digital output of 1 sample With dl .Req_subsystem = DL_DO .Req_mode = DL_POLLED .Req_op = DL_START .Evt_Tim_type = DL_NULLEVENT .Evt_Str_type = DL_DIEVENT .Evt_Str_diChannel = Channel .Evt_Str_diMask = Mask .Evt_Str_diMatch = DL_NotEquals .Evt_Str_diPattern = 0 .Evt_Stp_type = DL_NULLEVENT .Sel_buf_N = 0 .Sel_chan_format = DL_tNATIVE .Sel_chan_N = 1 .Sel_chan_start = Channel .Res_Sta_ioValue = Value .Refresh End With End Sub

Rapidly Transferring a Block of Digital Data

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  49

Applications can rapidly transfer a single data buffer of values to or from an I/O port using the computers block I/O hardware instructions.

To transfer a buffer, setup the Service Request Group as follows:

Device
<Logical Device>

Subsystem
<Logical Subsystem>

Mode
POLLED

Operation
START

Setup the Events Group as follows:

Timing
None

Start
None or Command

Stop
None or Terminal count

For a Start Event, None or Command are equivalent as are None or Terminal Count for a Stop Event. Start on Command and stop on Terminal Count tells DriverLINX to transfer the data in buffer once. Select Channels Setup the Select Group Channels as follows:

Number of channels
1

Start Channel
<Logical Channel>

Format
native

Select Buffers Set the number of Buffers to one and the BufferSize to the number of bytes to transfer.

Read or Write a Single Buffer Using C/C++


Read One Buffer

50  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

//********************************** // Use this procedure to read a data // array from a specific channel //********************************** UINT ReadChannelBuff (LPServiceRequest pSR, UINT Device, UINT Channel, PVOID Buffer, DWORD Length) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DI; pSR->mode = POLLED; pSR->operation = START; pSR->channels.nChannels = 1; pSR->channels.chanGain[0].channel = Channel; pSR->lpBuffers = (LPBUFFLIST)malloc(DL_BufferListBytes(1)); if (!pSR->lpBuffers) return Error(Abort, BufAllocErr); pSR->lpBuffers->nBuffers = 1; pSR->lpBuffers->bufferSize = Length; pSR->lpBuffers->BufferAddr[0] = Buffer; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Write One Buffer

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  51

//*********************************** // Use this procedure to write a data // array to a specific channel //*********************************** UINT WriteChanBuf (LPServiceRequest pSR, UINT Device, UINT Channel, PVOID Buffer, DWORD Length) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DO; pSR->mode = POLLED; pSR->operation = START; pSR->channels.nChannels = 1; pSR->channels.chanGain[0].channel = Channel; pSR->lpBuffers = (LPBUFFLIST)malloc(DL_BufferListBytes(1)); if (!pSR->lpBuffers) return Error(Abort, BufAllocErr); pSR->lpBuffers->nBuffers = 1; pSR->lpBuffers->bufferSize = Length; pSR->lpBuffers->BufferAddr[0] = Buffer; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

Read or Write a Single Buffer Using Visual Basic


Read One Buffer
'Use this procedure to read one buffer from a 'specific channel. Sub ReadChannelBuff(dl As Control, Channel As Integer, Buffer() As Integer, Length As Integer) ' Setup for polled digital input Dim i% With dl .Req_subsystem = DL_DI .Req_mode = DL_POLLED .Req_op = DL_START .Evt_Tim_type = DL_NULLEVENT .Evt_Str_type = DL_NULLEVENT .Evt_Stp_type = DL_NULLEVENT .Sel_buf_N = 1 .Sel_buf_samples = Length .Sel_chan_format = DL_tNATIVE .Sel_chan_N = 1 .Sel_chan_start = Channel .Refresh End With If dl.Res_result = DL_NoErr Then For i = 0 To Length - 1 Buffer(i) = dl.Buf_0(i) Next i End If End Sub

Write One Buffer

52  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

'Use this procedure write an integer data 'array to a specific channel Sub WriteChanBuf(dl As Control, Channel As Integer, Buffer() As Integer, Length As Integer) Dim i% With dl .Req_subsystem = DL_DO .Req_mode = DL_POLLED .Req_op = DL_START .Evt_Tim_type = DL_NULLEVENT .Evt_Str_type = DL_NULLEVENT .Evt_Stp_type = DL_NULLEVENT .Sel_buf_N = 1 .Sel_buf_samples = Length For i = 0 To Length - 1 .Buf_0(i) = Buffer(i) Next I .Sel_chan_format = DL_tNATIVE .Sel_chan_N = 1 .Sel_chan_start = Channel .Refresh End With End Sub

Performing Background Digital I/O


DriverLINX can transfer I/O data in the background if the digital hardware supports an external interrupt to time or clock the data transfers. The application can optionally start or stop background I/O at the occurrence of a digital trigger.

To transfer a buffer in the background, setup the Service Request Group as follows:

Device
<Logical Device>

Subsystem
<Logical Subsystem>

Mode
INTERRUPT

Operation
START

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  53

Setup the Events Group as follows:

Timing
Digital or Rate

Start
Command or Digital

Stop
Command or Digital or Terminal count

Timing Event Use a Digital Timing Event to tell DriverLINX which hardware input source to use for the interrupt. Setup the Digital Event as follows:

Channel
<external interrupt channel>

Mask
<input lines to test>

Match
FALSE or not equal

Pattern
0

For the Channel, either specify the Logical Channel DriverLINX has assigned as the external interrupt input line (for an N-channel digital input board, this is usually Logical Channel N) or use a hardwareindependent, symbolic Logical Channel, DI_EXTCLK. DriverLINX automatically replaces this value with the correct hardware channel when the app sends the Service Request to DriverLINX. Use the Mask property to indicate which line(s) to enable for interrupts. Most boards only support one external interrupt line so use a value of 1. The MetraByte PIO-SSR Series, however, logically combines (logical OR operation) the C0 and C3 inputs of every Port C on the board to trigger an interrupt. You can enable (1) or disable (0) individual interrupt input lines by setting the corresponding bit in the Mask property. The LSB specifies the C0 input of the lowest Logical Channel, and the MSB specifies the C3 input of the highest Logical Channel. Set the Match and Pattern properties to not equal zero. This specifies that a rising edge at any input will trigger the interrupt. Other values for these properties will generate an error.

As an alternative to a Digital Timing Event, you can specify a Rate Event that uses a Rate Generator with an external clock. This option is for compatibility with other data-acquisition devices that support pacing clocks. This option is logically equivalent to specifying the above Digital Event with a Mask value of 1. Start and Stop Events DriverLINX can optionally post buffer filled messages to the application as DriverLINX completes processing each buffer. To start or stop data transfer on software command, use Command Events for the Start or Stop Event. If you use a Stop Command or Digital Event, after DriverLINX finishes processing the last buffer, it will automatically start transferring data again from the first buffer. With a Stop Command, DriverLINX will acquire data until the application resets the Service Requests Operation property to Stop and resubmits the Service Request to DriverLINX.

54  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

DriverLINX can optionally post start trigger and stop trigger messages to the application. See the DriverLINX Technical Reference Manual for more information about messages.

To start or stop data transfer when a certain condition occurs on a digital input channel, use a Digital Event for the Start or Stop Event. At each interrupt, DriverLINX tests the requested Logical Channel for the trigger event. If DriverLINX detects the start trigger, it starts processing the data buffers immediately. After processing one sample or scan, DriverLINX tests for the stop trigger event, and, if found, stops processing data immediately. Note that a digital input may change value between the time when DriverLINX reads the Logical Channel for a trigger test and reads a channel for data input. Setup a Digital Event as follows:

Channel
<Logical Channel>

Mask
<input lines to test>

Match
0 - not equal or 1 - equal

Pattern
<pattern to match>

   

For the Channel property, specify the Logical Channel for any digital input port. Use the Mask property to select which input bits to test as a digital trigger. Use the Match property to select how DriverLINX tests for a digital trigger. Use the Pattern property to specify the bits DriverLINX uses for comparison.

DriverLINX supports two types of digital triggers tests based on the value of the Match property.

Match Value
0 1

Trigger Test
Channel AND Mask  Pattern Channel AND Mask = Pattern

With a Stop Digital Event, DriverLINX will terminate acquisition either when the digital input value satisfies the digital trigger condition or when the application sends a stop operation. If the delay property of a Digital Event is not zero, DriverLINX wont trigger the event until it has counted the number of additional interrupts the app specified in the delay property. As a special case, if the stop delay property has the maximum count, DriverLINX treats this event as stop on command, but it will send a message to the application each time it detects the stop event. Select Channels Setup the Select Group Channels for 1 Logical Channel:

Number of channels
1

Start Channel
<Logical Channel>

Format
native

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  55

Setup the Select Group Channels for a consecutive range of channels:

Number of channels
2

Start Channel
<Logical Channel>

Stop Channel
<Logical Channel>

Format
native

Specify the number of channels as 2, not the number of channels in the consecutive sequence.

DriverLINX scans all channels between the starting and stopping channel. If the starting channel is greater than the stopping channel, the channel sequence wraps around at the highest Logical Channel and continues from zero. Setup the Select Group Channels for a random channel list:

Number of channels
<size of list>

Channeli
<Logical Channel>

Gaini
0

Format
native

You may use extended Logical Channel addressing, but all channels must have the same size attribute. DriverLINX can transfer one Logical Channel at each interrupt or transfer all the specified Logical Channels (a scan) at each interrupt. The Simultaneous property tells DriverLINX to transfer either one channel (unchecked or false) or all channels (checked or true) at each interrupt. Most digital I/O hardware doesnt support true simultaneous transfers, so DriverLINX rapidly reads each channel in a loop. Select Buffers Set the number of Buffers between 1 and 255 and the BufferSize to the number of bytes to transfer. Buffers must contain an integral multiple of the number of channels.

56  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Read or Write a Background Buffer Using C/C++


Read Buffers
//********************************** // Use this procedure to read a data // array from a specific channel // in the background //********************************** UINT ReadChannelBuffBkg (LPServiceRequest pSR, UINT Device, UINT Channel, PVOID Buffer, DWORD Length) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DI; pSR->mode = INTERRUPT; pSR->operation = START; /* Setup external interrupt as timing clock */ pSR->timing.typeEvent = DIEVENT; pSR->timing.u.diEvent.channel = DI_EXTCLK; pSR->timing.u.diEvent.mask = 1; pSR->timing.u.diEvent.match = FALSE; pSR->timing.u.diEvent.pattern = 0; pSR->start.typeEvent = COMMAND; pSR->stop.typeEvent = TCEVENT; pSR->channels.nChannels = 1; pSR->channels.chanGain[0].channel = Channel; pSR->lpBuffers = (LPBUFFLIST)malloc(DL_BufferListBytes(1)); if (!pSR->lpBuffers) return Error(Abort, BufAllocErr); pSR->lpBuffers->nBuffers = 1; pSR->lpBuffers->bufferSize = Length; pSR->lpBuffers->BufferAddr[0] = Buffer; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  57

Write Buffers
//*********************************** // Use this procedure to write a data // array to a specific channel // in the background //*********************************** UINT WriteChannelBuffBkg (LPServiceRequest pSR, UINT Device, UINT Channel, PVOID Buffer, DWORD Length) { memset(pSR, 0, sizeof(DL_SERVICEREQUEST)); DL_SetServiceRequestSize(*pSR); pSR->device = Device; pSR->subsystem = DO; pSR->mode = INTERRUPT; pSR->operation = START; /* Setup external interrupt as timing clock */ pSR->timing.typeEvent = DIEVENT; pSR->timing.u.diEvent.channel = DI_EXTCLK; pSR->timing.u.diEvent.mask = 1; pSR->timing.u.diEvent.match = FALSE; pSR->timing.u.diEvent.pattern = 0; pSR->start.typeEvent = COMMAND; pSR->stop.typeEvent = TCEVENT; pSR->channels.nChannels = 1; pSR->channels.chanGain[0].channel = Channel; pSR->lpBuffers = (LPBUFFLIST)malloc(DL_BufferListBytes(1)); if (!pSR->lpBuffers) return Error(Abort, BufAllocErr); pSR->lpBuffers->nBuffers = 1; pSR->lpBuffers->bufferSize = Length; pSR->lpBuffers->BufferAddr[0] = Buffer; UINT result = NoErr; if (DriverLINX(pSR) != NoErr) { result = pSR->result; // Display error message pSR->operation = MESSAGEBOX; DriverLINX(pSR); } return result; }

58  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Read or Write a Background Buffer Using Visual Basic


Read Buffers
' Use this procedure to read a data ' array from a specific channel ' in the background Sub ReadChannelBuffBkg (dl As Control, Channel As Integer, Length As Integer) With dl .Req_subsystem = DL_DI .Req_mode = DL_INTERRUPT .Req_op = DL_START ' Setup external interrupt as timing clock .Evt_Tim_type = DL_DIEVENT .Evt_Tim_diChannel = DL_DI_EXTCLK .Evt_Tim_diMask = 1 .Evt_Tim_diMatch = DL_NotEquals .Evt_Tim_diPattern = 0 .Evt_Str_type = DL_COMMAND .Evt_Stp_type = DL_TCEVENT .Sel_chan_N = 1 .Sel_chan_start = Channel .Sel_chan_format = DL_tNATIVE .Sel_buf_N = 1 .Sel_buf_samples = Length .Sel_buf_notify = DL_NOTIFY .Refresh End With End Sub Sub DriverLINXSR1_BufferFilled(task As Integer, device As Integer, subsystem As Integer, mode As Integer, bufIndex As Integer) .VBArrayBufferXfer(0, Buffer, DL_BufferToVBArray) End Sub

DriverLINX Digital I/O Programming Guide

Programming Digital I/O with DriverLINX  59

Write Buffers
' Use this procedure to write a data ' array to a specific channel ' in the background Sub WriteChannelBuffBkg (dl As Control, Channel As Integer, Buffer As Integer, Length As Integer) With dl .Req_subsystem = DL_DO .Req_mode = DL_INTERRUPT .Reqoperation = DL_START ' Setup external interrupt as timing clock .Evt_Tim_type = DL_DIEVENT .Evt_Tim_diChannel = DL_DI_EXTCLK .Evt_Tim_diMask = 1 .Evt_Tim_diMatch = DL_NotEquals .Evt_Tim_diPattern = 0 .Evt_Str_type = DL_COMMAND .Evt_Stp_type = DL_TCEVENT .Sel_chan_N = 1 .Sel_chan_start = Channel .Sel_chan_format = DL_tNATIVE .Sel_buf_N = 1 .Sel_buf_samples = Length .Sel_buf_notify = DL_NOTIFY .Refresh End With Sub DriverLINXSR1_BufferFilled(task As Integer, device As Integer, subsystem As Integer, mode As Integer, bufIndex As Integer) .VBArrayBufferXfer(0, Buffer, DL_VBArrayToBuffer) End Sub

60  Programming Digital I/O with DriverLINX

DriverLINX Digital I/O Programming Guide

Glossary of Terms

ActiveX
Component software object using Microsofts Component Object Model specification for 16- and 32-bit controls. ActiveX controls were formerly called OCX controls.

API
Application Programming Interfacethe properties and methods used to communicate with a software service.

COM
Component Object Model is a specification of a binary standard for reusable software objects.

DMA
Direct Memory Access provides a direct device to memory hardware channel that doesnt require software overhead to transfer acquired data.

Kernel Mode
The privileged mode in which the operating system runs system software such as device drivers. Kernel mode software has complete access to memory and hardware resources.

Logical Channel
A DriverLINX-assigned number for a data channel of a Logical Subsystem.

Logical Device
A user-assigned number that a DriverLINX driver uses to designate an installed hardware device.

DriverLINX Digital I/O Programming Guide

Glossary of Terms  61

Logical Device Descriptor


A DriverLINX data structure that contains hardware specifications for a Logical Device.

Logical Subsystem
A set of related hardware resources on a data-acquisition device. DriverLINX abstractly characterizes all data-acquisition devices as consisting of seven possible subsystemsdevice, analog input, analog output, digital input, digital output, and counter/timer.

nibble
A nibble is 4 bits or byte.

OCX
OLE Custom Controls are now called ActiveX custom controls.

OLE
Object Linking and Embedding is an older term for Microsoft's ActiveX technology.

Service Request
A DriverLINX data structure that completely specifies the parameters for all dataacquisition tasks.

User Mode
The mode in which the operating system runs user applications. User mode software has restricted access to memory, other processes, and hardware.

VBX
Component software object using the 16-bit Visual Basic Custom Control specification. Many 16-bit C/C++ compilers and Delphi 1.0 also support VBX controls.

62  Glossary of Terms

DriverLINX Digital I/O Programming Guide

Index

Configuration Example 25 Configuration Setup 2526 Configuration Values 25 Configure digital ports 24, 30 Configure DriverLINX Device dialog box 23, 36 Configuring a device 29 Configuring DriverLINX administrative account 22 Connecting to a device 29 Constant DI_EXTCLOCK 54, 5759 Control Interface 16 CT 14 custom configuration 22

1
16-bit 33

D
DASCard-PIO12 26 Data Buffers Specifying 33 default hardware initialization 24 Delphi 33 Detect 23, 41 detection protocols 23 DEVICE 14, 3639 device drivers 711, 22 advantages 11 disadvantages 12 Device initialization 24, 27, 2931, 37 Device Property Page 23 Address 23 Calibrate 24 Detect 23, 41 Model 1314, 23, 25 DI 14, 40, 4546, 5152, 54, 5759 DI_EXTCLK 54, 5759 dialog box Configure DriverLINX Device 23, 36 Edit Service Request 15, 30 Open DriverLINX 35 Digital Event 32 Digital I/O events 31 Digital I/O hardware 8, 17, 22, 36, 41, 56 Digital I/O operations 7, 2931 Digital Input Property Page 24, 27 Channels 24, 27 Configuration Setup 2526 Initialize 25, 27 Interrupt 24, 31, 32 Setup 23, 2426, 28, 32, 42, 44, 4647, 4950, 5259 Digital Output Property Page 27 Channels 24, 27 Initialize 25, 27 Value 27, 4346, 4346, 4346, 49 Digital Setup Event 28, 32, 42

3
32-bit 13, 3334

A
ActiveX 16, 2930, 34 Address 23 administrative account 22 AI 14 AO 14 asynchronous 30 Asynchronous I/O 30, 53

B
Background I/O 30, 53 base I/O address 2223 Block I/O transfers 20 Block transfer 29 Buffered I/O 30 Buffered interrupt transfers 20

C
C/C++ Interface 16, 34 Calibrate 24 channel size 20 Channels 24, 27 CloseDriverLINX 35 Command Event 3132, 44, 50, 54 Configuration base address 2223 custom 22 DriverLINX Control Panel 8, 22, 36 interrupt channel 22, 24, 54

DriverLINX Digital I/O Programming Guide

Index  63

direct hardware I/O 11 Direct Memory Access 24, 31 Distribution Disks 713, 34 DLCODES.BAS 34 dlcodes.h 34, 39 DLXOCX16.OCX 34 DLXOCX32.OCX 34 DMA 24, 31 DO 6, 14, 4546, 49, 5253, 5860 DOS 1112 DriverLINX AI 14 AO 14 CT 14 DEVICE 14, 3639 DI 14, 40, 4546, 5152, 54, 5759 DO 6, 14, 4546, 49, 5253, 5860 hardware model 713 Interfacing 29, 33 Logical Channels 1415, 1820, 2427, 3233, 40, 56 Logical Device 1315, 2223, 29, 36, 38, 40, 42, 44, 47, 50, 53 Logical Device Descriptor 1315, 31 Logical Subsystems 14, 16 Opening 29, 35 programming model 714 Serivce Requests 13, 15, 2931, 37, 39 DriverLINX 4.0 Installation and Configuration Guide 7, 22 DriverLINX Control Panel 8, 22, 36 Device Property Page 23 Digital Input Property Page 24, 27 Digital Output Property Page 27 DriverLINX Distribution Disks 13, 34 DriverLINX Technical Reference Manual 713, 1516, 3031, 42 drvlinx.h 30, 34, 39 DrvLNX16.DLL 34 DrvLNX32.DLL 34 DRVLNXVB.BAS 34 DRVLNXVBX.VBX 34 Dynamic port configuration 29

Types for digital I/O 31 Events Group 15, 44, 47, 50, 54

F
Functions CloseDriverLINX 35 ConfigDevice 37 DetectPortConfig 41 InitDevice 39 InitDigitalInput 40 InitDIOPort 43 OpenDriverLINX 35 ReadChannel 41, 4546 ReadChannelBuff 5152 ReadChannelBuffBkg 57, 59 SelectDriverLINX 35 WriteBits 49 WriteChanBuf 5253 WriteChannel 41, 4546 WriteChannelBuffBkg 5860

G
Group A 17, 25 Group B 17, 25

H
hardware I/O direct 11 hardware model 713 hardware testing algorithms 23 HINSTANCE 35

I
I/O address 13, 2223 base 2223 I/O addresses 17 I/O hardware calibration 24 description 17 detecting 23, 41 initialization 24 I/O instructions 11, 20, 33 I/O transfer asynchronous 30 background 30, 53 block 29, 49 buffered 30 masked I/O 29, 46 masked single value 29 overlapped 30, 53 single value 29, 33, 43

E
Edit Service Request Dialog Box 15, 30 Event Digital 32 Events Command 3132, 44, 50, 54 Digital Setup 28, 32, 42 None 3132, 44, 47, 50 Rate 32, 54 Terminal count 3132, 44, 47, 50, 54

64  Index

DriverLINX Digital I/O Programming Guide

starting and stopping 5455 synchronous 3031 timed or paced 33 untimed 33 I/O transfers 20, 33 block 20 buffered 20 interrupt 20 single value 20, 44, 48 Implementation notes 20 Initialize 25, 27 Initialize digital output ports 24, 27 Intel 8255 1719, 2326, 42 Group A 17, 25 Group B 17, 25 Operational modes 17, 25 Port A 17 Port B 17 Port C 17, 26, 54 Reconfiguring 42 Intel 8255A Programmable Peripheral Interface 17 Interface C/C++ 16, 34 Control 16 Interfacing to DriverLINX 29, 33 Interrupt 24, 31, 32 interrupt channel 22, 24, 54 Interrupt I/O 30, 53 ioValue property 4446, 4849 ISA 23

Properties 18, 24 Logical Device 1315, 2223, 29, 36, 38, 40, 42, 44, 47, 50, 53 configuration 8, 22, 36 configuring 29 connecting 29 initialization 24, 27, 2931, 37 Initializing 29, 37 Logical Device Descriptor 1315, 31 LDD 15 Logical Driver Connecting 29, 35 Logical Subsystem AI 14 AO 14 CT 14 DEVICE 14, 3639 DI 14, 40, 4546, 5152, 54, 5759 DO 6, 14, 4546, 49, 5253, 5860 initialization 39 Initializing 29, 39 Logical Subsystems 14, 16 LPServiceRequest 37, 3941, 43, 45, 49, 5152, 5758

M
Mapping Logical Channels 18 Masked I/O transfer 29, 46 Masked, single value I/O 29 Method Refresh 16 MetraByte DASCard-PIO12 26 PDISO-8 1819 PIO-12 18, 25 PIO-24 18, 26 PIO-32IN 1819 PIO-32IO 1819 PIO-32OUT 1819 PIO-96 18, 26 PIO-HV 1819 PIO-SSR-120 1819, 26 PIO-SSR-24 18, 26 PIO-SSR-48 18, 26 REL-16 1819 Mode 31, 32, 36, 38, 40, 41, 44, 47, 50, 53 Model 1314, 23, 25 multiple processes 37 multitasking 712

K
Kernel Mode 24, 27 KMBPIO.BAS 34 kmbpio.h 34

L
LDD 15 library files 34 License software 5 Logical Channel block I/O 29, 49 Determining configuration 30, 40 Dynamic configuration 25, 28, 29, 30, 41 masked I/O 29, 46 Reading or writing 29, 33, 43 reconfiguring 42 Logical Channel addressing 1920, 43, 56 notes 20 Logical Channels 1415, 1820, 2427, 3233, 40, 56 Combining or splitting 19 Mapping to hardware channels 18

N
Native 20, 33, 44, 47, 50, 5556 nibble 20, 2526 None Event 3132, 44, 47, 50

DriverLINX Digital I/O Programming Guide

Index  65

Null Event 3132, 44, 47, 50

O
Object Linking and Embedding 16, 34 OCX 16, 30, 3435 ActiveX 16, 2930, 34 OLE 16, 34 ActiveX 16, 2930, 34 OLE Custom Control 16, 30, 3435 Open DriverLINX dialog 35 OpenDriverLINX 35 Operation 31, 36, 38, 40, 41, 44, 47, 50, 5354 operational modes 17 Overlapped I/O 30, 53

P
PDISO-8 1819 PIO-12 18, 25 PIO-24 18, 26 PIO-32IN 1819 PIO-32IO 1819 PIO-32OUT 1819 PIO-96 18, 26 PIO-HV 1819 PIO-SSR-120 1819, 26 PIO-SSR-24 18, 26 PIO-SSR-48 18, 26 Port A 17 Port B 17 Port C 17, 26, 54 process 28, 37, 39 programming model 714 Properties of Logical Channels 18, 24 Property ioValue 4446, 4849 Req_DLL_name 3536

SelectDriverLINX 35 Service Request Common properties 30 Edit dialog box 15, 30 Events 31 Events Group 15, 36, 38, 39, 44, 47, 50, 53, 54 Mode 31, 32, 36, 38, 40, 41, 44, 47, 50, 53 Operation 31, 36, 38, 40, 41, 44, 47, 50, 5354 Results Group 15, 44, 48 Select Group 15, 44, 47, 50, 5556 Specifying data buffers 33 Specifying I/O channels 32 Start Events 3132, 44, 47, 50, 5455 Stop Events 3132, 44, 47, 50, 5455 Subsystem 1516, 23, 2930, 36, 3840, 41, 44, 47, 50, 53 Timing Events 3132, 44, 47, 50, 54 Service Requests 13, 15, 2931, 37, 39 Setup 23, 2426, 28, 32, 42, 44, 4647, 4950, 5259 Sharing hardware 37 Single value I/O 29 single-value transfers 20, 44, 48 Software License 5 Splitting Logical Channels 19 Start Event 3132, 44, 47, 50, 5455 Stop 3132, 44, 47, 50, 5455 Stop Event 3132, 44, 47, 50, 5455 Subsystem 1516, 23, 2930, 36, 3840, 41, 44, 47, 50, 53 Subsystem initialization 39 synchronous 3031

T
Terminal count Event 3132, 44, 47, 50, 54 threads 11, 15, 46 Timing Events 3132, 44, 47, 50, 54

V R
Rate Event 32, 54 Refresh method 16 REL-16 1819 Req_DLL_name property 3536 Request Group 15, 36, 38, 39, 44, 47, 50, 53 resource arbitration 12 resource sharing 11 Results Group 15, 44, 48 Value 27, 4346, 4346, 4346, 49 VBX 16, 29, 3335 Visual Basic 11, 16, 29, 33, 37, 3941, 43, 45, 49, 52, 59 VBX 16, 29, 3335

W
Web site 34 Win 3.x 11, 13, 34 Win 95 11, 13, 34 Win NT 1113, 34 administrative account 22 security 12, 22 Win32 11, 33

S
Scientific Software Tools 56 security 12, 22 Select Group 15, 44, 47, 50, 5556

66  Index

DriverLINX Digital I/O Programming Guide

Windows 3.x 11, 13 Windows 95 11, 13 Windows NT 1113

DriverLINX Digital I/O Programming Guide

Index  67

Das könnte Ihnen auch gefallen