北洋POSDLL二次开发操作热敏打印机 原创 C++Builder 2022年4月16日 16:42 夏至未至 1967 当前内容 30784 字,在路上,马上到,马上到 ### 目录 [TOC] ### 何为posdll `POSDLL` 是一个动态库,其出口函数是用来直接控制 `POS` 打印机工作。  ### 开发包介绍 文末提供云盘下载开发包,`POSDLL` 目前为较新的155版本,并配有项目实测示例,包中包含: 1. POSDLL 使用 demo,覆盖串口、并口、USB口、网络接口、驱动等打印方式 2. 提供完整的 POSDLL 接口指导文档(中文版、英文版) 3. POSDLL动态库 POSDLL.dll 4. USB驱动,提供驱动安装包,对于USB打印方式,可能需要先安装 有幸使用 `C++Builder 6.0` 工作一年有余,有问题,[欢迎交流](https://www.codecomeon.com/posts/1/ "欢迎交流")。 ### 项目实际应用 #### 打印机配置 无论那种打印方式,配置打印参数是必须的,各打印类型,所需要的参数不同,所以最好需要一个界面来配置,如下这种: #### 加载动态库 以 `C++Builder 6.0` 工具开发为例,LoadPosDll.h #ifndef LOADDLL_H #define LOADDLL_H #pragma once #define POS_SUCCESS 1001 // 函数执行成功 #define POS_FAIL 1002 // 函数执行失败 #define POS_ERROR_INVALID_HANDLE 1101 // 端口或文件的句柄无效 #define POS_ERROR_INVALID_PARAMETER 1102 // 参数无效 #define POS_ERROR_NOT_BITMAP 1103 // 不是位图格式的文件 #define POS_ERROR_NOT_MONO_BITMAP 1104 // 位图不是单色的 #define POS_ERROR_BEYONG_AREA 1105 // 位图超出打印机可以处理的大小 #define POS_ERROR_INVALID_PATH 1106 // 没有找到指定的文件路径或名称 #define POS_COM_DTR_DSR 0x00 // 流控制为DTR/DST #define POS_COM_RTS_CTS 0x01 // 流控制为RTS/CTS #define POS_COM_XON_XOFF 0x02 // 流控制为XON/OFF #define POS_COM_NO_HANDSHAKE 0x03 // 无握手 #define POS_OPEN_PARALLEL_PORT 0x12 // 打开并口通讯端口 #define POS_OPEN_BYUSB_PORT 0x13 // 打开USB通讯端口 #define POS_OPEN_PRINTNAME 0X14 //打开打印机驱动程序 #define POS_OPEN_NETPORT 0X15 // 打开以太网打印机 #define POS_OPEN_CLASSPRINTER 0X16 // 类模式 #define POS_FONT_TYPE_STANDARD 0x00 // 标准 ASCII #define POS_FONT_TYPE_COMPRESSED 0x01 // 压缩 ASCII #define POS_FONT_TYPE_UDC 0x02 // 用户自定义字符 #define POS_FONT_TYPE_CHINESE 0x03 // 标准 “宋体” #define POS_FONT_STYLE_NORMAL 0x00 // 正常 #define POS_FONT_STYLE_BOLD 0x08 // 加粗 #define POS_FONT_STYLE_THIN_UNDERLINE 0x80 // 1点粗的下划线 #define POS_FONT_STYLE_THICK_UNDERLINE 0x100 // 2点粗的下划线 #define POS_FONT_STYLE_UPSIDEDOWN 0x200 // 倒置(只在行首有效) #define POS_FONT_STYLE_REVERSE 0x400 // 反显(黑底白字) #define POS_FONT_STYLE_SMOOTH 0x800 // 平滑处理(用于放大时) #define POS_FONT_STYLE_CLOCKWISE_90 0x1000 // 每个字符顺时针旋转 90 度 #define POS_PRINT_MODE_STANDARD 0x00 // 标准模式(行模式) #define POS_PRINT_MODE_PAGE 0x01 // 页模式 #define POS_PRINT_MODE_BLACK_MARK_LABEL 0x02 // 黑标记标签模式 #define POS_BARCODE_TYPE_UPC_A 0x41 // UPC-A #define POS_BARCODE_TYPE_UPC_E 0x42 // UPC-C #define POS_BARCODE_TYPE_JAN13 0x43 // JAN13(EAN13) #define POS_BARCODE_TYPE_JAN8 0x44 // JAN8(EAN8) #define POS_BARCODE_TYPE_CODE39 0x45 // CODE39 #define POS_BARCODE_TYPE_ITF 0x46 // INTERLEAVED 2 OF 5 #define POS_BARCODE_TYPE_CODEBAR 0x47 // CODEBAR #define POS_BARCODE_TYPE_CODE93 0x48 // 25 #define POS_BARCODE_TYPE_CODE128 0x49 // CODE 128 #define POS_FONT_TYPE_STANDARD 0x00 // 标准ASCII #define POS_FONT_TYPE_COMPRESSED 0x01 // 压缩ASCII #define POS_HRI_POSITION_NONE 0x00 // 不打印 #define POS_HRI_POSITION_ABOVE 0x01 // 只在条码上方打印 #define POS_HRI_POSITION_BELOW 0x02 // 只在条码下方打印 #define POS_HRI_POSITION_BOTH 0x03 // 条码上、下方都打印 #define POS_BITMAP_PRINT_NORMAL 0x00 // 正常 #define POS_BITMAP_PRINT_DOUBLE_WIDTH 0x01 // 倍宽 #define POS_BITMAP_PRINT_DOUBLE_HEIGHT 0x02 // 倍高 #define POS_BITMAP_PRINT_QUADRUPLE 0x03 // 倍宽且倍高 #define POS_CUT_MODE_FULL 0x00 // 全切 #define POS_CUT_MODE_PARTIAL 0x01 // 半切 #define POS_AREA_LEFT_TO_RIGHT 0x0 // 左上角 #define POS_AREA_BOTTOM_TO_TOP 0x1 // 左下角 #define POS_AREA_RIGHT_TO_LEFT 0x2 // 右下角 #define POS_AREA_TOP_TO_BOTTOM 0x3 // 右上角 #define POS_S_SETPOSITION_MIDDLE 0X01 //居中 #define POS_S_SETPOSITION_LEFT 0X00 //居左 #define POS_S_SETPOSITION_RIGHT 0X02 //居右 typedef HANDLE (__stdcall *POS_Open)( LPCTSTR lpName, int nComBaudrate, int nComDataBits, int nComStopBits, int nComParity, int nParam ); typedef int (__stdcall *POS_EnumUSBPrinter)(char* cPrinterName); typedef int (__stdcall *POS_Close)(void); typedef int (__stdcall *POS_Reset)(void); typedef int (__stdcall *POS_SetMode)(int nPrintMode); typedef int (__stdcall *POS_SetMotionUnit)(int nHorizontalMU,int nVerticalMU); typedef int (__stdcall *POS_SetCharSetAndCodePage)(int nCharSet,int nCodePage); typedef int (__stdcall *POS_FeedLine)(void); typedef int (__stdcall *POS_SetLineSpacing)(int nDistance); typedef int (__stdcall *POS_SetRightSpacing)(int nDistance); typedef int (__stdcall *POS_PreDownloadBmpToRAM)(char *pszPath,int nID); typedef int (__stdcall *POS_PreDownloadBmpsToFlash)(char *pszPaths[],int nCount); typedef int (__stdcall *POS_QueryStatus)(char *pszStatus,int nTimeouts); typedef int (__stdcall *POS_RTQueryStatus)(char *pszStatus); typedef int (__stdcall *POS_NETQueryStatus)(char *ipAddress,char *pszStatus); typedef int (__stdcall *POS_KickOutDrawer)(int nID,int nOnTimes,int nOffTimes); typedef int (__stdcall *POS_CutPaper)(int nMode,int nDistance); typedef bool (__stdcall *POS_StartDoc)(); typedef bool (__stdcall *POS_EndDoc)(); typedef bool (__stdcall *POS_EndSaveFile)(); typedef bool (__stdcall *POS_BeginSaveFile)(LPCTSTR lpFileName,bool bToPrinter); typedef int (__stdcall *POS_S_SetAreaWidth)(int nWidth); typedef int (__stdcall *POS_S_TextOut)( char *pszString, int nOrgx, int nWidthTimes, int nHeightTimes, int nFontType, int nFontStyle); typedef int (__stdcall *POS_S_DownloadAndPrintBmp)(char *pszPath,int nOrgx,int nMode); typedef int (__stdcall *POS_S_PrintBmpInRAM)(int nID,int nOrgx,int nMode); typedef int (__stdcall *POS_S_PrintBmpInFlash)(int nID,int nOrgx,int nMode); typedef int (__stdcall *POS_S_SetBarcode)( char *pszInfoBuffer,int nOrgx,int nType,int nWidthX,int nHeight,int nHriFontType,int nHriFontPosition,int nBytesToPrint); typedef int (__stdcall *POS_PL_SetArea)( int nOrgx,int nOrgy,int nWidth,int nHeight,int nDirection); typedef int (__stdcall *POS_PL_TextOut)( char *pszString,int nOrgx,int nOrgy,int nWidthTimes,int nHeightTimes,int nFontType,int nFontStyle); typedef int (__stdcall *POS_PL_DownloadAndPrintBmp)(char *pszPath,int nOrgx,int nOrgy,int nMode); typedef int (__stdcall *POS_Raster_DownloadAndPrintBmp)(char *, int); typedef int (__stdcall *POS_Raster_DownloadAndPrintBmpEx)(char *, int, int, int, int); typedef int (__stdcall *POS_SetPrintDensity)(int); typedef int (__stdcall *POS_PL_PrintBmpInRAM)(int nID,int nOrgx,int nOrgy,int nMode); typedef int (__stdcall *POS_PL_SetBarcode)( char *pszInfoBuffer, int nOrgx, int nOrgy, int nType, int nWidthX, int nHeight, int nHriFontType, int nHriFontPosition, int nBytesToPrint); typedef int (__stdcall *POS_PL_Print)(void); typedef int (__stdcall *POS_PL_Clear)(void); typedef int (__stdcall *POS_S_SetAlignMode)(int); typedef int (__stdcall *POS_WriteFile)(HANDLE hPort,char *pszData,int nBytesToWrite); typedef int (__stdcall *POS_ReadFile)( HANDLE hPort, char *pszData, int nBytesToRead, int nTimeouts); typedef HANDLE (__stdcall *POS_SetHandle)(HANDLE hNewHandle); typedef int (__stdcall *POS_GetVersionInfo)(int *pnMajor, int *pnMinor); bool LoadPosdll(void); bool UnloadPosdll(void); #endif LoadPosDll.cpp #include #include #include "LoadPosDll.h" HMODULE g_hPosdll = NULL; /***************通用函数******************/ POS_Open VC_POS_Open = NULL; POS_EnumUSBPrinter VC_POS_EnumUSBPrinter = NULL; POS_Close VC_POS_Close = NULL; POS_Reset VC_POS_Reset = NULL; POS_SetMode VC_POS_SetMode = NULL; POS_SetMotionUnit VC_POS_SetMotionUnit = NULL; POS_SetCharSetAndCodePage VC_POS_SetCharSetAndCodePage = NULL; POS_FeedLine VC_POS_FeedLine = NULL; POS_SetLineSpacing VC_POS_SetLineSpacing = NULL; POS_SetRightSpacing VC_POS_SetRightSpacing = NULL; POS_PreDownloadBmpToRAM VC_POS_PreDownloadBmpToRAM = NULL; POS_PreDownloadBmpsToFlash VC_POS_PreDownloadBmpsToFlash = NULL; POS_QueryStatus VC_POS_QueryStatus = NULL; POS_NETQueryStatus VC_POS_NETQueryStatus = NULL; POS_RTQueryStatus VC_POS_RTQueryStatus = NULL; POS_KickOutDrawer VC_POS_KickOutDrawer = NULL; POS_CutPaper VC_POS_CutPaper = NULL; POS_StartDoc VC_POS_StartDoc = NULL; POS_EndDoc VC_POS_EndDoc = NULL; POS_EndSaveFile VC_POS_EndSaveFile = NULL; POS_BeginSaveFile VC_POS_BeginSaveFile = NULL; POS_S_SetAlignMode VC_POS_S_SetAlignMode = NULL; /***********只支持标准打印模式(行模式)的函数************/ POS_S_SetAreaWidth VC_POS_S_SetAreaWidth = NULL; POS_S_TextOut VC_POS_S_TextOut = NULL; POS_S_DownloadAndPrintBmp VC_POS_S_DownloadAndPrintBmp = NULL; POS_S_PrintBmpInRAM VC_POS_S_PrintBmpInRAM = NULL; POS_S_PrintBmpInFlash VC_POS_S_PrintBmpInFlash = NULL; POS_S_SetBarcode VC_POS_S_SetBarcode = NULL; /*******只支持页打印模式(P)或标签打印模式(L)的函数*******/ POS_PL_SetArea VC_POS_PL_SetArea = NULL; POS_PL_TextOut VC_POS_PL_TextOut = NULL; POS_PL_DownloadAndPrintBmp VC_POS_PL_DownloadAndPrintBmp = NULL; POS_Raster_DownloadAndPrintBmp VC_POS_Raster_DownloadAndPrintBmp = NULL; POS_Raster_DownloadAndPrintBmpEx VC_POS_Raster_DownloadAndPrintBmpEx = NULL; POS_SetPrintDensity VC_POS_SetPrintDensity = NULL; POS_PL_PrintBmpInRAM VC_POS_PL_PrintBmpInRAM = NULL; POS_PL_SetBarcode VC_POS_PL_SetBarcode = NULL; POS_PL_Print VC_POS_PL_Print = NULL; POS_PL_Clear VC_POS_PL_Clear = NULL; /*****杂项---主要用于调试和自定义控制函数使用*****/ POS_WriteFile VC_POS_WriteFile = NULL; POS_ReadFile VC_POS_ReadFile = NULL; POS_SetHandle VC_POS_SetHandle = NULL; POS_GetVersionInfo VC_POS_GetVersionInfo = NULL; /***********加载动态库****************/ bool LoadPosdll(void) { bool Flag = true; try { AnsiString strPath = ExtractFilePath(Application->ExeName); AnsiString strDll = strPath + "libs\\POSDLL.dll"; if(FileExists(strDll)) { if(g_hPosdll != NULL) { return Flag; } g_hPosdll = LoadLibrary(strDll.c_str()); AnsiString errMsg = ""; if(!g_hPosdll) { errMsg = "动态库加载失败!"; Flag = false; } /***************加载通用函数******************/ VC_POS_Open = (POS_Open) GetProcAddress(g_hPosdll, "POS_Open"); if(VC_POS_Open == NULL) { errMsg = "VC_POS_Open"; Flag = false; } VC_POS_EnumUSBPrinter = (POS_EnumUSBPrinter)GetProcAddress(g_hPosdll, "POS_EnumUSBPrinter"); if (VC_POS_EnumUSBPrinter == NULL) { errMsg = "VC_POS_EnumUSBPrinter"; Flag = false; } VC_POS_Raster_DownloadAndPrintBmp = (POS_Raster_DownloadAndPrintBmp)GetProcAddress(g_hPosdll, "POS_Raster_DownloadAndPrintBmp"); if (VC_POS_Raster_DownloadAndPrintBmp == NULL) { errMsg = "VC_POS_Raster_DownloadAndPrintBmp"; Flag = false; } VC_POS_Raster_DownloadAndPrintBmpEx = (POS_Raster_DownloadAndPrintBmpEx)GetProcAddress(g_hPosdll, "POS_Raster_DownloadAndPrintBmpEx"); if (VC_POS_Raster_DownloadAndPrintBmpEx == NULL) { errMsg = "VC_POS_Raster_DownloadAndPrintBmpEx"; Flag = false; } VC_POS_SetPrintDensity = (POS_SetPrintDensity)GetProcAddress(g_hPosdll, "POS_SetPrintDensity"); if (VC_POS_SetPrintDensity == NULL) { errMsg = "VC_POS_SetPrintDensity"; Flag = false; } VC_POS_Close = (POS_Close) GetProcAddress(g_hPosdll,"POS_Close"); if(VC_POS_Close == NULL) { errMsg = "VC_POS_Close"; Flag = false; } VC_POS_Reset = (POS_Reset) GetProcAddress(g_hPosdll,"POS_Reset"); if(VC_POS_Reset == NULL) { errMsg = "VC_POS_Reset"; Flag = false; } VC_POS_SetMode = (POS_SetMode) GetProcAddress(g_hPosdll,"POS_SetMode"); if(VC_POS_SetMode == NULL) { errMsg = "VC_POS_SetMode"; Flag = false; } VC_POS_SetMotionUnit = (POS_SetMotionUnit) GetProcAddress(g_hPosdll,"POS_SetMotionUnit"); if(VC_POS_SetMotionUnit == NULL) { errMsg = "VC_POS_SetMotionUnit"; Flag = false; } VC_POS_SetCharSetAndCodePage = (POS_SetCharSetAndCodePage) GetProcAddress(g_hPosdll,"POS_SetCharSetAndCodePage"); if(VC_POS_SetCharSetAndCodePage == NULL) { errMsg = "VC_POS_SetCharSetAndCodePage"; Flag = false; } VC_POS_FeedLine = (POS_FeedLine) GetProcAddress(g_hPosdll,"POS_FeedLine"); if(VC_POS_FeedLine == NULL) { errMsg = "VC_POS_FeedLine"; Flag = false; } VC_POS_SetLineSpacing = (POS_SetLineSpacing) GetProcAddress(g_hPosdll,"POS_SetLineSpacing"); if(VC_POS_SetLineSpacing == NULL) { errMsg = "VC_POS_SetLineSpacing"; Flag = false; } VC_POS_SetRightSpacing = (POS_SetRightSpacing) GetProcAddress(g_hPosdll,"POS_SetRightSpacing"); if(VC_POS_SetRightSpacing == NULL) { errMsg = "VC_POS_SetRightSpacing"; Flag = false; } VC_POS_PreDownloadBmpToRAM = (POS_PreDownloadBmpToRAM) GetProcAddress(g_hPosdll,"POS_PreDownloadBmpToRAM"); if(VC_POS_PreDownloadBmpToRAM == NULL) { errMsg = "VC_POS_PreDownloadBmpToRAM"; Flag = false; } VC_POS_PreDownloadBmpsToFlash = (POS_PreDownloadBmpsToFlash) GetProcAddress(g_hPosdll,"POS_PreDownloadBmpsToFlash"); if(VC_POS_PreDownloadBmpsToFlash == NULL) { errMsg = "VC_POS_PreDownloadBmpsToFlash"; Flag = false; } VC_POS_QueryStatus = (POS_QueryStatus) GetProcAddress(g_hPosdll,"POS_QueryStatus"); if(VC_POS_QueryStatus == NULL) { errMsg = "VC_POS_QueryStatus"; Flag = false; } VC_POS_RTQueryStatus = (POS_RTQueryStatus) GetProcAddress(g_hPosdll,"POS_RTQueryStatus"); if(VC_POS_RTQueryStatus == NULL) { errMsg = "VC_POS_RTQueryStatus"; Flag = false; } VC_POS_NETQueryStatus = (POS_NETQueryStatus)GetProcAddress(g_hPosdll,"POS_NETQueryStatus"); if(VC_POS_NETQueryStatus == NULL) { errMsg = "VC_POS_NETQueryStatus"; Flag = false; } VC_POS_KickOutDrawer = (POS_KickOutDrawer) GetProcAddress(g_hPosdll,"POS_KickOutDrawer"); if(VC_POS_KickOutDrawer == NULL) { errMsg = "VC_POS_KickOutDrawer"; Flag = false; } VC_POS_CutPaper = (POS_CutPaper) GetProcAddress(g_hPosdll,"POS_CutPaper"); if(VC_POS_CutPaper == NULL) { errMsg = "VC_POS_CutPaper"; Flag = false; } VC_POS_StartDoc = (POS_StartDoc) GetProcAddress(g_hPosdll,"POS_StartDoc"); if(VC_POS_StartDoc == NULL) { errMsg = "VC_POS_StartDoc"; Flag = false; } VC_POS_EndDoc = (POS_EndDoc) GetProcAddress(g_hPosdll,"POS_EndDoc"); if(VC_POS_EndDoc == NULL) { errMsg = "VC_POS_EndDoc"; Flag = false; } VC_POS_EndSaveFile = (POS_EndSaveFile) GetProcAddress(g_hPosdll,"POS_EndSaveFile"); if(VC_POS_EndSaveFile == NULL) { errMsg = "VC_POS_EndSaveFile"; Flag = false; } VC_POS_BeginSaveFile = (POS_BeginSaveFile) GetProcAddress(g_hPosdll,"POS_BeginSaveFile"); if(VC_POS_BeginSaveFile == NULL) { errMsg = "VC_POS_BeginSaveFile"; Flag = false; } /***********只支持标准打印模式(行模式)的函数************/ VC_POS_S_SetAreaWidth = (POS_S_SetAreaWidth) GetProcAddress(g_hPosdll,"POS_S_SetAreaWidth"); if(VC_POS_S_SetAreaWidth == NULL) { errMsg = "VC_POS_S_SetAreaWidth"; Flag = false; } VC_POS_S_TextOut = (POS_S_TextOut) GetProcAddress(g_hPosdll,"POS_S_TextOut"); if(VC_POS_S_TextOut == NULL) { errMsg = "VC_POS_S_TextOut"; Flag = false; } VC_POS_S_DownloadAndPrintBmp = (POS_S_DownloadAndPrintBmp) GetProcAddress(g_hPosdll,"POS_S_DownloadAndPrintBmp"); if(VC_POS_S_DownloadAndPrintBmp == NULL) { errMsg = "VC_POS_S_DownloadAndPrintBmp"; Flag = false; } VC_POS_S_PrintBmpInRAM = (POS_S_PrintBmpInRAM) GetProcAddress(g_hPosdll,"POS_S_PrintBmpInRAM"); if(VC_POS_S_PrintBmpInRAM == NULL) { errMsg = "VC_POS_S_PrintBmpInRAM"; Flag = false; } VC_POS_S_PrintBmpInFlash = (POS_S_PrintBmpInFlash) GetProcAddress(g_hPosdll,"POS_S_PrintBmpInFlash"); if(VC_POS_S_PrintBmpInFlash == NULL) { errMsg = "VC_POS_S_PrintBmpInFlash"; Flag = false; } VC_POS_S_SetBarcode = (POS_S_SetBarcode) GetProcAddress(g_hPosdll,"POS_S_SetBarcode"); if(VC_POS_S_SetBarcode == NULL) { errMsg = "VC_POS_S_SetBarcode"; Flag = false; } VC_POS_S_SetAlignMode = (POS_S_SetAlignMode) GetProcAddress(g_hPosdll, "POS_S_SetAlignMode"); if(VC_POS_S_SetAlignMode == NULL) { errMsg = "VC_POS_S_SetAlignMode"; Flag = false; } /*******只支持页打印模式(P)或标签打印模式(L)的函数*******/ VC_POS_PL_SetArea = (POS_PL_SetArea) GetProcAddress(g_hPosdll,"POS_PL_SetArea"); if(VC_POS_PL_SetArea == NULL) { errMsg = "VC_POS_PL_SetArea"; Flag = false; } VC_POS_PL_TextOut = (POS_PL_TextOut) GetProcAddress(g_hPosdll,"POS_PL_TextOut"); if(VC_POS_PL_TextOut == NULL) { errMsg = "VC_POS_PL_TextOut"; Flag = false; } VC_POS_PL_DownloadAndPrintBmp = (POS_PL_DownloadAndPrintBmp) GetProcAddress(g_hPosdll,"POS_PL_DownloadAndPrintBmp"); if(VC_POS_PL_DownloadAndPrintBmp == NULL) { errMsg = "VC_POS_PL_DownloadAndPrintBmp"; Flag = false; } VC_POS_PL_PrintBmpInRAM = (POS_PL_PrintBmpInRAM) GetProcAddress(g_hPosdll,"POS_PL_PrintBmpInRAM"); if(VC_POS_PL_PrintBmpInRAM == NULL) { errMsg = "VC_POS_PL_PrintBmpInRAM"; Flag = false; } VC_POS_PL_SetBarcode = (POS_PL_SetBarcode) GetProcAddress(g_hPosdll,"POS_PL_SetBarcode"); if(VC_POS_PL_SetBarcode == NULL) { errMsg = "VC_POS_PL_SetBarcode"; Flag = false; } VC_POS_PL_Print = (POS_PL_Print) GetProcAddress(g_hPosdll,"POS_PL_Print"); if(VC_POS_PL_Print == NULL) { errMsg = "VC_POS_PL_Print"; Flag = false; } VC_POS_PL_Clear = (POS_PL_Clear) GetProcAddress(g_hPosdll,"POS_PL_Clear"); if(VC_POS_PL_Clear == NULL) { errMsg = "VC_POS_PL_Clear"; Flag = false; } /*****杂项---主要用于调试和自定义控制函数使用*****/ VC_POS_WriteFile = (POS_WriteFile) GetProcAddress(g_hPosdll,"POS_WriteFile"); if(VC_POS_WriteFile == NULL) { errMsg = "VC_POS_WriteFile"; Flag = false; } VC_POS_ReadFile = (POS_ReadFile) GetProcAddress(g_hPosdll,"POS_ReadFile"); if(VC_POS_ReadFile == NULL) { errMsg = "VC_POS_ReadFile"; Flag = false; } VC_POS_SetHandle = (POS_SetHandle) GetProcAddress(g_hPosdll,"POS_SetHandle"); if(VC_POS_SetHandle == NULL) { errMsg = "VC_POS_SetHandle"; Flag = false; } VC_POS_GetVersionInfo = (POS_GetVersionInfo) GetProcAddress(g_hPosdll,"POS_GetVersionInfo"); if(VC_POS_GetVersionInfo == NULL) { errMsg = "VC_POS_GetVersionInfo"; Flag = false; } if(!Flag) { printf("加载【%s】方法失败!", errMsg.c_str()); } } else { print("动态库文件不存在!"); Flag = false; } } catch(Exception &e) { print("LoadPosdll err: %s!",e.Message.c_str()); Flag = false; g_hPosdll = NULL; } catch(...) { print("LoadPosdll err!"); Flag = false; g_hPosdll = NULL; } return Flag; } bool UnloadPosdll(void) { if (NULL == g_hPosdll) { return false; } FreeLibrary(g_hPosdll); return true; } #### 打印示例 依然在 C++Builder 6.0 项目中实现,其中重点为: 1. 打印时耗时操作,设计考虑放入线程执行 2. 打印时使用不同的打印类型,相对应的打印所需参数,需要在打印前就已经配置成静态数据,存放到数据库或者配置文件,以便打印时,能及时获取到 3. 打印机是共享的,而打印任务却是多个的,所以打印请求注意缓存到队列 以下为项目源码剥离出打印部分,略微调试,基本可以复用,打印中使用的 POSDLL 接口函数作用、参数含义、返回值都可以在下载的开发包中指导文档内查找。 CodeComeOnPrinter.h //--------------------------------------------------------------------------- #ifndef CodeComeOnPrinterH #define CodeComeOnPrinterH //--------------------------------------------------------------------------- #include /*打印类型*/ enum PRINT_INFO_TYPE { PRINT_THREAD_QUIT = 8000, //打印线程退出 PRINT_PRINTING_TEST, //打印机测试 }; typedef struct { int type; int itemIndex; }T_PrintMsg; //--------------------------------------------------------------------------- class CodeComeOnPrinter { public: CodeComeOnPrinter(HANDLE handle); ~CodeComeOnPrinter(); //创建打印线程 void createPrintThread(); void __fastcall printerTestReq(int itemIndex, int type); public: //POSDLL static AnsiString __fastcall openComPrinter(); static bool __fastcall isDrive(AnsiString printerName); static void __fastcall printTestByPosdll(); private: DWORD m_printThreadID; //打印线程ID }; #endif CodeComeOnPrinter.cpp //--------------------------------------------------------------------------- #include #pragma hdrstop #include "LoadPosDll.h" #include "CodeComeOnPrinter.h" #pragma package(smart_init) /***************通用函数******************/ extern POS_Open VC_POS_Open; extern POS_EnumUSBPrinter VC_POS_EnumUSBPrinter; extern POS_Close VC_POS_Close; extern POS_Reset VC_POS_Reset; extern POS_SetMode VC_POS_SetMode; extern POS_SetMotionUnit VC_POS_SetMotionUnit; extern POS_SetCharSetAndCodePage VC_POS_SetCharSetAndCodePage; extern POS_FeedLine VC_POS_FeedLine; extern POS_SetLineSpacing VC_POS_SetLineSpacing; extern POS_SetRightSpacing VC_POS_SetRightSpacing; extern POS_PreDownloadBmpToRAM VC_POS_PreDownloadBmpToRAM; extern POS_PreDownloadBmpsToFlash VC_POS_PreDownloadBmpsToFlash; extern POS_Raster_DownloadAndPrintBmp VC_POS_Raster_DownloadAndPrintBmp; extern POS_Raster_DownloadAndPrintBmpEx VC_POS_Raster_DownloadAndPrintBmpEx; extern POS_SetPrintDensity VC_POS_SetPrintDensity; extern POS_QueryStatus VC_POS_QueryStatus; extern POS_RTQueryStatus VC_POS_RTQueryStatus; extern POS_KickOutDrawer VC_POS_KickOutDrawer; extern POS_CutPaper VC_POS_CutPaper; extern POS_StartDoc VC_POS_StartDoc; extern POS_EndDoc VC_POS_EndDoc; extern POS_EndSaveFile VC_POS_EndSaveFile; extern POS_BeginSaveFile VC_POS_BeginSaveFile; extern POS_S_SetAlignMode VC_POS_S_SetAlignMode; /***********只支持标准打印模式(行模式)的函数************/ extern POS_S_SetAreaWidth VC_POS_S_SetAreaWidth; extern POS_S_TextOut VC_POS_S_TextOut; extern POS_S_DownloadAndPrintBmp VC_POS_S_DownloadAndPrintBmp; extern POS_S_PrintBmpInRAM VC_POS_S_PrintBmpInRAM; extern POS_S_PrintBmpInFlash VC_POS_S_PrintBmpInFlash; extern POS_S_SetBarcode VC_POS_S_SetBarcode; /*******只支持页打印模式(P)或标签打印模式(L)的函数*******/ extern POS_PL_SetArea VC_POS_PL_SetArea; extern POS_PL_TextOut VC_POS_PL_TextOut; extern POS_PL_DownloadAndPrintBmp VC_POS_PL_DownloadAndPrintBmp; extern POS_PL_PrintBmpInRAM VC_POS_PL_PrintBmpInRAM; extern POS_PL_SetBarcode VC_POS_PL_SetBarcode; extern POS_PL_Print VC_POS_PL_Print; extern POS_PL_Clear VC_POS_PL_Clear; /*****杂项---主要用于调试和自定义控制函数使用*****/ extern POS_WriteFile VC_POS_WriteFile; extern POS_ReadFile VC_POS_ReadFile; extern POS_SetHandle VC_POS_SetHandle; extern POS_GetVersionInfo VC_POS_GetVersionInfo; extern AnsiString m_szVersion; static HANDLE g_msgHandle = NULL; static HANDLE g_hComm = NULL; static int g_printerType = 0; static bool m_blPrinting = false; static AnsiString dottedLine("----------------------------------------------"); //------------------------------------------------------------------------------ CodeComeOnPrinter::CodeComeOnPrinter(HANDLE handle) { g_msgHandle = handle; g_hComm = INVALID_HANDLE_VALUE; m_printThreadID = 0; //加载DLL数据 if(LoadPosdll()) { c ¥20.00 解锁全文 下载资源 本文标题: 北洋POSDLL二次开发操作热敏打印机 本文作者: 夏至未至 发布时间: 2022年4月16日 16:42 最近更新: 2024年1月4日 17:54 原文链接: 许可协议: 署名-非商业性-禁止演绎 4.0 国际(CC BY-NC-ND 4.0) 请按协议转载并保留原文链接及作者 POSDLL(1) 上一个 Python必知必会-异常处理之finally 下一个 Python必知必会-for循环break和else联用 当前文章评论暂未开放,请移步至留言处留言。