
marsh:  mas-345 (and other multimeters) read and store (hopefully)


This is a small program designed to connect to a MAS-345 or a
Digitek-4000 multimeter through an RS-232 port.

Both devices are 3+3/4 digits mm manufactured under several brand
names and sold below 50$; they are not precision instruments, but come
handy to monitor a current, voltage, resistance and so on, with
reasonable accuracy.

The program can control up to four mm at a time (recompiling, up to 32),
read data at a given cadence, perform some computations online (using
the 'bc' facility) and save data and results to a file.
The program  is suitable also as a front-end for other applications.

The program has been tested in a GNU/Linux environment (Debian Sarge,
kernel 2.6.8); it needs standard Unix tools for compilation (C compiler
and libraries) and the 'bc' application if online calculation is
required.

Compile with "gcc -Wall marsh.c -o marsh" or "make marsh" and run "./marsh".

With "./marsh -h" you can see the available options:

 -l <string> : the RS232 line the mm is connected to; default is 
               /dev/ttyS0. You must have permissions to use the
               line, otherwise you get an error message. 
               As root, give: "chown $USER:$USER /dev/ttyS0".
 -m <string> : select one more line to which one more mm is connected.
               By default it is possible to use up to four mm at a
               time. By changing the MAX_PORTS definition in the
               source code it is possible to use up to 32 mm.
 -j <char>   : select the mm model. By default the first device is 
               a MAS-345 (change DEFAULT_DEVICE and DEFAULT_MODEL
               in the source code, if you don't like it); you can
               select another model with this option and change the
               selection after every -m.
                  -j m : MAS-345
                  -j d : Digitek-4000
 -i <float>  : time interval (in seconds) at which readings are taken.
 -r <int>    : measure repetiton count. The program gets these many
               readings, then exits. "-r 0" starts an endless loop;
               stop it with Ctrl-C. "-r 0" is the default.
 -s          : add time stamp to readings as "YYYY-MM-DD  HH:MM:SS.SS".
 -t          : add indication of elapsed time since start of operations.
 -o <file>   : write output to a file.
 -f <file>   : write output ***only*** to a file.
 -c <string> : add a comment string at the beginning of the file.
 -e <string> : perform computation on mm data using the bc calculator.
               A string is sent to bc with variables m0, m1, m2 ....
               assigned the values read from mm 0, 1, 2 ....
               Then the command string you specify is appended.
               e.g.: -e "m0-m1" takes the differences between readings
               from mm 0 and mm 1.
 -p <string> : a preset command to be sent to the bc calculator before
               any other request. With, e.g., -p "s=100" you can preset
               the variable s to the value 100; then, with -e "s=s+m0;s"
               every new reading is added to s and the total is printed.
               Quite useful: -p "scale=6" (see man bc for the reason why).
 -d          : activate debug messages that explain what is going on.
               More d's, more messages (up to -ddd).
 -z <float>  : modify the timeout for the multimeter operation (def.: 2 sec).
 -h          : short help on line.


Some examples:

1 (easy):
---------
./marsh
    OH  11.13MOhm
    ......

The default device (MAS-345) is connected to the default port (/dev/ttyS0)
and the default reading is taken with default cadence etc.


2 (not so easy):
----------------

./marsh -l /dev/ttyUSB0 -s -m /dev/ttyS0 -j d -o data -e "m0*m1" -p "scale=3"
 2006-02-09  21:53:19.10   OH  102.9 Ohm     787. uA DCa0  80982.3
  ............

The default device (MAS-345) is connected to line /dev/ttyUSB0
(-l /dev/ttyUSB0); time stamp is added to output data (-s); another
device is connected to line /dev/ttyS0 (-m /dev/ttyS0) and this device
is a Digitek-4000 (-j d); data are sent to file 'data' (-o data) and
written to terminal; the product of the two readings is taken
(-e "m0*m1") with 3 digits accuracy (-p "scale=3").


Some information about the MAS-345 and Digitek-4000 protocols
(many thanks to Giovanni Aloisi who installed the official software
in his Windows machine and helped me a lot in finding the correct
parameters).

MAS-345
=======
data format: 7n2 at 600 baud (7 bits, no parity, 2 stop bits).

Control lines:
   DTR and RTS lines are used to power the TX line: RTS is clear
   for -12 supply; DTR is set for +12 supply. Data transmission is
   solicited sending whatever character to the RX line.

Data string format:
   MAS-345 sends a 14 bytes string with:
         <mode>< ><sign><value>< ><units><return>
   <mode>:  two bytes with the oerating mode: DC, AC, OH, CA, TE ...
   <sign>:  one byte with - or space
   <value>: five bytes with four digits and one decimal dot.
   <units>: four bytes with the units: mV, A, kOhm, nF ...
   <return>: '\r'
   One space is inserted between <mode> and <sign>, one between
   <value> and <units>.
   The data string (without the '\r') is sent to the output device.

Digitek-4000
============
data format: 8n1 at 2400 baud.

Control lines:
   DTR line is used to start/stop the transmission. RTS is clear.

Data string format:
   Digitek-4000 sends a 14 byte string, each byte containing the
   upper four bits with a progressive code and the lower four bits with
   a map of the display: one bit for every segment in the digit display,
   one for the decimal dot, the sign and the auxiliary indications: A, V,
   kohm etc. If you are interested in the map, look at the source file.
   The string is converted to:
            <value> <units> <mode>
   <value>: six chars with four digits, the decimal dot and sign (or space).
   <units>: four chars with the units: mV, uA, kohm ...
   <mode>: four chars with AC/DC+a/m+0/1/2/3, meaning:
              AC/DC: just that
              a/m: autorange/manual
              0/1/2/3: 0/1=Hold + 0/2=Relative
   One space is inserted before and after <units>.


marcello carla'
carla@fi.infn.it
