Novell is now a part of Micro Focus

HowTo: Create a Factory Rejects Data Recording system Part 1

Novell Cool Solutions: Feature
By Stomfi

Digg This - Slashdot This

Posted: 23 Feb 2005

StomfiLearning to use Linux at Home and Work
Welcome to my ongoing series of HowTo articles designed to help Linux newbies get comfortable with Linux. Before trying any of these HowTos, take a few minutes to study the prerequisites so you can hit the ground running.

This HowTo explains the creation of a turn key system for collecting and analysing factory reject data. First, a conventional data entry system using collected hand-filled-out forms will be developed and tested. Second, a factory floor point of origin data entry system using conventional keyboards and screens will be developed, using the previous data collection files and analysis system. Third, a replacement wireless pocket-sized handheld data entry and read-out device to replace conventional keyboards and screens with a multi-unit base station will be designed.

Runtime Revolution and the Linux shell tools are the tools used to develop and create this system without requiring any specialised programming skill. Reading HowTos and Linux manuals is as heavy as it gets. When using RunRev you'll find it works best in the Gnome desktop.

The use of Linux has let this system be developed. Any other solution platform would put the cost way out of the reach of small businesses for whom it was designed.

To simplify things, each program module has been developed as a separate RunRev program stack, although RunRev has the ability to combine several stacks into one program. We shall have a look at this aspect at the end of the first development.

Take advantage of the special offer from Runtime Revolution especially for Cool Solutions readers. (Free!)

This is the program stack window which calls the other stacks. It is named "RejCtl"."

We shall now have a look at the script for the new rejects button.

on mouseUp

put ($HOME & "/frejects/bin/newrejects") into REJPROG

replace return with empty in REJPROG

launch REJPROG

end mouseUp

See that we have a folder in our HOME folder called "frejects" with a sub folder called "bin". In "bin" there is a file called "newrejects". This is a RunRev program. The "rejctl" program also lives there. When we click the New Rejects Entry Screen button, this window appears. This is the first of two windows. This one allows data entry personnel to select a work area, an operator, and a product by scrolling down a list and clicking a selection. The selection appears in the relevant space. When all three selections have been made, the "COUNT" button is active. This window is called "rejhead".

Clicking the "COUNT" button replaces that window with one called "rejcount". As you can see in this window, the three selections have been carried across.

The date has been automatically filled in for today. This may not be the date on the entry form so we will have to create a way to modify this, which we shall do later on.

The same method of scrolling and clicking lets us select a reject reason and a quantity from 1 to 20. Selecting these two parameters activates the "DONE" button, which write the new record to a text file.

The date is in English D/M/YY format. RunRev puts the date in USA format which is handy when using Linux as you can convert a USA date into the number of seconds since the UNIX epoch began on 1/1/1970. Comparing epoch seconds is an easy way of comparing dates for data analysis.

When the "DONE" button saves the data it also saves the epoch seconds, so we can use this later in the charting program.

Now I will show you the scripts so you can see how this bit is constructed. Any of you who are unfamiliar with Runtime Revolution should read the HowTos on the Poems database for an excellent primer. Of course the help in RunRev is so good you can probably jump right in, and look up key words in the Transcript Dictionary in the RunRev help.

The first script is the openCard script. This clears out the selected product field and sets up today's date in English format and puts the converted date and epoch seconds in a hidden field, into fields in the "rejcount" card.

The shell script to convert the date into English format is called "" and the one to convert the date into epoch seconds is called ""

Here they are:

#!/bin/bash DATE


#convert US date to AUS date

AUSDATE=`echo $1 | awk -F"/" '{print $2 "/" $1 "/" $3}'`

#!/bin/bash DATE


#convert to epoch seconds for charting date ranges

EPOCH=`date -d $1 +%s`

echo $EPOCH

The scripts for the selection lists are shown next. You will find that changing the Work Area changes the list of products associated with that work centre. I think that this is a case where the shell really shows off its ease of use.

This is the script for the "WorkArea" list field. The shell script "" works out what products to put into the "Products" list field.

on mouseDown

global SELWORK

put the selectedText of me into SELWORK

put SELWORK into field "SelWorkArea"

put ($HOME &"/frejects/bin/ " & SELWORK) into ProdList

replace return with empty in ProdList

open process ProdList for read

read from process ProdList until EOF

put it into field "Product"

close process ProdList

end mouseDown

Here is the "" shell script.


# workarea



case $1 in

CASTING) awk -F# -f $BINDIR/prodsel4.awk $HOME/frejects/lists/products.txt ;;

MACHINING) awk -F# -f $BINDIR/prodsel5.awk $HOME/frejects/lists/products.txt ;;

LINISHING) awk -F# -f $BINDIR/prodsel6.awk $HOME/frejects/lists/products.txt ;;

PLASTICS) awk -F# -f $BINDIR/prodsel7.awk $HOME/frejects/lists/products.txt ;;

NONE) awk -F# -f $BINDIR/prodsel1.awk $HOME/frejects/lists/products.txt ;;


The case construct tests $1 (which is the supplied work area) and runs one of five awk scripts to give the resulting list of products. The last one gives a list of all products. This is the "prodsel4.awk" script.

{ if ($4 !~ "No" ) { print $1 }}

And this one line from the "products.txt" file, which is a list of all the products made in the factory.

100mm female half 4inch#QIS#QISQF4QISJAX#Yes#No#Yes#No

Those four "Yes or No" fields at the end of the line tell us which work centres do work on this product.

These are the scripts for the operator and products lists:

on MouseDown

put the selectedText of me into field "SelOperator"

end mouseDown
on MouseDown

put the selectedText of me into field "ProdSel"

end mouseDown

The list fields have their properties set so that they can act as lists thus:

These are the scripts for the buttons COUNT and FINISH:

on mouseUp

global SELWORK

global SELOP

global PRODSEL

if field "SelWorkArea" <> empty and field "SelOperator" <> empty 
and field "ProdSel" <> empty


put field "SelWorkArea" into SELWORK

put field "SelOperator" into SELOP

put field "ProdSel" into PRODSEL

put empty into field "SelReject" of card "RejCount"

go card "RejCount"

end if

end mouseUp
on mouseUp

put ($HOME & "/frejects/bin/") into BUK

open process BUK for read

read from process BUK until EOF

close process BUK


end mouseUp

This is the "" shell script:



#save and replace newrejects.txt




#if size of NEW > 10 we got some new records


if [ ${#NSIZE} -gt 10 ]






We will modify this script in a later part of the HowTo when I show you how to securely copy this file to a networked MS Windows machine.

The next screen is the reject count data collection screen as shown above.

on openCard

global SELWORK

global PRODSEL

global SELOP

put SELWORK into field "SelWorkArea"

put PRODSEL into field "ProdSel"

put SELOP into field "SelOperator"

put ($HOME & "/frejects/lists/" & SELWORK & ".txt") into RejList

replace return with empty in RejList

open file RejList for read

read from file RejList until EOF

close file RejList

put it into field "Rejects"

global NewRejFile

put ($HOME & "/frejects/database/newrejects.txt") into NewRejFile

replace return with empty in NewRejFile

open file NewRejFile for append

end openCard

This is what the RejList looks like for the SELWORK "CASTING"









Notice that the newrejects.txt is opened for append but not closed in the openCard script.

This is the script for the reject type field.

on mouseDown

put "New Record" into field "Response"

put the selectedText of me into field "SelReject"

end mouseDown

This is the count field script.

on mouseDown

put the selectedText of me into field "RCount"

end mouseDown

This is the script for the DONE button.

on mouseUp

put "Writing Record" into field "Response"

global SELWORK

global PRODSEL

global SELOP

global NewRejFile

put field "Date" into TDATE

put field "epochsecs" into ESECS

if field "SelReject" <> empty and field "RCount" <> empty


put field "SelReject" into REJ

put field "RCount" into RCNT

#This next is all on one line.

put (SELWORK & "#" & PRODSEL & "#" & TDATE & "#" & SELOP & "#" & 
REJ & "#" & RCNT & "#" & ESECS) into REJLINE

replace return with empty in REJLINE

put(REJLINE & return) into REJECT

write REJECT to file NewRejFile

put empty into field "SelReject"

put empty into field "RCount"

put "Record Written" into field "Response"

end if

end mouseUp

Notice that this script writes to the newrejects.txt file which was opened for append.

And finally this is the script for the BACK button.

on mouseUp

global NewRejFile 

close file NewRejFile

go card "RejHead"

end mouseUp

Notice that this script is the one which closes the newrejects.txt file. There is a problem with this approach in that if the power goes off while the file is open, there could be a corruption problem. We can generally expect Linux to handle this but if you think that there may be problems you can open and close the file each time you do a write, although this can slow things down on a slower computer.

All that's left to do is to compile the project. There are two stack so far; although you have only been shown the New Rejects button script in the rejctl stack, this will do. Save and close the newrejects stack and open the rejctl stack. In the file menu select Standalone Application Settings. In the Stacks tab, add the newrejects.rev stack. Click the x to quit this window. In the File menu select Save as Standalone Application and build it in the frejects bin directory. The program will be what you called it ( e.g. rejcontrol) and its folder will include the newrejects.rev file. When you run the program it will open this file when you click the button. The file is only 2M plus the small amount for the .rev file.

In part 2 of this howto we shall develop the stacks for administering the products, as shown on the rejctl stack window.

For more information about Runtime Revolution visit

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates