One of the requirements of this project is to control the bar code machine.
The first requirement is that the bar code can be printed. The second is that the Chinese name of the dealer can be printed and a bitmap logo can be printed.
The test environment is Windows 2000, XP, 2003, and zebra z4m plus.
Because I have never done a bar code machine before, I thought it was easy at first and thought I should have done it through the print driver.
At the beginning of the encoding test, it was found that the printer driver controlling zebra can indeed be processed according to the conventional printer, but there are two defects.
First, the position and effect of the printed content are not accurate. Second, the printing speed is not good.
In addition, the customer has several different models of machines to install the corresponding drivers one by one. This is indeed a headache.
So I tried to directly control the bar code machine through the serial port.
The zebra series has built-in custom zpl communication command set.
In fact, this is almost the standard currently supported by mainstream brand models.
Many specific zpl commands provide unlimited control over all aspects of the bar code machine.
ManyArticleI will not go into details about the usage of commands.
For more instructions, refer to the zebra command manual.
I. bar code printing
Bar Code machine printing is very simple
Generally, Commands include setting the label size, bar code location, bar code size, bar code type, and specific bar code content.
Example:
^ XA ^ lh0, 0 ^ fo130, 44 ^ fo20, 25 ^ by4 ^ fo100, 100 ^ BCN, 104, Y, N, N ^ FD>; 0123456789 ^ FS ^ pq1 ^ xz
Note:
This command sequence will print the one-dimensional Digital bar code of code 128 standard 0-9
Ii. Chinese Printing
As mentioned on the Internet, you can use a library named fnthex32.dll to export a getfonthex function.
The function is to convert the passed Chinese string to hexadecimal encoding and return this library. It is not very good to find it online. After I finish the project, I am lucky to find
It should be convenient to use it. However, if the project has been completed and no bar code machine has been tested, you can try it.
3. graphic printing
The getfonthex function mentioned above does not know whether it is also a personal conjecture for converting Chinese characters into image encoding.
In fact, the bar code machine should print non-standard characters and graphics in the same way.
The focus of graphics processing is to encode the image and add instructions to send it.
The encoding method is very simple. It is very similar to the encoding of Dot Matrix Chinese character libraries on the Chinese platform under DOS.
That is, a vertex uses a single bit to indicate that each byte describes eight vertices first and then columns from top to bottom.
That is to say, the bar code machine can only print binary images.
During encoding, it should be noted that if the byte is not filled at the end of each line, it should be expanded up to the whole byte (with 0)
It is easier to process the encoding method.
I personally think it is not flexible to have solutions on the Internet to extract dot matrix data directly from the Dot Matrix Chinese font.
First, the dot matrix font is too large to be released. Second, the text size is limited.
My implementation method is to directly use the API to draw the font and size of Chinese characters such as Chinese characters into the memory bitmap, which can be easily controlled.
Then scan the dot matrix information and encode it to generate the final data.
For example, if it is determined that the image is painted in white and black, the white text is regarded as 0 black spots as 1.
The final generated data needs to be downloaded to the bar code machine cache in graphical form.
Specify to use this image for output.
In addition, you must note that the image cache name and the total number of bytes of the image and the number of bytes of each row must be specified with several parameters to download the graph command ^ DG.
These two numbers need to be calculated and then added to the command string.
Calculation Method of the total number of bytes:
(Drawing width * DPM/8) * (drawing height/8)
DPM is the resolution, that is, the number of points per millimeter (dots per mm)
Calculation Method of the number of bytes per line:
(Image width/8)
The ratio is 664x40 DPM is 8 (usually this value)
The total number of bytes = (664*8/8) * (40/8) = 3320 bytes
Number of bytes per line = (664/8) = 83 bytes
Example:
^ XA ^ lh0, 0 ^ IDR: *. * ^ xz ~ Dgimg0, 3320,83,... (encoded data)... ^ pq1 ^ xz
Note:
This command downloads the encoded graphic data to the bar code machine and saves it to the cache region with the alias img0.
Then use the ^ XG command to reference the image.
//*******************
// Notes:
//*******************
I. Resolution
If the resolution is not the standard 8dpm, the zebra z4m plus is tested to process the data. Sometimes, an error occurs.
It works perfectly on the S series.
I hope it is my method orCodeProblematic
Ii. processing speed
The speed of sending data through the serial port is slow. It takes about 3320 seconds to print 0.5 bytes of data.
Fortunately, the tag size of this project is not large enough to be within the acceptable range.
If you have higher speed requirements, consider using parallel ports.
The USB port may be faster, but I don't know if the method is common.
Here we only record the poor memory of the applications involved. When there is a similar development, we can find a case to avoid getting it from the beginning.
I hope it will give some bad inspiration to my friends who are new to getting started and need to handle bar code machine applications.
Welcome to the study: scumyang@163.com
Scum
2006-08-07