## Mtinkd

Mtinkd is a little server which allow to use the status monitor mtink or ttink while a job is printed.
Mtinkd work only with EPSON printers which support the EPSON-D4 protocol. The first devices supporting this protocol was probably the Stylus Color 740 and the Stylus Scan 2000/2500.

#### Content:

Syntax
Printing with mtinkd
Configuration of start script
Call of ttink
Call of mtink
Start of mtinkd at boot time
Theory of operation
Bugs
See also

#### Syntax:

mtink [start|stop|status] -dev <device file> [-nodaemon] [-model <model name>] [-name <modelname] [-usbbase <path and device file base>] [-debug] [-L]

Special option for the SYS V start / stop scripts
start |  | The server will be started. start may be ommited
stop |  | An running server will be stopped
status |  | This allow to ask if a server is running.
Normal options
-dev | device file | This option is mandatory and is also used in order to get the status or to stop a running server. Device file is the name of the character device on which the printer is attached (/dev/lp0, /dev/usb/lp0, /dev/ecpp0, ...)
-nodaemon |  | This option is for test purpose, without this option mtink start in the background.
-model | model name | If the printer don't return it identity you may tell which printer is attached. The name is derived from the official name and space characters are to be replaced by the "_ " character. This will be the case for the Stylus Scan 2500 (model anme isScan_2500). This option may also be usefull for multifunction device as the Stylus Photo 895 under Linux. If the printer is powered off and then on, the usb kernel will not detect the printer properly and mtinkd must be at least stopped and started again.
-name | name | The name of the named pipe will be set according to this name. If the -model option is not given, mtinkd will terminate if the identification returned don't comply with passed name
-usbbase | path and device file base | ONLY FOR LINUX This option require a special system call which is only implemented into newer kernels. The -type <name> option is required ! path and device file base may be /usr/usblp or /usr/usl/lp. All device files matching whith the passed name will be scanned for the wanted printer, the device file will then be used later. If the kernel don't support the special call, scanning will fail and if the -dev <device file> option was given, the given device file name will then be used.
-debug |  | print out a few debug messages
-L |  | debug for D4 protocol

#### Printing with mtinkd

The usb or parallel ports can't be used by more as one process at the same time. Mtink supply a named pipe for this purpose and you will have to reconfigure the print service accordingly.
The named pipes are all installed under the directory /var/mtink. The file name is derived from the device file name and path.

Example of file name
Device file | Named pipe name | Remark
/dev/lp0 | /var/mtink/lp0 |
/dev/usb/lp0 | /var/mtink/usb_lp0 | The "/" is replaced by a "_"
/dev/printer/0 | /var/mtink/printer_0 |
Name given with -type |  |
Photo 890 | /var/mtink/Photo_890 | The " " are replaced by "_" characters
If you configure your print systeme you must choose the file /var/mtink/xxx. If you don't use cups you must make sure that the print system will not write at the same time on the named pipe ! #### Call of ttink Normally you have to call ttink with for example the option -d /dev/lp0. If you use the mtinkd server you must launch ttink with the option -d /var/mtink/lp0 #### Call of mtink Mtink can be called as usual. If the choosed device is locked, mtink will allow you to choose the /var/mtink/* files. #### Theory of operation Mtinkd and mtink / ttink communicate via shared memory. The shared memory will be created by the server process and this memory has a key which is calculated from the file name /var/mtink/<name>. The print jobs are to be send to the file /var/mtink/<name>. If datas are recognized by mtinkd on this file, these datas are packed into the D4 protocol and sent to the printer via a data channel. Queries or commands from mtink / ttink are written into the shared memory and send via the D4 control channel. Both channel data and control channel are independant so you will be able to get information while a print job is running. In order to prevent problems, only one frontend (mtink or ttink) can attach it to the server mtinkd. Linux specific: Powering the printer on / off / on will normally be handled by mtinkd however the usb driver may be the cause of problems id the attached device contain more as one device as printer and storage. In this case you will have to stop the daemon and restart it. If this don't help you must delete the printer module and insert it again. #### Start of mtinkd at boot time In order to allow an easy integration of the daemon to different systems the options start, status and stop was added to the daemon mtinkd. This allow a dramatic simplification of the start script. An example script is provided in the source subdirectory etc:
    # define the device file, adapt this
    #DEV_FILE=/dev/usb/lp0

    # Special options, adapt this

    SPEC="-name $NAME -usbbase /dev/usb/lp"

    # where the program is located

    PROG=/usr/local/sbin/mtinkd

    case $1 in
        start|stop|status)
    	names=""
            if [ -f /etc/mtinkd.conf ]
            then
               while read opt1 name opt2 dev; do
                  if [ $opt1 = -name ]
                  then
                      echo -n "$1 `basename $0` for $name "
                      if $PROG $1 $opt1 $name $opt2 $dev
                      then
                         echo RUN
                      else
                         echo STOP
                     fi
                  fi
               done < /etc/mtinkd.conf
            else
    	   for f in /dev/usb/lp* /dev/lp; do
    	       name=`askPrinter $f | grep '[:,]D4[,;]' | sed -n '/Stylus/s/.*:EPSON Stylus \(.*\);/\1/pg' | tr ' ' '_'`
    	       if [ ! -z $name ]; then
    	           echo -n "$1 `basename $0` for $name "
                   	   if echo $f | grep usb > /dev/null; then
    	              $PROG $1 -name $name -usbbase /dev/usb/lp
                       else
                          $PROG $1 -name $name -dev $f
                       fi
                       if [ $? -eq 0 ]
                       then
                          echo RUN
                       else
                          echo STOP
                       fi
    	       fi
    	   done
            fi
    	RETVAL=$?;;
       restart)
    	$0 stop
    	sleep 2
    	$0 start
    	RETVAL=$?;;
       *)
    	echo "Syntax `basename $0` start|stop|status|restart"
    	RETVAL=1;;
    esac

Please take in account that the you need a server for each EPSON printer, if you have the luck to own more such devices.
In this case you will have to provide start/stop scripts with different name, for example mtink.lp0 mtink.usblp0 and correct the line DEV_FILE=/dev/usb/lp0 in the script.

#### Warning

The server is not able to detect printer from other manufacturers and using this server with an unsupported printer may cause garbage.

#### Configuration of start script:

Under Linux the script /usr/sbin/mtink-installInitScript generate all necessaries links in the /etc/rc.d/* directories and generate the configurations file /etc/mtinkd.conf. The printer must ne attached on the computer and powered on while launching mtink-installInitScript.

#### Bugs

Probably a lot.

#### See also

mtink
mtinkc
ttink
gimp-installInitScript

#### Author:

Jean-Jacques Sarton
jj.sarton@t-online.de
http://xwtools.automatix.de