How to print connected character in verifone vx520

2019-09-02 17:32发布

问题:

I want to draw a line in printed paper like _____ and the picture below is my font bitmap

and I use this code to download and select my font to printer and print characters

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <svc.h>
#include <printer.h>

int main() {
    int retVal;
    int handle;
    open_block_t parm;
    int h_font_file;
    char print[32] = {43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43};

    handle = open("/dev/com4", 0);

    memset(&parm, 0, sizeof (parm));
    parm.rate = Rt_19200;
    parm.format = Fmt_A8N1 | Fmt_auto | Fmt_RTS;
    parm.protocol = P_char_mode;
    parm.parameter = 0;
    set_opn_blk(handle, &parm);
    SVC_WAIT(200);
    p3700_init(handle, 6);
    SVC_WAIT(100);

    /****************SETUP FONT******************/
    h_font_file = open("8x16.pft", O_RDONLY); //load font
    retVal = p3700_dnld_font_file(handle, h_font_file, 2); //set font
    SVC_WAIT(100);
    retVal = p3700_select_font(handle, 0x03, 2);


    retVal = write(handle, print, 32);

    printf("printf: %d\n", retVal);

    retVal = write(handle, "\n\n\n\n", 4);

    SVC_WAIT(100);

    return 0;
}

but the result is the image below and the characters don't connected together. How can I fix this problem?

回答1:

If all you want to do is print a horizontal line, then I think creating a new font is probably not the way to go. Instead, consider making a graphic that is just a horizontal line and printing it like any other graphic.

You can also try putting the terminal into graphics mode and drawing it manually, although this will take more effort. From the documentation (emphasis added):

In dot graphics mode, the host has almost complete control over the mechanism and can print dots in any dot positions... The horizontal and vertical print density is eight dots per mm. In dot graphics mode, printable characters are subdivided into two groups of characters—printable bit patterns and terminators. The wide variety of line terminators determine the way that received bit patterns print.

Graphic images are constructed one dot line-at-a-time in one pass. Paper feeds one dot-line after one line of image prints. The data for the image is presented sequentially in 6-bit increments. Bit 8 depends on parity; bit 7 is always 1; the remaining bits are the graphic-image bits. For graphic image bits, bit 6 is the leftmost bit and bit 0 is rightmost. The first code sent represents the leftmost carriage position, the last character the rightmost carriage position, and so on.

Due to mechanism configuration, the image data format is constructed as 384 dots per dot line. The host can send a maximum of 64 image code per dot-line, and one terminator code.

NOTE: Image code must not be less than hex number 40; the terminator must not be less than hex number 20.

So the print characters are defined to be P 1 G G G G G G Where P = "Parity as defined by word format", 1=constant 1, and G is a graphics bit

The terminator char is defined to be P 0 1 0 EXIT X X FEED where P = "Parity as defined by word format", 0 is a constant 0, 1 is a constant 1, "EXIT" allows you to exit graphics mode (0=don't exit, 1=exit), X is ignored, and "FEED" allows you to send a line feed.

I'm not sure if this sample code will work as-is, but it should at least get you started, if you want to play with it:

char line[65]; /* room for 64 image codes + 1 terminator code 
                 (if using all 64, no line feed should be used
                  as it will drop down on its own) */
memset(line, 0, sizeof(line));

// ENTER GRAPHICS MODE
line[0] = ESC; // ESC is defined as 0x1B
line[1] = 'g';
p350_print(hPrinter, line);

for(int i = 0; i<sizeof(line); i++)
    line[i] = 0x7F;

line[sizeof(line)-1] = 0x29;
p350_print(hPrinter, line);

Final note: I was just looking at some code I had written quite a long time ago that uses graphics mode and it doesn't look like I'm paying any attention to parity, so you may be able to get away with that always being 0.