Search code examples
c++printingreceiptparallel-portlpt

LPT POS printer alternate feed


I have an ancient POS printer Axhiohm A470 LINK. Windows 7 64bit doesn't detect this printer and drivers don't exist. Only way to print (text mode only) is to send print job directly to LPT. After some digging I found that it's pretty easy. Only thing you have to do is correctly create file LPT1 and write to it.

#include <iostream>
#include <conio.h>
#include <windows.h>

int main(int argc, char* argv[])
{
    HANDLE hComm = CreateFileA("LPT1", GENERIC_READ | GENERIC_WRITE,
                       0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

    if (hComm == INVALID_HANDLE_VALUE)
        return 1;

    char str[] = { "   Hello from your printer\n" };

    DWORD bytesWritten;
    unsigned char data;

    BOOL nError = WriteFile(hComm, str, sizeof(str), &bytesWritten, NULL);

    if (nError)
        std::cout << "Data sent" << std::endl;
    else
        std::cout << "Failed to write data " << GetLastError() << std::endl;

    _getch();
}

Now I would like to take one step further and send print job to second feeder. First one is roll of paper inside the printer (prints receipt). This one prints by the code above. Second one is a slit that is used to put in another receipt. I don't know how to send print job there.


Solution

  • As I found out this is not a programming problem but printer control problem. To accomplish form validation on Axiohm A470 receipt/form validation printer, you have to send appropriate escape sequences. This is link to website where I described how to validate form Printing on POS slip and receipt validation printer . Also, if you don't have any useful drivers to your printer and it's connected to lpt/com port there's an easier way to send a print job to that printer than in my code above. You don't even have to install Windows generic/text only drivers. This is how I send line feed to my printer:

    FILE * pFile;
    char buffer[] = { (char)0x0a };
    pFile = fopen ("c:\\test.txt", "wb");
    fwrite (buffer , sizeof(char), sizeof(buffer), pFile);
    fclose (pFile);
    system("copy c:\\test.txt lpt1");
    

    You can probably bypass creating and copying file to lpt1 and open lpt1 file directly.