File-Interface-Script






2.53/5 (6 votes)
Dec 2, 2004
3 min read

33390

696
Script-interpret-class with comfortable editor and debugger
Introduction
The idea of this project came by my last assigned task in a company which has to manage multiple file-interfaces. My job in this case was the reorganization and simplification of the historical grown structures of different classes. A big problem was that the technical personnel, who made the installation and servicing by the customers, had to send firstly the most new interfaces to the development to check if a compatible module exists. If not, the developers had to adapt an existing or completely develop a new one. When I began to deal with this matter, it was quick obvious to me, that a small script-language would be the best solution. So I began to plan and develop the project (in those days in C++/MFC). After a successful presentation I got a very positive reflection, because all file-interfaces could now be managed by one module. Also the technical personnel could handle all file-interfaces by themselves because there are only 13 different methods needed for and the contained editor and debugger are very simple and comfortable tools.
For quite some time I am developing now in C#/.NET and that's the reason why I am searching for a reference-project which I can publish. So I decided by myself to revise and develop this base-idea. The most important part by this project was to show multiple techniques and that is why some things could surely be realized by other or easier ways.
The crucial class is named as "clsFIS" and can completely be extracted. It doesn't need the editor- or debugging tool to run and the whole source-code is sufficient documented. So it shall be easy to implement the class in the own application.
Background
The script-class is a useful tool to read values from a file-interface. The first task of the “script” is to position the internal interface-pointer on the first character of the relevant value. After the interface-pointer is positioned the value can be read. The relevant number of characters which will be read can be given by a fix length or by the separator which defines the end of the value. Also a processed-mark can be set to prevent that this value will be read twice a time.
Example 1: (Interface with fix column length)
In this example the X-Value and the Width-Value will be sent
Interface: ---------------------------------------------------------------
--------------------------- Header ----------------------------
---------------------------------------------------------------
-NAME SOLL VALUE TOL ME ARTIKEL MARK -
---------------------------------------------------------------
X: 12.3456 12.3456 0.0020 mm 0987654321 VV1200321Y
Y: 22.3456 22.2201 0.0020 mm 0987654321 VV1200322Y
Width: 128.00 128.00 0.9000 mm 0987654321 VV1200326Y
Height: 7.00 7.00 0.9000 mm 0987654321 VV1200327Y
Script: EmptyLines(5); /// Header;
/// Reading the X-Value and the Width-Value;
Fix(18); SendValue(10,”X: ”); NextLine;
EmptyLines(1);
Fix(18); SendValue(10,”Width: ”); NextLine;
Result: The following values will be sent: “X: 12.3456 ”
and “Width: 128.00 ”
Example 2: (Interface with separators) This example read a value from an interface which uses a ‘;’
- separator and the 5th value will be read
Interface: KK3276;1.001;234;;767.01;ZU1
KJ123;12.1;235;12;65.13;ZU2
Script: Separator(4,@59); SendValue(@59,”VAL1: ”);
Separator(4,’;’); SendValue(‘;’,”VAL2: ”);
Result: The following values will be sent: “VAL1: 767.01”
and “VAL2: 65.13”
Example 3: (Constant increasing interface) This example shows how to use the process-mark. The “Width”-value has to be read.
The processed-mark is already be set in the first value-block and therefore
the SendValue-method doesn’t send this value.
After sending the “Width”-value of the second block the processed-mark will be
inserted in the interface-text on the position which is defined by the PM-function.
Interface: ---------------------------------------------------------------
--------------------------- Header ----------------------------
---------------------------------------------------------------
-NAME SOLL VALUE TOL ME ARTIKEL MARK -
---------------------------------------------------------------
X: 12.3456 12.3456 0.0020 mm 0987654321 VV1200321Y
Y: 22.3456 22.2201 0.0020 mm 0987654321 VV1200322Y
Width: 128.00 $128.00 0.9000 mm 0987654321 VV1200326Y
Height: 7.00 7.00 0.9000 mm 0987654321 VV1200327Y
---------------------------------------------------------------
X: 12.3456 12.3423 0.0020 mm 0987654322 VV1200321Y
Y: 22.3456 22.2344 0.0020 mm 0987654322 VV1200322Y
Width: 128.00 128.21 0.9000 mm 0987654322 VV1200326Y
Height: 7.00 7.01 0.9000 mm 0987654322 VV1200327Y
---------------------------------------------------------------
Script: /// PROPERTIES;
ChangePM(@36); /// Changes the PM-character
ChangeEndlessLoop(1); /// Activate the endless-loop
EmptyLines(5); /// Header;
/// Start reading the blocks;
EndlessLoopStart;
EmptyLines(2);
Fix(17); PM(1); Fix(1); SendValue(10,PM1,”Width: ”); NextLine;
EmptyLines(2);
Result: The following value will be sent: “Width: 128.21 ”
Points of Interest
The properties clearness and readability are important for my own source-codes, because I developed a long time in C++. For all who have their first contact with C#-code will agree that the code-structure looks strange. Therefore I am formatting my code in the following way:
//*************************************************************************** //************************ METHODS ******************************** //*************************************************************************** #region *** public void Method1() *** #region Comment *** public void Method1() *** /// /// Description /// /// Parameters /// #endregion public void Method1() { ... ... } #endregion //****************************************************************************
If you activate the special option in your Microsoft Visual C# .NET-Studio all codes in the #region-blocks will be reduced to single lines (when the file will be opened) and you have a similar outfit like C++ -header-files. To format the source-code automatically I developed a macro which I will be publishing here next time.
//********************************************************************************* //*************************** METHODS *********************************** //********************************************************************************* *** public void Method1() *** //********************************************************************************* *** public void Method2() *** //********************************************************************************** *** public void Method3() *** //**********************************************************************************
Of course it is a matter of taste, but in my opinion very helpful.