INTERFACE EXTENSION IOLIB OF CLASS LIBRARY MFC FORCONTROL APPLICATIONS
Y. Amemiya, Engineering Research Institute, School of Engineering, The University of Tokyo, Tokyo,JapanYu. A. Gaponov, Siberian Synchrotron Radiation Center, ISSC SB RAS, Novosibirsk, Russia
K. Ito, Photon Factory, Institute of Material Structure Science, National Laboratory for High Energy
Physics, Tsukuba, Japan

Abstract
The hierarchical scheme of C++ object class library
IOLib is described and discussed. This library is interface
extension of the class library MFC for control applications
in Windows 95/NT. The extension consists of three mainparts: external device interface, windows interface andprogramming interface. The external device interface
supports a control of CAMAC modules. The windowsinterface supports different types of windows objects:
controlling (switches, buttons), numerical (integer,double, string), graphical (2D). Programming interface
supports operations with binary and ASCII text files;
multithread operations.

1 INTRODUCTION
The project of Interface Object Library is planned to be
the next realization of the class library for object-oriented
programming of control applications. Previous versions ofthe Interface Object Library were written for Windows 95(using Borland C++ with OWL) and for Solaris 2.4 (usingProCompiler and GnuCC with Motif1) [1].
The programming of the experimental control
applications is connected with solving several different
tasks. It is necessary to create the experimental control
device interface to supply the connection and interaction ofa computer with different modules needed for building theexperiment (step motors, detectors, monitors, temperatureor pressure regulators). The display user's interface isnecessary to provide input and output of experimental andcontrol information (presentation of the digital andgraphical information on the screen, control of the
keyboard and mouse for input of the experimentparameters and control of the experiment operation). It isalso very convenient to have some experiment procedureinterface to provide simple programming of different
experimental conditions.
Very often creation of the control application for new
hardware forces the programmer to make system
programming. In this case one problem is to make theprogramming extension with flexible and simplified1

http://www.inp.nsk.su/~gaponov/cpp_programming.html

interfaces (graphical, hardware, experimental process).
Another problem is the possibility to make system
programming (programming in low level language). One
may solve these two problems and realize it by using theobject oriented programming. From this point of view C++
language is a very convenient, useful programming
language [2].
During several last years Windows 95 and Windows NT
operating systems became more suitable and moreconvenient for control programming. There is amechanism of multitasking (multiprocess and multithreadmechanisms). It allows one to execute several paralleltasks to provide the real time mode of operation of theapplication. Creating the MFC class library stimulates thewriting of the easily managed and controlled graphicalapplications [3]. From the other hand, there is a quite
cheap way of creation of electronics for scientificequipment (PC hardware and CAMAC logical devices
based, for example, on ALTERA chips). Due to thesefeatures, the Windows 95/NT operating systems become
quite popular among programmers who are working withthe experiment control applications. Nevertheless, simple
using of classes from MFC class library is not very
convenient for control tasks. The objects of these classes
are the objects for general and universal purposes. Taking
into account the specialization and complexity of control
tasks, the necessity of coding the different kind ofcommunications with both MFC objects and control
devices objects, one can conclude that the next extensionof MFC class library is actual task for control application
programming.
The main goal of this project is to create extension ofMFC class library (Interface Object Library) for thewriting of experimental control applications using VisualC++.

2 INTERFACE OBJECT LIBRARY
Figure 1 shows a general overview of the Interface
Object Library. The library has hierarchical structure. TheI level classes define the main objects of the controlling
application. All of classes of the display user's interface areconstructed with the MFC and Windows API Libraries.

Classes for the CAMAC access are based on the CAMAC
Access Library.
MFC, Windows API

MFC

CWnd

I

II

TIOLMeter

TIOLMessageBox

TIOLBoard

TIOLPlot

TIOLSwitch

TIOLPlotScale

CButtonTIOLButton

CEdit

TIOLEdit

CScrollBar

TIOLScrollBar

CWinApp

TIOLApplication

CFrameWnd

TIOLVariableIII

TIOLFileName

TIOLMain

TIOLWorkThread

CWinThread

TIOLUserThread

TIOLShortTIOLUShortTIOLInt
TIOLUIntTIOLLong
TIOLULongTIOLLongLong
TIOLFloat
TIOLDouble
TIOLLongDouble
TIOLString

TIOLFile

TIOLGraph
TIOLCLib
TIOLCCrate
TIOLCBlock

TIOLCTimer

CAMAC Access Library

Figure 1: General overview of Interface Object Librarywith MFC.

2.1 MFC extension
Because of the I classes are primitive ones, forpracticable programming, a set of derived classes wereprovided.
The object of the TIOLMain class is used as anapplication with main application window. It is analogous
to the main() function in C language. After creation of thisobject the main window of application appears on thescreen. Creating the object of the TIOLBoard class as achild object of the main window one may to define (it islogically to use menu bar in main application window) themessage map functions for the main menu bar (with submenus), defined in the object of CFrameWnd class. Allwindow objects, created later, have to be pointed as a childof the corresponding parent object to be correctlymanaged.
The different controls are represented by the objects
from the TIOLEdit, TIOLButton, TIOLSwitch andTIOLScrollBar classes of the library. The mechanism ofmessage map functions and defined additional functions(for objects of TIOLScrollBar class) is used in the Interface
Object Library. When any control is made active thedefined message map function is called. The object of theTIOLEdit class may check the type of input character.
Defining the check rules one may organize, for example,input of only characters that represent the integer
numerals. In this case checking rules are written very
simply as a string "++--09" (ASCII codes 43, 45, 48-57).
Other characters during the input will not be inputted andwill not be reflected on the screen.
The diagnostic indicator is represented by the object of
the TIOLMeter class. This is a bar with changeable size ofthe another color bar inside the main one. This indicator
represents some application variable changing withinsome limits.
A very important class of the library is TIOLVariable.
Objects of this class represent different variables of theapplication. The pointer of the application variable ispassed to the object of this class during creation. Also themap function is defined. During the input operations in theeditable field, the value of the variable is automaticallyupdated. It is considered to have two ways of inputting thevalue of variable: without and with a special key tocomplete the input operation. There is an additionalfeature of the object compared with the TIOLEdit classthat may check the type of the input character. In this casethere is possibility to define the valid value range. If theinput value does not belong to the defined range, the colorof the numeric information and of the editable area borderchanges indicating the incorrect input. This incorrect
value will not be updated in the application. The
application value will have the last valid value.
The group of the classes was derived for operations withthe window objects like with the different kind of language
variables. This group of classes is TIOLInt, ...,TIOLString. Creation of objects of these classes is similar
to creation of ones of the language general types. The only
difference is that additionally it is necessary to initialize
the created object. During the initialization one can define
the limits of the object changes, the completion function.
The completion function will be called after everysuccessful input to the editable field of the object. Theobjects of these classes may be used in the arithmeticalequations.
In the library the specialized class TIOLFile for the file
operations is foreseen. After creation of the object of thisclass one has to initialize it. It is possible to initialize twodifferent map functions. One is for global checking theexperimental situation without the analysis of thestructure of the file. Another one is a traditional functionthat is called after successful analysis of the structure of thefile. The file in the Interface Object Library has a heading
block and several user's blocks. The heading block consistsof the identifier of the file, full date of the creation,comment string and the reserved space for future use. The
identifier is used by checking procedure. The user's block
consists of the number of records, the format of the record,
the string of the comment for this block of data and thecolumn of the data. All user's blocks are defined after
initialization by calling the method function of the object
AddBlock(...) with the description of the structure blockand the pointer to the data that will be used during theread/write operations. Read/write method functions
operate with at least one block of the Interface Object
Library file. For optimizing the time for file access thestructure after successful opening or creating the file isstored in the Interface Object Library. The pointer to thefile block is defined as a pointer to the current file block.
Read/write operations increment the value of this pointer.
For reading or writing the file block one has only to pointon the necessary block by using the method function
Seek(nBlock) and call then the read/write methodfunction.
For presentation of the one dimensional array theTIOLGraph class was derived. To optimize the quantity ofinformation output the graphical controls are "hidden" inan additional dialog panel that is called by pushing themiddle mouse button under the plot area. After creating
the object one have to initialize it. Then several arrays may
be connected to this object with different color. To update
the information of this object one has to use method
function Update() after any modifications of the arrays.
For simplifying the experiment programming theTIOLUserThread and TIOLWorkThread classes wereinserted into library. The object of TIOLUserThread classis initialized with the pointer to some window object to beconnected with it. The virtual function Run() is defined tomake structure of the thread: initial part, body part andfinal part. The body part of code contains the cycle ofdifferent cases, handled by an object of CEvent class.
Every part of different cases contains (optionally) the partsof code, controlled by objects of CCriticalSection andCSemaphore classes. The object of TIOLWorkThreadclass is initialized with the pointer to some procedure thathas to be carried out during the experiment. Data buffer
may be defined for data exchange between different objectsof that classes. Synchronization during the operation withthe data buffer is carried out automatically. This allows
one to use method-functions of the thread objects for dataexchange, synchronization of the, for example, CAMAC
access.

2.2 CAMAC classes
The main class for the CAMAC access is TIOLCLib.
The object of this class allows one to organize theoperation with several CAMAC crates, to check it andcheck its content (CAMAC modules) easily throughadditional dialog panel from the library. The object of theTIOLCLib class uses objects of the TIOLCCrate classpreviously defined with the objects of the TIOLCBlockclass or of the derived from it.

3 CONCLUSION
This project is planned to be realised under Windows
95/NT operating system using Visual C++ 7.0 with MFC.
The main part of Interface Object Library with graphicaluser's, CAMAC and process interfaces was created inSolaris 2.4 Operating System.
There is some smaller IBM PC realization of thislibrary in Windows 95 (written in Borland C++ 4.0) thathas been in operational use for about 4 years. It is managed
by specialists with different professional orientation.
There were no problems for them to extend and modify
this software without the help of authors.
There is possibility to add another device interface withusing corresponding device access library. On the exampleof the OD3Tools application for the controlling the fast
X-ray parallax-free position sensitive detector the goodreal-time response of the application during the actual
experiments was achieved [1,4].

REFERENCES[1] Yu.A. Gaponov, K. Ito, Y. Amemiya, “Object libraryfor a new generation of experiment-controlling
applications under the UNIX operating system”, J.
Synchrotron Rad. (1998). 5, 593-595.
[2] B. Straustrup, (1991). “The C++ programminglanguage”, Reading, MA: Addison Wesley.
[3] G. Schildt, (1996). “MFC programming from theground up”, Osborne/McGraw-Hill.
[4] V.M. Aulchenko, et. al., “Fast, parallax-free, onecoordinate X-ray detector OD3”, Nucl. Instrum, andMeth. In Phys. Research (1998). A405, 269-273.