Unified IO - C++ interface for industrial IO cards

  1. Windows NT

Download distribution package from www.bbdsoft.com

Unzip it to any directory on your hard disk.

For Windows NT only - use loaddrv.exe utility to install and load Unified IO hardware access driver. You can install and load this driver using following command line:

Loaddrv uniio <full path to your driver >\uniio.sys

To verify installation of the driver open Windows NT Control Panel item "Devices", find device uniio. Status should be "Started", Startup should be "Manual". In the future this driver will load automatically when you use Unified IO first time after restart. If you wish to load this driver automatically during Windows NT startup select push button "Startup…" and select Startup type – "Automatic". Then press "OK" button.

  • Building package
    1. Microsoft Visual C++ 5.0 and up

    You can build release version of entire Unified IO package by executing br.cmd batch file. Debug version can be built by bd.cmd batch file. Already built release version for Microsoft Visual C++ of uniio.dll and uniio.lib are included in the package.

    Size of Unified IO package can be reduced if you software does not have to support all IO cards supported by Unified IO.

    .cpp file

    Required if

    osiface.cpp

    iotrack.cpp

    iocard.cpp

    always

    physmem.cpp

    fwfbuff.cpp

    ab1784card.cpp

    1784dpram.cpp

    AB1784KTx card supported

    ioport.cpp

    any card other than AB1784KTx supported

    ac5card.cpp

    OPTO22 AC5 card supported

    pc7166card.cpp

    US Digital PC7166 card supported

    ac28card.cpp

    OPTO22 AC28 card supported

    dummycard.cpp

    testing without actual IO cards is supported

    pcibus.cpp

    pcidev.cpp

    pcicfg1.cpp

    pcicfg2.cpp

    pcicfgdr.cpp

    pcicfgsl.cpp

    pcicfg.cpp

    pci72xxcard.cpp

    Arbor Technologies PCI-7248 or PCI-7296 card supported

  • Overview
    1. Architecture

    Unified IO is designed to be platform independent C== class library for hardware control. Basic structure is in the figure bellow:

    Figure 1 Unified IO Architecture

    Therefore only small portion of Unified IO is platform dependent. This part varies depending on operating system. But basically this code should provide ability to perform port IO and direct memory access. Specific IO card wrappers are using only interface of platform dependent classes. As a result support for n cards under m platforms would require only n+m code modules. Traditional approach would require n*m device drivers. End user is using only platform independent Standard C++ code and therefore code is fully portable.

  • Using Unified IO
    1. Overview

    Unified IO is based on concept of IO Tracks. IO Track is a logical group of consecutive IO point controlled by the same IO interface card. There are 6 types of IO points:

    Object of class inherited from abstract class IOCard is created for each IO card in the system. Then IO tracks have to be associated with IO cards. Then program control loop:

        1. IOTrack and IOCard creation and configuration
        2. Here is a sample code of IO Track and IOCard creation:

          // create digital IO card object
          AC5Card aDigitalCard (0x220);
          // create 2 tracks consisting of digital IO
          // and associate tracks with the card
          IOTrack track ( aDigitalCard // IO card reference
                        , 0 // starting point
                        , "IIIIIIIIIIIIOOOO" // track of 12 inputs and 4 outputs
                        );
          

          Specific IOCard instance is created. You should consult specific IOCard class description for constructor parameters description. In our case OPTO 22 AC5 card is created and it’s base address is passed in the constructor.

          IO Track is created by providing a reference to a specific IOCard object to which this track belongs. Since IOTrack is an abstraction of physical group of inputs, outputs and other elements, multiple IOTracks can belong to the same IOCard. For this purpose starting point parameter is used. First IOTrack for any IOCard should have starting point 0. Other IOTracks in the same IOCard should have starting point more than 0. Usually this number is incremented by the number of points of previous track. In our example starting point for a next track on the same IOCard would be 16. Third parameter of IOTrack constructor is used to specify IO mask of the IOTrack. This can be any combination of the following characters (assuming specific IOCard supports them):

          ‘N’ Not Used
          ‘I’ Digital Input
          ‘O’ Digital Output
          ‘A’ Analog Input
          ‘U’ Analog Output
          ‘C’ Counter
          ‘R’ Reverse Counter

          If specified point type is not supported by a specific card an exception is thrown.

          User is responsible for correct destruction of objects of classes IOCard and IOTrack.

        3. Reading and writing to IO

    Class IOTrack provides all necessary interface to read from and write to IO points. By calling function IOTrack::updateInputs() IOTrack reads all inputs belonging to this track from IOCard and places values to an internal image.

    Later you can access this image by using IOTrack::operator [].

    All modifications to outputs are performed in this internal image and are written to IOCard by calling function IOTrack::updateOutputs().

    Usually all IO control is performed within an loop. In the beginning of the loop reading inputs from all tracks, then performing control logic and writing outputs to all tracks at the end.

    Here is a simple example of reading and writing to IO points:

    while (1)
    {
       // read current state of all inputs
       track.updateInputs ();
       // do control logic
       if ( track[5] && track[1] )
       {
          track[14] = 0;
       } // endif
    
       // activate/deactivate outputs
       track.updateOutputs ();
       // sleep for 10 milliseconds = 10000 microseconds
       OSInterface::sleep (10000);
    } // endwhile
    
    1. Class Diagrams
      1. System Interface classes
      2. IO Card Interface classes

    2. Unified IO Reference
        1. AB1784Card
        2. Class for accesing Allen-Bradley 1784 KTx series of cards by Remote IO protocol

           

          1. Derived from IOCard
          2.  

          3. Public Operations:
            1. AB1784Card AB1784Card (const unsigned int inBaseMemoryAddress, const char* const inFirmwarePath, const unsigned int inLinkSpeed)
            2. void ~AB1784Card ()
            3. unsigned int baseMemoryAddress ()
            4. returns dual port RAM address provided while constructing AB1784Card

            5. unsigned int linkSpeed ()
            6. Returns Remote IO link speed

            7. const char* const firmwarePath ()
            8. returns full path to directory where AB1784KTx firmware files are stored.

           

        3. IOCard
        4. An abstract class for representation of IO interface card.

          1. Public Operations:
            1. IOCard IOCard (const char* inType)
            2. IOCard& reset ()
            3. default implemetation of reset operation does nothing.

            4. void ~IOCard ()
            5. const char* const type ()
            6. Returns name of IO card

           

        5. PhysicalMemory
        6. provides access to physical memory block from user process.

          1. Public Operations:
            1. PhysicalMemory PhysicalMemory (const unsigned long inPhysicalAddress, const unsigned long inSize, bool fWriteAccess = true)
            2. Retrives pointer to the specified block of physical memory.

            3. PhysicalMemory& writeMemoryBlock (const void* const inDataToWrite, const unsigned long inBlockSize, const unsigned long inStartOffset = 0)
            4. modifies physical memory block

            5. void ~PhysicalMemory ()
            6. PhysicalMemory& readMemoryBlock (void* inBuffer, const unsigned long inBlockSize, const unsigned long inStartOffset = 0)
            7. reads block of data from physical memory

            8. unsigned long size ()
            9. returns size of a physical memory region

           

        7. AC28Card
        8. OPTO 22 ISA AC28 Pamux bus card wrapper

          1. Derived from IOCard
          2.  

          3. Public Operations:
            1. AC28Card AC28Card (const unsigned int inBaseIOPort, const unsigned int inResetPort, const bool inResetLevel)
            2. unsigned int baseIOPort ()
            3. Returns base IO port address

            4. void ~AC28Card ()
            5. unsigned int resetPort ()
            6. returns reset port address

            7. bool resetLevel ()
            8. returns reset level. true - HIGH, false - LOW

           

        9. AC5Card
        10. OPTO 22 ISA AC5 direct digital card wrapper.

          1. Derived from IOCard
          2.  

          3. Public Operations:
            1. AC5Card AC5Card (const unsigned int inBaseIOPort)
            2. unsigned int baseIOPort ()
            3. returns base IO port number - parameter provided while constructing AC5Card

            4. void ~AC5Card ()

           

        11. DummyCard
        12. Default implementation of IOCard, could be used to test functionality of software without actual IO cards.

          1. Derived from IOCard
          2.  

          3. Public Operations:
            1. void ~DummyCard ()
            2. DummyCard DummyCard ()

           

        13. FirmwareFileBuffer
        14. Class for implementing file buffer for loading firmware files

          1. Public Operations:
            1. FirmwareFileBuffer FirmwareFileBuffer (const char* const inFileName)
            2. unsigned long size ()
            3. Returns the size of an firmware file

            4. void ~FirmwareFileBuffer ()
            5. char* operator char* ()
            6. Returns pointer to a firmaware file buffer read from disk

           

        15. IOPort
        16. Represent class wrapper for reading and writing from PC IO ports

          1. Public Operations:
            1. IOPort IOPort (const unsigned int inPortNumber, bool fWriteAccess = true)
            2. represents IO port. Constructor enables access to a port.

            3. IOPort& write (const unsigned char inValue)
            4. writes 1 byte of data to the port.

            5. IOPort& write (const unsigned short inValue)
            6. writes 2 bytes of data

            7. IOPort& write (const unsigned long inValue)
            8. writes 4 bytes of data

            9. void ~IOPort ()
            10. -

            11. unsigned char readChar ()
            12. reads 1 byte of data

            13. unsigned short readShort ()
            14. reads 2 bytes of data

            15. unsigned long readLong ()
            16. reads 4 bytes of data

           

        17. IOTrack
        18. Basic abstraction level of physical IO track. Track must be asociated with an specific IO card.All input/output operations are performed through IOTrack.

          1. Public Operations:
            1. IOTrack IOTrack (IOCard& inCard, const unsigned int inStartingPoint, const char* const inIOMask)
            2. -----------------------------------------------------------------------------

            3. void ~IOTrack ()
            4. enum IOTrack::PointTypes pointType (const unsigned int inPointNumber)
            5. return type of specified IO point.

            6. bool hasPointOfType (const char inPointType)
            7. returns if there are any points of specified type.

            8. unsigned int startingPoint ()
            9. meaning of starting point value is IO card specific.

            10. unsigned int numberOfPoints ()
            11. Returns number of points per track

               

            12. IOCard& card ()
            13. Returns a reference to IOCard which this trac belongs to.

            14. long trackState ()
            15. returns track state code. 0 always means OK, other state codes are

              IO card specific

            16. const long& operator [] (const unsigned int inPointNumber)
            17. returns state of individual IO point

            18. long& operator [] (const unsigned int inPointNumber)
            19. changes state of individual IO point

            20. IOTrack& updateInputs ()
            21. reads current state of all input points from IO card. Should be called periodically.

            22. IOTrack& updateOutputs ()
            23. modified physical state of all output points. Should be called periodically or after output state modification.

           

        19. OSInterface
        20. Singleton class for accessing operating system services. Windows NT implementatin loads and opens uniio.sys driver that is used to enable port IO from user process and retrive pointer to physical memory block. All communication with device driver is performed through OSInterface class.

          1. Public Operations:
            1. OSInterface& osinterface ()
            2. void sleep (const unsigned long inMicroseconds)
            3. suspends execution of the current thred for specified number of microseconds

            4. void ~OSInterface ()

           

        21. PC7166Card
        22. Class for accessing USDigital PC7166 Encoder counter card. This card accepts tracks only with 'C' or 'R' types

          1. Derived from IOCard
          2.  

          3. Public Operations:
            1. PC7166Card PC7166Card (const unsigned int inBaseIOPort)
            2. unsigned int baseIOPort ()
            3. Returns base IO Port of this card

            4. void ~PC7166Card ()
            5. IOCard& reset ()
            6. Reset encoder counters to 0

           

        23. PCI72xxCard
        24. Class for interfacing Arbor Technologies PCI-7248 and PCI7296 direct digital IO cards

          1. Derived from IOCard
          2.  

          3. Public Operations:
            1. PCI72xxCard PCI72xxCard (const unsigned int inCardId = 0)
            2. void ~PCI72xxCard ()

           

        25. PCIBus
        26. Singleton class representing computer PCI bus.

          1. Public Operations:
            1. PCIBus& pciBus ()
            2. bool exists ()
            3. Tests if PCI bus exists on the system

            4. void ~PCIBus ()
            5. const PCIDeviceInfo* getDeviceInfo (const unsigned short inVendorId, const unsigned short inDeviceId, const unsigned int inCardNumber = 0)
            6. returns pointer to Device Information structure or NULL or device with specified ID is not present in the system

           

        27. PCIDeviceInfo
        28. Clas for representing PCI device information retrieved from PCI Bus.

          1. Public Operations:
            1. unsigned short vendorId ()
            2. void ~PCIDeviceInfo ()
            3. unsigned short deviceId ()
            4. unsigned short status ()
            5. unsigned char revisionId ()
            6. unsigned char progIf ()
            7. unsigned char subClass ()
            8. unsigned char baseClass ()
            9. unsigned char cacheLineSize ()
            10. unsigned char latencyTimer ()
            11. unsigned char headerType ()
            12. unsigned char BIST ()
            13. base addresses are from 0 to 5

            14. unsigned long baseAddress (const unsigned char i)
            15. unsigned long CIS ()
            16. unsigned short subVendorId ()
            17. unsigned short subSystemId ()
            18. unsigned long ROMBaseAddress ()
            19. unsigned char capabilityList ()
            20. unsigned char interruptLine ()
            21. unsigned char interruptPin ()
            22. unsigned char minimumGrant ()
            23. unsigned char maximumLatency ()

           

        29. PCIConfig
        30. Abstract class representing method of retrieving PCI device information.

          1. Public Operations:
            1. bool exists ()
            2. returns if this PCI configuration retrieval method is available in the computer.

            3. void ~PCIConfig ()
            4. void scanBus ()
            5. Function which scans PCI bus on first use and stores retrieved information in the PCIBus class

           

        31. PCIConfig1
        32. Class for direct PCI access using "Type 1"

          1. Derived from PCIConfigDirect
          2.  

          3. Public Operations:
            1. PCIConfig1 PCIConfig1 ()
            2. Command word for Config1 access

              -----------------------------------------------------------------------------

            3. bool exists ()
            4. end destructor

              -----------------------------------------------------------------------------

            5. void ~PCIConfig1 ()
            6. end constructor

              -----------------------------------------------------------------------------

           

        33. PCIConfigDirect
        34. Abstract class for retrieving PCI device information using direct port IO.

          1. Derived from PCIConfig
          2. Public Operations:
            1. PCIConfigDirect PCIConfigDirect ()
            2. void scanBus ()
            3. void ~PCIConfigDirect ()

           

        35. PCIConfig2
        36. Class for Direct PCI access using "Type 2"

          1. Derived from PCIConfigDirect
          2.  

          3. Public Operations:
            1. PCIConfig2 PCIConfig2 ()
            2. bool exists ()
            3. end destructor

              -----------------------------------------------------------------------------

            4. void ~PCIConfig2 ()
            5. end constructor

              -----------------------------------------------------------------------------

           

        37. PCIConfigSelector
        38. Class which selects what PCI acces type should we use on a specific platform. Platform specific. On a Windows NT PC systems tries PCIConfig1 and if this one fails uses PCIConfig2.

          1. Public Operations:
            1. PCIConfig* createPCIConfig ()
            2. determines which PCI bus configuration retrieval options are available and creates appropriate PCIConfig object.



    Copyright © 2000 UAB "BBD SOFT"
    All Rights Reserved.
    Comments to bbdsoft@bbdsoft.com

    All brand names and products names are trademarks or registered trademarks of their respective companies.