佳博GP-L80180 打印机 win7下 驱动方式 打印

手头有一个佳博 GP-L80180 热敏打印机,该打印机有USB口 ,串口,还有一个接口,不是RJ45网口,应该是用来连接钱箱的。
开发包 80开发包\POSDLL+V1.40\POSDLL演示例程\POSDLLDemo_VC\PosdllDemo.exe
界面如下:
这里写图片描述
该软件,用串口的方式 可以打印成功,需要仔细看附带的说明书
用USB口的方式,没有通信成功。
用驱动程序的方式,可以打印成功,前提是正确安装了驱动。

安装驱动的方法:

80开发包\GP80DRVCN V12\GP80DRVCN V12.exe
安装过程和说明书保持一致:
主要是注意:
不要安装 USB 虚拟串口端口 驱动
要选择 GP-L80180 Series
选择对应端口的时候,选择USB001 Virtual Printer Port for USB,不要选别的LPT或者COM端口

驱动安装成功之后,在win7 64位系统的开始菜单,点击 设备和打印机
这里写图片描述
会看到如下界面:
这里写图片描述

测试一下 能够是否正常打印,

给GP-L80180 打印机上电,然后通过USB线 连接到 PC。

这里写图片描述

这里写图片描述

打印出来的小票的样式为:
这里写图片描述
这样表明 驱动安装成功了。

PosdllDemo 使用驱动方式打印

80开发包\POSDLL+V1.40\POSDLL演示例程\POSDLLDemo_VC\PosdllDemo.exe
这里写图片描述

使用POSDLL.dll 库 驱动方式打印的代码

驱动方式打印 和串口 等其他方式打印,其中一个不同点,就是
需要VC_POS_StartDoc 和VC_POS_EndDoc
基本流程如下:
VC_POS_Open
VC_POS_StartDoc
print
VC_POS_EndDoc

BOOL GPL801_OpenDev_USB(void)
{
    BOOL bRet ;
    int ret ;
    g_hComm = VC_POS_Open(_T("GP-L80180 Series"),0,0,0,0,POS_OPEN_PRINTNAME);


    if (g_hComm != INVALID_HANDLE_VALUE) //判断打开端口函数返回值
    {
        printf("GPL801_OpenDev_USB  Open OK\r\n");

        //return true;

    }
    else
    {
        printf("GPL801_OpenDev_USB Open Fail\r\n");

        return false;
    }

    bRet = VC_POS_StartDoc();

    if(bRet == TRUE){

        printf("VC_POS_StartDoc Success \r\n");

    }else{

        return false;
    }


    ret = VC_POS_Reset();

    printf("VC_POS_Reset ret = %d\r\n",ret);

    if(ret != POS_SUCCESS){

        printf("VC_POS_Reset Fail\n");

        return false;
    }


    int nRet = VC_POS_SetMotionUnit(180, 180);

    if(POS_SUCCESS != nRet)
    {

        printf("VC_POS_SetMotionUnit Error %d\r\n",nRet);
        return false;
    }

    VC_POS_SetMode(POS_PRINT_MODE_STANDARD);

    VC_POS_SetRightSpacing(0);

    VC_POS_SetLineSpacing(100);
    VC_POS_S_TextOut("GP POS Printer", 50, 2, 3, POS_FONT_TYPE_STANDARD, 
        POS_FONT_STYLE_NORMAL);

    VC_POS_SetLineSpacing(35);

    VC_POS_FeedLine();
    VC_POS_FeedLine();



    VC_POS_FeedLine();
    VC_POS_FeedLine();

    // 切纸
    VC_POS_CutPaper(POS_CUT_MODE_FULL, 0);

     VC_POS_EndDoc();
     VC_POS_Close();


    return true;

}

输出的log:

GPL801_OpenDev_USB  Open OK
VC_POS_StartDoc Success
VC_POS_Reset ret = 1001
Open OK

使用Win32 API打印原始数据(强烈建议)。

这可是微软的方法啊,不用在系统添加任何文件,同时又能保证打印机的正常使用,所以强烈建议。
参照:http://support.microsoft.com/kb/138594

下载下来:rawprn.exe
解压出来:rawprint 工程:
这里写图片描述
运行如下指令:

   RawPrint.exe GP-L80180 123.txt

GP-L80180 是打印机 共享出来的 名字
输出:

Attempting to send file [123.txt] to printer [GP-L80180].
Data sent to printer.

123.txt中的内容为:

\x0D\x1B\x40
OK打印完成
\x1D\x56\x41\x00

代码如下:RawPrint.cpp

#include <Windows.h>
#include <StdIO.h>


// **********************************************************************
// PrintError - uses printf() to display error code information
// 
// Params:
//   dwError       - the error code, usually from GetLastError()
//   lpString      - some caller-defined text to print with the error info
// 
// Returns: void
// 
void PrintError( DWORD dwError, LPCTSTR lpString )
{
#define MAX_MSG_BUF_SIZE 512
    TCHAR   *msgBuf;
    DWORD   cMsgLen;

    cMsgLen = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_ALLOCATE_BUFFER | 40, NULL, dwError,
                MAKELANGID(0, SUBLANG_ENGLISH_US), (LPTSTR) &msgBuf,
                MAX_MSG_BUF_SIZE, NULL );
    printf( TEXT("%s Error [%d]:: %s\n"), lpString, dwError, msgBuf );
    LocalFree( msgBuf );
#undef MAX_MSG_BUF_SIZE
}
// end PrintError
// **********************************************************************

// **********************************************************************
// ReadFileWithAlloc - allocates memory for and reads contents of a file
// 
// Params:
//   szFileName   - NULL terminated string specifying file name
//   pdwSize      - address of variable to receive file bytes size
//   ppBytes      - address of pointer which will be allocated and contain file bytes
// 
// Returns: TRUE for success, FALSE for failure.
//
// Notes: Caller is responsible for freeing the memory using GlobalFree()
// 
BOOL ReadFileWithAlloc( LPTSTR szFileName, LPDWORD pdwSize, LPBYTE *ppBytes )
{
    HANDLE      hFile;
    DWORD       dwBytes;
    BOOL        bSuccess = FALSE;

    // Validate pointer parameters
    if( ( pdwSize == NULL ) || ( ppBytes == NULL ) )
        return FALSE;
    // Open the file for reading
    hFile = CreateFile( szFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
    if( hFile == INVALID_HANDLE_VALUE )
    {
        PrintError( GetLastError(), TEXT("CreateFile()") );
        return FALSE;
    }
    // How big is the file?
    *pdwSize = GetFileSize( hFile, NULL );
    if( *pdwSize == (DWORD)-1 )
        PrintError( GetLastError(), TEXT("GetFileSize()") );
    else
    {
        // Allocate the memory
        *ppBytes = (LPBYTE)GlobalAlloc( GPTR, *pdwSize );
        if( *ppBytes == NULL )
            PrintError( GetLastError(), TEXT("Failed to allocate memory\n") );
        else
        {
            // Read the file into the newly allocated memory
            bSuccess = ReadFile( hFile, *ppBytes, *pdwSize, &dwBytes, NULL );
            if( ! bSuccess )
                PrintError( GetLastError(), TEXT("ReadFile()") );
        }
    }
    // Clean up
    CloseHandle( hFile );
    return bSuccess;
}
// End ReadFileWithAlloc
// **********************************************************************

// **********************************************************************
// RawDataToPrinter - sends binary data directly to a printer
// 
// Params:
//   szPrinterName - NULL terminated string specifying printer name
//   lpData        - Pointer to raw data bytes
//   dwCount       - Length of lpData in bytes
// 
// Returns: TRUE for success, FALSE for failure.
// 
BOOL RawDataToPrinter( LPTSTR szPrinterName, LPBYTE lpData, DWORD dwCount )
{
    HANDLE     hPrinter;
    DOC_INFO_1 DocInfo;
    DWORD      dwJob;
    DWORD      dwBytesWritten;

    // Need a handle to the printer.
    if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )
    {
        PrintError( GetLastError(), TEXT("OpenPrinter") );
        return FALSE;
    }

    // Fill in the structure with info about this "document."
    DocInfo.pDocName = TEXT("My Document");
    DocInfo.pOutputFile = NULL;
    DocInfo.pDatatype = TEXT("RAW");
    // Inform the spooler the document is beginning.
    if( (dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo )) == 0 )
    {
        PrintError( GetLastError(), TEXT("StartDocPrinter") );
        ClosePrinter( hPrinter );
        return FALSE;
    }
    // Start a page.
    if( ! StartPagePrinter( hPrinter ) )
    {
        PrintError( GetLastError(), TEXT("StartPagePrinter") );
        EndDocPrinter( hPrinter );
        ClosePrinter( hPrinter );
        return FALSE;
    }
    // Send the data to the printer.
    if( ! WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten ) )
    {
        PrintError( GetLastError(), TEXT("WritePrinter") );
        EndPagePrinter( hPrinter );
        EndDocPrinter( hPrinter );
        ClosePrinter( hPrinter );
        return FALSE;
    }
    // End the page.
    if( ! EndPagePrinter( hPrinter ) )
    {
        PrintError( GetLastError(), TEXT("EndPagePrinter") );
        EndDocPrinter( hPrinter );
        ClosePrinter( hPrinter );
        return FALSE;
    }
    // Inform the spooler that the document is ending.
    if( ! EndDocPrinter( hPrinter ) )
    {
        PrintError( GetLastError(), TEXT("EndDocPrinter") );
        ClosePrinter( hPrinter );
        return FALSE;
    }
    // Tidy up the printer handle.
    ClosePrinter( hPrinter );
    // Check to see if correct number of bytes were written.
    if( dwBytesWritten != dwCount )
    {
        printf( TEXT("Wrote %d bytes instead of requested %d bytes.\n"), dwBytesWritten, dwCount );
        return FALSE;
    }
    return TRUE;
}
// End RawDataToPrinter
// **********************************************************************

// **********************************************************************
// main - entry point for this console application
// 
// Params:
//   argc        - count of command line arguments
//   argv        - array of NULL terminated command line arguments
//
// Returns: 0 for success, non-zero for failure.
// 
// Command line: c:\>RawPrint PrinterName FileName
//               sends raw data file to printer using spooler APIs
//               written nov 1999 jmh
//
int main( int argc, char* argv[] )
{
    LPBYTE  pBytes = NULL;
    DWORD   dwSize = 0;

    if( argc != 3 )
        return printf( TEXT("Syntax: %s <PrinterName> <FileName>\n"), argv[0] );

    printf( TEXT("Attempting to send file [%s] to printer [%s].\n"), argv[2], argv[1] );

    if( ! ReadFileWithAlloc( argv[2], &dwSize, &pBytes ) )
        return printf( TEXT("Failed to allocate memory for and read file [%s].\n"), argv[2] );

    if( ! RawDataToPrinter( argv[1], pBytes, dwSize ) )
        printf( TEXT("Failed to send data to printer.\n") );
    else
        printf( TEXT("Data sent to printer.\n") );

    GlobalFree( (HGLOBAL)pBytes );
    return 0;
}
// end main
// **********************************************************************

猜你喜欢

转载自blog.csdn.net/wowocpp/article/details/80748184
今日推荐