COMPUTER LOGICIEL — MÉTROLOGIE

The Mensurasoft-System: Software Drivers for

Scientific Devices in the Most Common Computer

Languages on All Major Operating Systems with a

Prototype API for Measurement Data Processing

Applications - Practical Examples

P. Dieumegard *

Independent Researcher, Orléans, France

Abstract

For years now, although many scientific devices have a port for computer connection, the diversity of various con- nection types results in lack of software able to use the totality of them. This paper presents how to: (1) build software drivers with a prototype Application Programming Interface API for scientific devices using dynamic libraries under various combinations of connection ports, programming languages and operating systems, (2) employ these drivers in software programs capable of managing more than one device at the same time, and (3) use two specific software imple- mentations of this whole Mensura (Measurement) System to se- lect appropriate built driver, define communication set- tings, and collect-store-process-present experimental data.

Keywords

Mensurasoft, measurement, devices, dynamic , pro- gramming languages, MS-Windows, , driver

Introduction ally through an ISA, PCI or In this paper, "scientific RS-232, but nowadays via USB devices" are mainly measure- too. ment devices: pHmeters, volt- Sometimes there is soft- meters, thermometers etc, but ware to use them, often there sometimes they are actuators: is no software. When a soft- motors, heaters, voltage-gen- ware is sold or given with a erators etc. Many scientific device, it can be used only devices can be connected to a with this device or similar computer; in the past, usu- devices from the same sup-

MONDAY 14 SEPTEMBER 2015 v1—7 FUNKTECHNIKPLUS # JOURNAL P. DIEUMEGARD plier. This causes problems program for his/her aim. to professional scientists, In the present work we will as well to teachers of sci- show how to use "scientific ences, and to simple amateurs drivers" from the system Men- of sciences. Can we imagine surasoft named by the Latin programs able to manage all word mensura which means mea- of them? sure. Fig. 1 gives an illus- This problem is similar to tration of the Mensurasoft that of office software: how system architecture: separa- to make programs (spread- tion between programming for sheets, word-processors etc) devices and programming for able to manage all printers - humans is an obvious neces- not only already existing sity. printers, but also the print- ers which will appear in the The necessity of Drivers next years. The solution is The construction of scien- similar; by using device dri- tific devices is not easy. vers. There is a printer dri- Making a pHmeter is a job for ver for each printer, and we specialists, with special can make a driver for each glasses for the electrode, measurement driver. special electronics, correc- However, there are two dif- tion for temperature, etc. In ferences between office pro- the same way, building a pre- grams and scientific pro- cise scale to measure weight, grams. Scientific devices are or an accurate lux-meter are more various than printers, works of specialists. These and usually produced in small specialists can supply a pro- quantities. Scientist often gram for their devices, but must make himself/herself the not for others.

Computer measurement device driver main program

user

Fig. 1: Mensurasoft System

FUNKTECHNIKPLUS # JOURNAL v1—8 ISSUE 8 — YEAR 3 THE MENSURASOFT-SYSTEM: SOFTWARE DRIVERS FOR SCIENTIFIC DEVICES

A professional scientist On the other hand, almost needs several scientific de- all programming languages can vices. For example, in eco- use dynamic libraries, inclu- logy, we must measure accu- ding office software such as rately temperature AND pH AND Openoffice/LibreOffice, or the light: there are not programs calculation specialists for from devices makers for all example FreeMat [2], Scilab them. A teacher of sciences [3] Julia [4], R [5], and needs to show to the students tools for general programing how to make an experiment. If as Basic, /C++, Pascal, Py- there are several models of thon, Ruby, Rebol. measurement devices in the In order to use dynamic li- classroom, with different soft- braries for all scientific de- ware, the explanations will be vices, we must standardize the very difficult for the tea- functions, giving them the cher, who dreams about one same name in all the drivers. piece of software for all "Mensurasoft system" is a pro- these devices. posal for a possible stan- Drivers for measurement de- dard: the names are short and vices must be simple and easy consist of combination of let- to use, because science work- ters. ers may not have great skills in programming. They must be Fundamental functions and usable with a lot of program- additional properties ming languages, in order to Computer must receive mea- be used by many people. sures from the measurement device, and the driver needs Dynamic Libraries as a function for this input. In Drivers Mensurasoft system, the name Dynamic libraries are pie- of this input function has ces of compiled program, with the letter "e" (as "entrée" functions callable by others in French, "eingang" in Ger- programs; they are standard- man, "entrada" in Spanish, ized and available in major "entrata" in Italian and "en- operating systems: MS-Win- try" in English). This is the dows, Linux (named "shared ob- main job. jects") and Mac-OS [1]. Many If the device has an actu- programming languages can ma- ator, computer must send a ke dynamic libraries, often value to the device, in order available as , to change its state. In Men- but they must be compiled surasoft system, the name of ones, such as: C/C++, Pascal, this output function has the and some kinds of Basic. letter "s" (as "sortie" in

MONDAY 14 SEPTEMBER 2015 v1—9 FUNKTECHNIKPLUS # JOURNAL P. DIEUMEGARD

French, "salida" in Spanish). to the first channel, 1 to Inputs and outputs can be the second and so on. digital or binary if there Output functions have two are only two values as "yes/ parameters. The first is the no", "1/0", "on/off", repre- number of the channel, as for sented with the letter "b" in input functions, and the sec- Mensurasoft. They are analog ond is the value to be set by if there are a great number the device (integer or "dou- of values, for example when ble"). we measure temperature, volt- In programming languages, age or pH: in Mensurasoft, there are several ways to the letter is "a" for them. pass parameters to a function: Computers use different ty- stdcall, cdecl, pascal, and pe of numbers: integers or others. "stdcall" is more used reals ("floating"). Reals are in Windows world, "cdecl" in often coded as "double" (dou- Linux world, but this is no ble precision), using 8 bytes mandatory. In order to use (64 bits), and integers can all of them, we must put a be coded on 4 bytes (32 prefix "std" if the declared bits). When the result of an function is "stdcall" and "c" input function (or the value if the function is "cdecl". to be set by an output func- For example, in Mensura- tion) is an integer, there is soft system, the first analog no special letter, but when input channel sending a real the result or the value is a (double) is stdead(0) with "double", a letter "d" is the calling convention "std- added. call"; the second binary out- Sometimes (often) there put is stdsb(1,1) if it is are several inputs. For exam- set to "On" and stdsb(1,0) if ple, the little Arduino Uno it is set to "Off"; with has 6 analog inputs; a simple "cdecl" convention, the third thermometer only measures tem- binary input is ceb(2) and the perature at one sensor, but fourth analog output set to we could have the results ei- 3.44 is csad(3, 3.44). ther in kelvins or in Celsius That is enough for main or even in Fahrenheit system, programming languages, but thus three (3) analog inputs there are some among them are needed. So the input which want other functions. functions have one parameter Some languages accept parame- meaning the channel for mea- ters only as "double", even surement which is usually for the channel number: in- coded as integer without a stead of "d", we put "double" special letter; 0 corresponds to show that all parameters

FUNKTECHNIKPLUS # JOURNAL v1—10 ISSUE 8 — YEAR 3 THE MENSURASOFT-SYSTEM: SOFTWARE DRIVERS FOR SCIENTIFIC DEVICES and results are in double pre- a. when we do not know the cision. Some languages deals channels of the device: we with parameters and results can ask cnead(0), cnead(1), only as "strings": we can add cnead(2) and so on in order "str" at the end, and then to find out them the word stdeastr (0), for example, stands for the first b for general purpose soft- analog input. Others need spe- ware with menus and dialog cial functions (R, Scilab) in boxes: to show all analog in- the dynamic library, but they puts the is able are not included in the pre- to use a loop, asking the na- sent work. A detailed outline me of the analog input until of the naming procedure for this name is empty. functions in the Mensurasoft system is shown in Fig. 2. Additional string func- tions can be added for more Additional string comfortable use. A function functions "detail" could provide infor- mation about the device such In Mensurasoft system each as the company identity, the numerical function as already device name, the programmer's has been mentioned above has name, the date of programming its name, coded by a string etc. Even if there are not of characters. This string is parameters, the name will be a null-terminated string, as cdetail() and stddetail(). We pchar in Pascal, zstring in could also define a title fun- FreeBasic, s in PureBasic or ction, which will send a smal- LPTSTR in C++. The name of ler string, for example only the function begins by a "n" the name of the device, as: (as "name", "nom", "nomo", no- stdtitre() and ctitre(). This me", "nombre"), e.g. nead(1) small string could be useful, is the name of the second e.g., as a title in a dialog analog input. If a numerical box. function does not exist, its name is an empty string, i.e. An optional function for ca- a string whose length is 0; libration stdcalibration(ch) for example, cnead(133) is and ccalibration(ch) takes a usually an empty string, be- string as input and gives a cause normal devices have string as output. This func- only a few channels for mea- tion is useful only for spe- surement. cific devices, and the pro- These "name functions" are grammer can put anything in very useful since: it.

MONDAY 14 SEPTEMBER 2015 v1—11 FUNKTECHNIKPLUS # JOURNAL P. DIEUMEGARD

Fig. 2: Syntax of measurement function for Mensurasoft

FUNKTECHNIKPLUS # JOURNAL v1—12 ISSUE 8 — YEAR 3 THE MENSURASOFT-SYSTEM: SOFTWARE DRIVERS FOR SCIENTIFIC DEVICES

A free project rams for Windows and Linux. Dynamic libraries are well They can use three (3) chan- known, and well standardized nels, for three (3) different in programming languages. Men- drivers, make a graph of mea- surasoft is only a proposal sured values, and save the for the adoption of a stan- values in files. They can dard for the functions' names transform the measured values in order to allow all pro- by a formula (for example, to grammers to be able to use transform tension in volts dynamic libraries of others. from a pH-meter with analog Until now, all drivers and output to pH). They are mul- all application programs of tilingual by language files. Mensurasoft system are free Mensurasoft-PB [9] is writ- software. The best license ten in PureBasic. A booklet for drivers seems to be LGPL in pdf is available in French, [6], because the drivers are English, Spanish and Esperan- small programs, and the best to. Another program, Oscillo- license for application pro- PB, is very similar to Mensu- grams seems to be GPL [7]. rasoft-PB, but is designed Nevertheless, we can imagine for fast measurement, like an non-free drivers and non-free oscilloscope. Fig. 3 shows a application programs, co-op- window from Mensurasoft-PB. erating with free drivers and Mensurasoft-LZ is written applications. in FreePascal/. A book- Three frequently asked que- let in pdf is available in stions need to be answered: French, English and Esperan- to language. Fig. 4 shows an a. how to get existing drivers example of its usage in Linux illustrating the behavior of b. how to make new drivers, a common capacitor. c. how to build programs cal- ling them b. The best way to build a new driver is to modify an a. The repository of the de- existing driver found on [8]. veloped drivers for a lot of You can modify a "true dri- devices is at: ver" for a real device, or a "demonstration driver" [10]. http://sciencexp.free.fr Available drivers are in mainly in French [8], but Goog- , FreePascal and Laza- le Translate may provide a rus, FreeBasic, PureBasic, decent translation for other Oxygen-Basic, CodeBlocks, Dev languages. In this site, the- -C++, C++Builder, Visual-C++. re are also application prog-

MONDAY 14 SEPTEMBER 2015 v1—13 FUNKTECHNIKPLUS # JOURNAL P. DIEUMEGARD

Fig. 3: An example window from Mensurasoft-PB

For example, if you have a mat, Scilab, Julia, R ... new pH-meter, you can modify Small programs could also a driver only for a few func- be found at [12]. tions: stdead, stdnead, std- detail, stdtitre. After com- Conclusion pilation, you will be able to Mensurasoft system evolved use Mensurasoft-PB, Mensura- for twenty years, and works soft-LZ and others with your well, at least for slow mea- new driver, and measure pH surement, and for Linux and easily. Details of program- MS-Windows operating systems. ming is available with book- For fast measurement, like an lets in French [11], English oscilloscope, limitations are and Esperanto. due to the speed transfer of USB. A rather simple but sys- c. The booklets for prog- tematic notation of functions ramming also show how to use implemented in dynamic li- several languages to call the- braries has been adopted and se dynamic libraries: a lot successfully applied and tes- of Basic, C/C++, Pascal, Lo- ted. The same system is avai- go, Python, Rebol, Ruby, Free- lable for Mac OS, but never

FUNKTECHNIKPLUS # JOURNAL v1—14 ISSUE 8 — YEAR 3 THE MENSURASOFT-SYSTEM: SOFTWARE DRIVERS FOR SCIENTIFIC DEVICES has been tested. via a link on The author encourage those the website [8] or to share a who would like to be involved new written related applica- to this continuing effort and tion program. Do not hesitate to contribute their driver to contact the author for any for another device to the comment or related work.

Mensurasoft_LZ under Linux: Arduino Charge and discharge of a capacitor

Fig. 4: Application of Mensurasoft-LZ in Physics

References

[1] Dynamic-link library: https://en.wikipedia.org/wiki/Dynamic-link_library [2] FreeMat: http://freemat .sourceforge.net/ [3] Scilab: Scilab Enterprises, http://www.scilab.org/ [4] Julia: http://julialang.org/ [5] R: http://www.stats4stem.org/ r-math-functions.html [6] GNU Lesser General Public License: https://en.wikipedia.org/wiki/GNU_Lesser_General_Public _License [7] GNU General Public License: https :// en.wikipedia.org /wiki/GNU_General_Public_License

MONDAY 14 SEPTEMBER 2015 v1—15 FUNKTECHNIKPLUS # JOURNAL P. DIEUMEGARD

[8] Sciencexp - the site of the Experimental Sciences: http://sciencexp.free.fr [9] Mensurasoft-PB: http://sciencexp.free.fr/index.php?perma=Mensurasoft-PB [10] Pilot demonstration: http://sciencexp.free.fr/index.php? p p erma=pilotes_demonstration [11] Mensurasoft: drivers of measurement devices and actua- tors system under MS-Windows and Linux: http://sciencexp.free.fr/index.php?perma=Programmation [12] Demonstration applications: http://sciencexp.free.fr/index.php? perma=Ap plications_demonstration

Previous Publication in FUNKTECHNIKPLUS # JOURNAL

None

* About The Author

Pierre Dieumegard , was born in Limoges, France, in 1955. He teaches biology, geology and computer science in Lycée Pothier in Orléans, France. Since his thesis in plant genet- ics (1984), he started to use computers. After that, for many years, he was involved in research on the use of com- puters in science education.

[email protected]

FUNKTECHNIKPLUS # JOURNAL v1—16 ISSUE 8 — YEAR 3