The magazine of the Melbourne PC User Group
The Mysteries of n1 and
n2
Major Keary
|
 |
Epson and compatible printers require for several kinds of code, inclusion of values that the user has to calculate. Usually they are referred to as
n1 and n2.
Printer manuals must be amongst the most unhelpful documentation in the computer and peripherals market. If there is any explanation at all of
n1 and n2, it is likely to be obtuse. For example:
"
To find n1 and n2, first calculate the displacement required (n dots) and then, if it is to the left, subtract it from 65536. The values of
n1 and n2 can the be calculated from the formulae:
n1 = n MOD 256
n2 = Inn/256)".
|
Well, did you get all that? It is made even more confusing when the dimension of a printer dot can vary, the width of a column position can vary, and the same formulae are used in relation to bit image data.
MOD and INT are operators used in Basic. They are abbreviations for modulus arithmetic and integer division respectively. If you don't know about that, join the club. It is a case of a simple concept being made unnecessarily complicated. An example of a typical application will illustrate just how easy it is.
On some printers (for example, the Epson LQ series) it is possible to move the print head to a predetermined position. The Epson code is
Esc $ n1 n2. The desired position is measured in dots from the left margin and each dot (in the case of the Epson LQ series) is 1/60 inch wide. Thus, a position 1 inch from the left margin is 60 dots.
Suppose we want to position the printhead 2.25 inches from the left margin. That is a distance of 135 dots. Now we perform a most complex mathematical computation. Divide 256 into 135. Answer? Zero with a remainder of 135. And that gives us the values of
n2 and n1 respectively. Notice they are back to front. So our code will be
Esc $ 135 0, or in hex: 113 24 87 00.
Another example. We want to move the print head to a position 5 inches from the left margin. 5 X 60 = 300 dots. Divide 300 by 256 (300/256), which is 1 with a remainder of 46.
n1 = 46 and n2 = 1. The code would be Esc $ 46 1 or IB 24 2E
01 hex.
Setting an absolute printhead position is useful for lining up columns when in proportional print mode. Some wordprocessors convert tabs to spaces which can cause problems to proportional printing. It is also very useful for vertical alignment of segments of
graphics design. For example, a graphics image 1 inch x 1 inch is designed. It has to be printed in layers, so it is necessary for the printhead to be positioned accurately at each pass.
Bit image mode also calls for n1 and n2 values. In that case the information does not relate to measurement of print head travel, but to the number of data.
Remember, in computerspeak numbering starts at zero.
Working out code for bit image graphics is another subject, but it is necessary to know how to arrive at
n1 and n2. Epson codes for bit image modes require information about the number of data. Each piece of data tells the printer which pins to fire at each print head position. The
n1 and n2 values tell the printer how many pieces of data are to be received. The reason is that any data following is treated as an ordinary code, or ignored. It prevents additional, unwanted code getting mixed up with the bit image data
There are various kinds of bit image mode, but all require n1 and n2 values. If, for example, there are 520 pieces of data,
n1 and n2 would be derived thus. 520/256 = 2 with a remainder of 108.
n2 = 2 and n1 = 108.
Why not send 520 to the printer'?, you ask. Well, the printer microprocessor is built with eight bit architecture. That means a single byte cannot represent a decimal value of more than
255. The first value tells the printer to move the head 108 dots and the second value tells it to move the head in increments of 256 dots. But, as Sir Joh is wont to say, don't you worry about that. The important thing is to know how the
n1 and n2 values are found.
It's kid's maths, but even Einstein might have had difficulty comprehending some printer manuals.
Reprinted from the Jan/Feb 1992 issue of PC Update, the magazine of Melbourne PC User Group, Australia
|