|
|
@@ -1,496 +1,23 @@
|
|
|
#include "../pch/pch.h"
|
|
|
-#include "CPosPrinter.h"
|
|
|
+#include "CPosPrinterData.h"
|
|
|
|
|
|
-#include "../tool/CComHelper.h"
|
|
|
#include "../helper/CBitmapHelper.h"
|
|
|
-
|
|
|
#include <qrencode/qrencode.h>
|
|
|
|
|
|
-CPosPrinter::CPosPrinter(): m_socket(m_io)
|
|
|
+CPosPrinterData::CPosPrinterData()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
|
|
|
-CPosPrinter::~CPosPrinter()
|
|
|
+CPosPrinterData::~CPosPrinterData()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- *usbType是1表示只查找收银小票打印机,会排除已知的标签打印机
|
|
|
- *usbType为2表示所有usb打印机都查找,包含标签与非标签
|
|
|
- **/
|
|
|
-void CPosPrinter::InitUsb(int usbType)
|
|
|
-{
|
|
|
- //设置中文字符
|
|
|
- setlocale(LC_CTYPE, "chs");
|
|
|
-
|
|
|
- //取设备路径
|
|
|
- int nDevice = GetDevicePath((LPGUID)&USB_GUID, usbType);
|
|
|
- LOG_INFO("可用的USB打印机数量:" << nDevice);
|
|
|
-
|
|
|
- //添加usb端口
|
|
|
- int i = 0;
|
|
|
-
|
|
|
- while(i < nDevice)
|
|
|
- {
|
|
|
- std::string setting_biaoqian_printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
|
|
|
- std::wstring ws_setting_biaoqian_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_biaoqian_printer_usb);
|
|
|
-
|
|
|
- if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1" && ws_setting_biaoqian_printer_usb == m_usb_devices[i])
|
|
|
- {
|
|
|
- //碰到了一个标签打印机
|
|
|
- i++;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- LOG_INFO("准备打开端口 Port = " << m_usb_devices[i].c_str());
|
|
|
-
|
|
|
- HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
-
|
|
|
- if(hPort == INVALID_HANDLE_VALUE)
|
|
|
- {
|
|
|
- LOG_INFO("打开USB端口失败, Port = " << m_usb_devices[i].c_str());
|
|
|
-
|
|
|
- // 打开端口失败
|
|
|
- DWORD error = GetLastError();
|
|
|
-
|
|
|
- if(error == 2)
|
|
|
- {
|
|
|
- //没有指定的文件
|
|
|
- LOG_INFO("没有找对对应的usb端口");
|
|
|
- }
|
|
|
- else if(error == 5)
|
|
|
- {
|
|
|
- LOG_INFO("usb端口被占用!");
|
|
|
- }
|
|
|
-
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- LOG_INFO("打开usb端口成功,准备进行打印机检测! hPort:" << hPort);
|
|
|
-
|
|
|
- if(PortTest(hPort) == true)
|
|
|
- {
|
|
|
- //端口测试连通,保存起来
|
|
|
- PrinterHandle newHandle;
|
|
|
- newHandle.hPort = hPort;
|
|
|
- newHandle.type = 1;
|
|
|
-
|
|
|
- m_hPorts.push_back(newHandle);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //端口打印机没有连接,那么就直接关闭掉并口,避免占用
|
|
|
- CloseHandle(hPort);
|
|
|
- }
|
|
|
-
|
|
|
- i++;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-bool CPosPrinter::InitOneUsb(wstring usb_path)
|
|
|
-{
|
|
|
- if (usb_path == L"")
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
-
|
|
|
- if(hPort == INVALID_HANDLE_VALUE)
|
|
|
- {
|
|
|
- LOG_INFO("打开USB端口失败, Port = " << usb_path.c_str());
|
|
|
-
|
|
|
- // 打开端口失败
|
|
|
- DWORD error = GetLastError();
|
|
|
-
|
|
|
- if(error == 2)
|
|
|
- {
|
|
|
- //没有指定的文件
|
|
|
- LOG_INFO("没有找对对应的usb端口");
|
|
|
- }
|
|
|
- else if(error == 5)
|
|
|
- {
|
|
|
- LOG_INFO("usb端口被占用!");
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
|
|
|
-
|
|
|
- if(PortTest(hPort) == true)
|
|
|
- {
|
|
|
- //端口测试连通,保存起来
|
|
|
- PrinterHandle newHandle;
|
|
|
- newHandle.hPort = hPort;
|
|
|
- newHandle.type = 1;
|
|
|
-
|
|
|
- m_hPorts.push_back(newHandle);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //端口打印机没有连接,那么就直接关闭掉并口,避免占用
|
|
|
- CloseHandle(hPort);
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-bool CPosPrinter::InitBingkou()
|
|
|
-{
|
|
|
- std::wstring LptStr = L"lpt1";
|
|
|
-
|
|
|
- HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
-
|
|
|
- if(hPort == INVALID_HANDLE_VALUE)
|
|
|
- {
|
|
|
- LOG_INFO("打开并口失败, Port = " << LptStr.c_str());
|
|
|
-
|
|
|
- DWORD error = GetLastError();
|
|
|
-
|
|
|
- if(error == 2)
|
|
|
- {
|
|
|
- //没有指定的文件
|
|
|
- LOG_INFO("本机器没有并口!");
|
|
|
- }
|
|
|
- else if(error == 5)
|
|
|
- {
|
|
|
- LOG_INFO("并口被占用!");
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //这个表示并口可以使用
|
|
|
- LOG_INFO("找到并口,准备进行打印机检测! hPort:" << hPort);
|
|
|
-
|
|
|
- if(PortTest(hPort) == true)
|
|
|
- {
|
|
|
- //并口测试连通,保存起来
|
|
|
- PrinterHandle newHandle;
|
|
|
- newHandle.hPort = hPort;
|
|
|
- newHandle.type = 2;
|
|
|
-
|
|
|
- m_hPorts.push_back(newHandle);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //并口打印机没有连接,那么就直接关闭掉并口,避免占用
|
|
|
- CloseHandle(hPort);
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-void CPosPrinter::InitCom()
|
|
|
-{
|
|
|
- CComHelper helper;
|
|
|
- std::vector<std::wstring> comVector = helper.getComPort();
|
|
|
-
|
|
|
- for(std::vector<std::wstring>::iterator it = comVector.begin(); it != comVector.end(); it++)
|
|
|
- {
|
|
|
- std::wstring com2Str = *it;
|
|
|
-
|
|
|
- HANDLE hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
-
|
|
|
- if(hPort == INVALID_HANDLE_VALUE)
|
|
|
- {
|
|
|
- DWORD error = GetLastError();
|
|
|
-
|
|
|
- if(error == 2)
|
|
|
- {
|
|
|
- //没有指定的文件
|
|
|
- LOG_INFO("没有找到对应的串口 " << com2Str.c_str());
|
|
|
- }
|
|
|
- else if(error == 5)
|
|
|
- {
|
|
|
- LOG_INFO("串口被占用 " << com2Str.c_str());
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LOG_INFO(com2Str.c_str() << " success, handle:" << hPort);
|
|
|
-
|
|
|
- //扎到了可用的串口,设置串口波特率
|
|
|
- DCB dcb;
|
|
|
- dcb.DCBlength = sizeof(dcb);
|
|
|
- GetCommState(hPort, &dcb);
|
|
|
-
|
|
|
- //佳博的串口打印机,默认是这个波特率
|
|
|
- dcb.BaudRate = 19200;
|
|
|
-
|
|
|
- if(!SetCommState(hPort, &dcb))
|
|
|
- {
|
|
|
- LOG_INFO("set baudRate failed!");
|
|
|
-
|
|
|
- CloseHandle(hPort);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //设定通讯端口超时参数
|
|
|
- COMMTIMEOUTS tmouts;
|
|
|
- tmouts.ReadIntervalTimeout = 100;
|
|
|
- tmouts.ReadTotalTimeoutMultiplier = 100;
|
|
|
- tmouts.ReadTotalTimeoutConstant = 100;
|
|
|
- tmouts.WriteTotalTimeoutConstant = 100;
|
|
|
- tmouts.WriteTotalTimeoutMultiplier = 100;
|
|
|
- SetCommTimeouts(hPort, &tmouts);
|
|
|
-
|
|
|
- //设置端口缓冲
|
|
|
- SetupComm(hPort, 1024, 1024);
|
|
|
-
|
|
|
- //清除通讯端口缓存
|
|
|
- PurgeComm(hPort, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
|
|
|
-
|
|
|
- //保存端口
|
|
|
- PrinterHandle newHandle;
|
|
|
- newHandle.hPort = hPort;
|
|
|
- newHandle.type = 3;
|
|
|
-
|
|
|
- m_hPorts.push_back(newHandle);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
- *找到所有可用的小票打印机,这里只初始化USB,不包含并口、串口、网口
|
|
|
- *智能识别模式不再自动处理串口,串口的需要人工去选择类型
|
|
|
- **/
|
|
|
-void CPosPrinter::InitShouyin()
|
|
|
-{
|
|
|
- //开始添加usb
|
|
|
- InitUsb();
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
- *获取CreateFile的USB端口号
|
|
|
- **/
|
|
|
-int CPosPrinter::GetDevicePath(LPGUID lpGuid, int usbType)
|
|
|
-{
|
|
|
- HDEVINFO hDevInfoSet;
|
|
|
- SP_DEVINFO_DATA spDevInfoData;
|
|
|
- SP_DEVICE_INTERFACE_DATA ifData;
|
|
|
- PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
|
|
|
- int nCount;
|
|
|
- int nTotle;
|
|
|
- BOOL bResult;
|
|
|
-
|
|
|
- //这2个字符串,用于根据usb的名字对比是否为打印机设备
|
|
|
- wstring strUSBPrint = TEXT("USB 打印支持");
|
|
|
-
|
|
|
- //xp上是英文
|
|
|
- wstring strUSBPrint_EN = L"USB Printing Support";
|
|
|
-
|
|
|
- // 取得一个该GUID相关的设备信息集句柄
|
|
|
- hDevInfoSet = ::SetupDiGetClassDevs(lpGuid, // class GUID
|
|
|
- NULL, // 无关键字
|
|
|
- NULL, // 不指定父窗口句柄
|
|
|
- DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // 目前存在的设备
|
|
|
-
|
|
|
- // 失败...
|
|
|
- if(hDevInfoSet == INVALID_HANDLE_VALUE)
|
|
|
- {
|
|
|
- LOG_INFO("SetupDiGetClassDevs failed \r\n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- // 申请设备接口数据空间
|
|
|
- pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT, INTERFACE_DETAIL_SIZE);
|
|
|
- pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
|
|
- nTotle = -1;
|
|
|
- nCount = 0;
|
|
|
- bResult = TRUE;
|
|
|
-
|
|
|
- // 设备序号=0,1,2... 逐一测试设备接口,到失败为止
|
|
|
- while(bResult)
|
|
|
- {
|
|
|
- nTotle++;
|
|
|
- spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
|
|
-
|
|
|
- // 枚举符合该GUID的设备接口
|
|
|
- bResult = ::SetupDiEnumDeviceInfo(
|
|
|
- hDevInfoSet, // 设备信息集句柄
|
|
|
- (ULONG)nTotle, // 设备信息集里的设备序号
|
|
|
- &spDevInfoData); // 设备接口信息
|
|
|
-
|
|
|
- if(bResult)
|
|
|
- {
|
|
|
- DWORD DataT;
|
|
|
- TCHAR buf[MAX_PATH] = { 0 };
|
|
|
- DWORD nSize = 0;
|
|
|
-
|
|
|
- // get Friendly Name or Device Description
|
|
|
- if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
|
- SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
|
- {
|
|
|
- }
|
|
|
- else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
|
- SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
|
- {
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- lstrcpy(buf, _T("Unknown"));
|
|
|
- }
|
|
|
-
|
|
|
- wstring ws_buf = buf;
|
|
|
-
|
|
|
- //是否是要找的设备类型
|
|
|
- if(ws_buf != strUSBPrint && ws_buf != strUSBPrint_EN)
|
|
|
- {
|
|
|
- LOG_INFO("not good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- LOG_INFO("good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
|
|
|
- ifData.cbSize = sizeof(ifData);
|
|
|
-
|
|
|
- // 枚舉符合該GUID的設備接口
|
|
|
- bResult = ::SetupDiEnumDeviceInterfaces(
|
|
|
- hDevInfoSet, // 設備信息集句柄
|
|
|
- NULL, // 不需額外的設備描述
|
|
|
- lpGuid, // GUID
|
|
|
- (ULONG)nTotle, // 設備信息集里的設備序號
|
|
|
- &ifData); // 設備接口信息
|
|
|
-
|
|
|
- if(bResult)
|
|
|
- {
|
|
|
- // 取得该设备接口的细节(设备路径)
|
|
|
- bResult = SetupDiGetInterfaceDeviceDetail(
|
|
|
- hDevInfoSet, // 设备信息集句柄
|
|
|
- &ifData, // 设备接口信息
|
|
|
- pDetail, // 设备接口细节(设备路径)
|
|
|
- INTERFACE_DETAIL_SIZE, // 输出缓冲区大小
|
|
|
- NULL, // 不需计算输出缓冲区大小(直接用设定值)
|
|
|
- NULL); // 不需额外的设备描述
|
|
|
-
|
|
|
- if(bResult)
|
|
|
- {
|
|
|
- wstring DevicePath = pDetail->DevicePath;
|
|
|
-
|
|
|
- wstring vid = DevicePath.substr(DevicePath.find(_T("vid_"), 0) + 4, 4);
|
|
|
- wstring pid = DevicePath.substr(DevicePath.find(_T("pid_"), 0) + 4, 4);
|
|
|
-
|
|
|
- LOG_INFO("Vid:" << vid.c_str() << ", Pid:" << pid.c_str());
|
|
|
-
|
|
|
- if(usbType == 1 && GetPrinterType(vid, pid) == 2)
|
|
|
- {
|
|
|
- //标签打印机,暂时不处理打印
|
|
|
- LOG_INFO("标签打印机,暂时不打印!");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 复制设备路径到输出缓冲区
|
|
|
- m_usb_devices.push_back(DevicePath);
|
|
|
-
|
|
|
- // 调整计数值
|
|
|
- nCount++;
|
|
|
-
|
|
|
- LOG_INFO("Cnt = " << nCount << ",pDetail->DevicePath =" << pDetail->DevicePath);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //LOG_INFO("SetupDiEnumDeviceInfo FAILED!@");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 释放设备接口数据空间
|
|
|
- ::GlobalFree(pDetail);
|
|
|
-
|
|
|
- // 关闭设备信息集句柄
|
|
|
- ::SetupDiDestroyDeviceInfoList(hDevInfoSet);
|
|
|
- return nCount;
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
- *返回打印机的类型, 1:普通热敏打印机 2:标签打印机 3:发票打印机
|
|
|
- *这里因为不同厂家对vid pid定义不一样,有时候会出现佳博的标签打印机的vid和pid,在别的品牌上变成了热敏打印机,这里如果排除掉别的品牌的热敏打印机就无法打印了,所以这里不能轻易排除
|
|
|
- **/
|
|
|
-int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
|
|
|
-{
|
|
|
- if(vid == L"6868" && pid == L"0500")
|
|
|
- {
|
|
|
- //佳博标签打印机
|
|
|
- return 2;
|
|
|
- }
|
|
|
- else if (vid == L"XXX" && pid == L"XXX")
|
|
|
- {
|
|
|
- //发票打印机
|
|
|
- return 3;
|
|
|
- }
|
|
|
-
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
*打印收银小票
|
|
|
**/
|
|
|
-void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
+std::string CPosPrinterData::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
{
|
|
|
- LOG_INFO("_______________________________开始打印收银小票,订单编号:"<<order.m_order_num.c_str()<<"_________________________");
|
|
|
-
|
|
|
- //设置模式,后面输出数据不会错
|
|
|
- m_type = 1;
|
|
|
-
|
|
|
- std::string printer_leixing = CSetting::GetParam("setting_printer_leixing");
|
|
|
-
|
|
|
- if(printer_leixing == "auto")
|
|
|
- {
|
|
|
- InitShouyin();
|
|
|
- }
|
|
|
- else if(printer_leixing == "usb")
|
|
|
- {
|
|
|
- std::string printer_usb = CSetting::GetParam("setting_printer_usb");
|
|
|
- std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
|
|
|
-
|
|
|
- bool ret = InitOneUsb(ws_printer_usb);
|
|
|
- if (ret == false)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(printer_leixing == "bingkou")
|
|
|
- {
|
|
|
- bool ret = InitBingkou();
|
|
|
- if (ret == false)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(printer_leixing == "chuankou")
|
|
|
- {
|
|
|
- InitCom();
|
|
|
- }
|
|
|
- else if(printer_leixing == "wangkou")
|
|
|
- {
|
|
|
- m_type = 2;
|
|
|
-
|
|
|
- std::string wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
|
|
|
-
|
|
|
- //初始化连接
|
|
|
- try
|
|
|
- {
|
|
|
- boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(wangkou_ip.c_str()), 9100);
|
|
|
- m_socket.connect(ep);
|
|
|
- }
|
|
|
- catch(std::exception& e)
|
|
|
- {
|
|
|
- std::string err = e.what();
|
|
|
- LOG_INFO("网口打印机连接失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
|
|
|
-
|
|
|
- MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(wangkou_ip)).c_str(), L"打印机连接失败", MB_OK);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
//读取当前收银打印机的设置
|
|
|
std::string guige = CSetting::GetParam("setting_printer_guige");
|
|
|
std::string lianshu = CSetting::GetParam("setting_printer_lianshu");
|
|
|
@@ -905,26 +432,11 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
//还原打印机初始设置,有些傻逼收银设备居然不是自动调用,比如哗啦啦
|
|
|
POS_Reset();
|
|
|
|
|
|
- //关闭设备
|
|
|
- for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
|
|
|
- {
|
|
|
- CloseHandle((*it).hPort);
|
|
|
- }
|
|
|
-
|
|
|
- if (m_type == 2)
|
|
|
- {
|
|
|
- m_socket.close();
|
|
|
- }
|
|
|
-
|
|
|
- LOG_INFO("_______________________________结束打印收银小票,订单编号:" << order.m_order_num.c_str() << "_________________________");
|
|
|
- LOG_INFO(" ");
|
|
|
+ return m_print_content;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
+std::string CPosPrinterData::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
{
|
|
|
- m_type = 1;
|
|
|
-
|
|
|
std::string printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
|
|
|
std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
|
|
|
|
|
|
@@ -968,9 +480,6 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
nDIRECTION = 0;
|
|
|
}
|
|
|
|
|
|
- //连接usb端口
|
|
|
- InitOneUsb(ws_printer_usb);
|
|
|
-
|
|
|
//初始化标签打印机
|
|
|
BIAOQIAN_Reset(biaoqian_width, biaoqian_height, nDIRECTION);
|
|
|
|
|
|
@@ -1078,38 +587,25 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
BIAOQIAN_CLS();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return m_print_content;
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
+std::vector<ChufangPrinterContent> CPosPrinterData::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
{
|
|
|
- //设置模式,后面输出数据不会错
|
|
|
- m_type = 2;
|
|
|
+ std::vector<ChufangPrinterContent> datas;
|
|
|
|
|
|
//读取厨房打印机信息
|
|
|
std::vector<ChufangPrinter> total_printers = CSetting::getChufangPrints();
|
|
|
|
|
|
for(std::vector<ChufangPrinter>::iterator it = total_printers.begin(); it != total_printers.end(); it++)
|
|
|
{
|
|
|
+ //清空每个厨房打印机的打印内容
|
|
|
+ m_print_content = "";
|
|
|
+
|
|
|
ChufangPrinter printer = *it;
|
|
|
std::string ip = printer.ip;
|
|
|
|
|
|
- //初始化连接
|
|
|
- try
|
|
|
- {
|
|
|
- boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(ip.c_str()), 9100);
|
|
|
- m_socket.connect(ep);
|
|
|
- }
|
|
|
- catch(std::exception& e)
|
|
|
- {
|
|
|
- std::string err = e.what();
|
|
|
- LOG_INFO("厨房网口打印机连接失败,IP地址:" << ip.c_str() << ",错误信息:" << err.c_str());
|
|
|
-
|
|
|
- MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(ip)).c_str(), L"打印机连接失败", MB_OK);
|
|
|
-
|
|
|
- //连接失败了,处理下一个厨房打印机
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
std::string guige = printer.guige;
|
|
|
std::string fendan = printer.fendan;
|
|
|
std::string fenlei = printer.fenlei;
|
|
|
@@ -1144,8 +640,6 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
if (cur_printer_use.size() == 0)
|
|
|
{
|
|
|
//如果这个厨房打印机没有商品可以打印(开启了商品分类打印可能出现),就直接跳过
|
|
|
- m_socket.close();
|
|
|
-
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -1409,115 +903,71 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
POS_Reset();
|
|
|
}
|
|
|
|
|
|
- m_socket.close();
|
|
|
+ ChufangPrinterContent newData;
|
|
|
+ newData.ip = ip;
|
|
|
+ newData.data = m_print_content;
|
|
|
+
|
|
|
+ datas.push_back(newData);
|
|
|
}
|
|
|
+
|
|
|
+ return datas;
|
|
|
}
|
|
|
|
|
|
-std::vector<std::wstring> CPosPrinter::getUsbDevices()
|
|
|
+std::string CPosPrinterData::PrintDiandanOrderShouyin(CDiandanOrder& order)
|
|
|
{
|
|
|
- return m_usb_devices;
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::WriteData(string msg)
|
|
|
+std::string CPosPrinterData::PrintDiandanOrderBiaoqian(CDiandanOrder& order)
|
|
|
{
|
|
|
- return WriteBuf((unsigned char*)msg.c_str(), msg.length());
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- *这个函数只负责把数据拼接到打印缓存里面,不负责实际的发送数据
|
|
|
- **/
|
|
|
-int CPosPrinter::WriteBuf(const unsigned char* buf, int len)
|
|
|
+std::vector<ChufangPrinterContent> CPosPrinterData::PrintDiandanOrderChufang(CDiandanOrder& order)
|
|
|
{
|
|
|
- if(m_type == 1)
|
|
|
- {
|
|
|
- //USB、串口、并口,走这里
|
|
|
- for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
|
|
|
- {
|
|
|
- HANDLE hPort = (*it).hPort;
|
|
|
-
|
|
|
- //同步写数据
|
|
|
- DWORD dwWrite;
|
|
|
-
|
|
|
- BOOL ret = WriteFile(hPort, buf, len, &dwWrite, NULL);
|
|
|
- if (!ret)
|
|
|
- {
|
|
|
- LOG_INFO("WriteFile Failed!, hPort:"<<hPort<<", type:"<<(*it).type);
|
|
|
- }
|
|
|
- }
|
|
|
+ std::vector<ChufangPrinterContent> datas;
|
|
|
|
|
|
- return 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //网口走这里
|
|
|
- try
|
|
|
- {
|
|
|
- m_socket.write_some(boost::asio::buffer(buf, len));
|
|
|
- }
|
|
|
- catch(const std::exception& e)
|
|
|
- {
|
|
|
- LOG_INFO("网口打印机发送消息失败,错误信息:" << e.what());
|
|
|
- }
|
|
|
+ return datas;
|
|
|
+}
|
|
|
|
|
|
- return 1;
|
|
|
- }
|
|
|
+void CPosPrinterData::WriteData(string msg)
|
|
|
+{
|
|
|
+ m_print_content += msg;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- *测试打印机是否连接
|
|
|
+ *这个函数只负责把数据拼接到打印缓存里面,不负责实际的发送数据
|
|
|
**/
|
|
|
-bool CPosPrinter::PortTest(HANDLE hPort)
|
|
|
+void CPosPrinterData::WriteBuf(const unsigned char* buf, int len)
|
|
|
{
|
|
|
- //这里的话目前USB、串口、并口用的都是同步读写模式,有的打印机(比如一些发票打印机)CreateFile会成功,但是WriteFile会一直阻塞卡着,如果检测的话,
|
|
|
- //在这里会一直卡住,因此这里的检测就不检测了,默认所有的都是连通的
|
|
|
- //因此,对于智能识别模式,可能会出现无法打印(因为被某些usb打印设备阻塞),这种情况就只能手动选择USB模式,然后重新启动软件
|
|
|
- return true;
|
|
|
-
|
|
|
- //标签打印机的查询状态指令
|
|
|
- char chInitCode[2] = { 0x1b, 0x40};
|
|
|
-
|
|
|
- DWORD dwWrite;
|
|
|
-
|
|
|
- BOOL rc = WriteFile(hPort, chInitCode, 2, &dwWrite, NULL);
|
|
|
-
|
|
|
- if(rc)
|
|
|
- {
|
|
|
- LOG_INFO("porttest success, handle:" << hPort);
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LOG_INFO("porttest fail, handle:" << hPort);
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
+ for (int i = 0; i < len; i++)
|
|
|
+ {
|
|
|
+ m_print_content += buf[i];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_Reset(void)
|
|
|
+int CPosPrinterData::POS_Reset(void)
|
|
|
{
|
|
|
unsigned char s[2] = {0x1B, 0x40};
|
|
|
WriteBuf(s, 2);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_FeedLine(void)
|
|
|
+int CPosPrinterData::POS_FeedLine(void)
|
|
|
{
|
|
|
unsigned char s[1] = {0x0A};
|
|
|
WriteBuf(s, 1);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_Feed(void)
|
|
|
+int CPosPrinterData::POS_Feed(void)
|
|
|
{
|
|
|
unsigned char s[3] = { 0x1B, 0x4A, 0x00 };
|
|
|
WriteBuf(s, 3);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_SetMotionUnit(int x, int y)
|
|
|
+int CPosPrinterData::POS_SetMotionUnit(int x, int y)
|
|
|
{
|
|
|
string s;
|
|
|
s = "\x1D\x50\xB4\xB4";
|
|
|
@@ -1529,7 +979,7 @@ int CPosPrinter::POS_SetMotionUnit(int x, int y)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_SET_MOVE_X()
|
|
|
+int CPosPrinterData::POS_SET_MOVE_X()
|
|
|
{
|
|
|
unsigned char s2[6] = { 0x1B, 0x44, 0x0C, 0x0E, 0x17, 0x00};
|
|
|
WriteBuf(s2, 6);
|
|
|
@@ -1537,7 +987,7 @@ int CPosPrinter::POS_SET_MOVE_X()
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_MOVE_X()
|
|
|
+int CPosPrinterData::POS_MOVE_X()
|
|
|
{
|
|
|
unsigned char s[1] = { 0x09 };
|
|
|
WriteBuf(s, 1);
|
|
|
@@ -1545,7 +995,7 @@ int CPosPrinter::POS_MOVE_X()
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_SET_ABS_X(int x, int y)
|
|
|
+int CPosPrinterData::POS_SET_ABS_X(int x, int y)
|
|
|
{
|
|
|
unsigned char cx = (unsigned char)(x);
|
|
|
unsigned char cy = (unsigned char)(y);
|
|
|
@@ -1555,7 +1005,7 @@ int CPosPrinter::POS_SET_ABS_X(int x, int y)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int CPosPrinter::POS_SET_PRINT_AREA(int x, int y)
|
|
|
+int CPosPrinterData::POS_SET_PRINT_AREA(int x, int y)
|
|
|
{
|
|
|
unsigned char cx = (unsigned char)(x);
|
|
|
unsigned char cy = (unsigned char)(y);
|
|
|
@@ -1569,7 +1019,7 @@ int CPosPrinter::POS_SET_PRINT_AREA(int x, int y)
|
|
|
/*
|
|
|
*align_type:0 左对齐 1 居中对齐 2右对齐
|
|
|
**/
|
|
|
-int CPosPrinter::POS_TextOut(string abc, bool is_double_width, bool is_double_height, int align_type)
|
|
|
+int CPosPrinterData::POS_TextOut(string abc, bool is_double_width, bool is_double_height, int align_type)
|
|
|
{
|
|
|
if(is_double_width && is_double_height)
|
|
|
{
|
|
|
@@ -1627,7 +1077,7 @@ int CPosPrinter::POS_TextOut(string abc, bool is_double_width, bool is_double_he
|
|
|
/*
|
|
|
*打印机切纸,直接切不走纸
|
|
|
**/
|
|
|
-int CPosPrinter::POS_CutPaper()
|
|
|
+int CPosPrinterData::POS_CutPaper()
|
|
|
{
|
|
|
unsigned char s[4] = { 0x1D, 0x56, 0x01};
|
|
|
WriteBuf(s, 3);
|
|
|
@@ -1637,7 +1087,7 @@ int CPosPrinter::POS_CutPaper()
|
|
|
/*
|
|
|
*先转换成ANSI格式才能传进来
|
|
|
**/
|
|
|
-void CPosPrinter::POS_OutQRCode(std::string dataString)
|
|
|
+void CPosPrinterData::POS_OutQRCode(std::string dataString)
|
|
|
{
|
|
|
QRcode * qrCode = nullptr;
|
|
|
qrCode = QRcode_encodeString(dataString.c_str(), 0, QR_ECLEVEL_H, QR_MODE_8, 1);
|
|
|
@@ -1741,7 +1191,7 @@ void CPosPrinter::POS_OutQRCode(std::string dataString)
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::POS_OutBmp(std::wstring ImagePath)
|
|
|
+void CPosPrinterData::POS_OutBmp(std::wstring ImagePath)
|
|
|
{
|
|
|
//初始化
|
|
|
POS_Reset();
|
|
|
@@ -1839,7 +1289,7 @@ void CPosPrinter::POS_OutBmp(std::wstring ImagePath)
|
|
|
delete[] dataTmp;
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection)
|
|
|
+void CPosPrinterData::BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection)
|
|
|
{
|
|
|
char endTag[3] = {0x0d, 0x0a, 0x00};
|
|
|
|
|
|
@@ -1878,7 +1328,7 @@ void CPosPrinter::BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection)
|
|
|
/*
|
|
|
*前进一张纸
|
|
|
**/
|
|
|
-void CPosPrinter::BIAOQIAN_FORMFEED()
|
|
|
+void CPosPrinterData::BIAOQIAN_FORMFEED()
|
|
|
{
|
|
|
char endTag[3] = { 0x0d, 0x0a, 0x00 };
|
|
|
|
|
|
@@ -1888,7 +1338,7 @@ void CPosPrinter::BIAOQIAN_FORMFEED()
|
|
|
WriteData(formfeed);
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication)
|
|
|
+void CPosPrinterData::BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication)
|
|
|
{
|
|
|
char endTag[3] = { 0x0d, 0x0a, 0x00 };
|
|
|
|
|
|
@@ -1904,7 +1354,7 @@ void CPosPrinter::BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_mult
|
|
|
WriteData(text);
|
|
|
}
|
|
|
|
|
|
-std::string CPosPrinter::BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication)
|
|
|
+std::string CPosPrinterData::BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication)
|
|
|
{
|
|
|
char endTag[3] = { 0x0d, 0x0a, 0x00 };
|
|
|
|
|
|
@@ -1920,7 +1370,7 @@ std::string CPosPrinter::BIAOQIAN_TEXTGet(std::string content, int x, int y, int
|
|
|
return text;
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::BIAOQIAN_PRINT()
|
|
|
+void CPosPrinterData::BIAOQIAN_PRINT()
|
|
|
{
|
|
|
char endTag[3] = { 0x0d, 0x0a, 0x00 };
|
|
|
|
|
|
@@ -1930,7 +1380,7 @@ void CPosPrinter::BIAOQIAN_PRINT()
|
|
|
WriteData(print);
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::BIAOQIAN_CLS()
|
|
|
+void CPosPrinterData::BIAOQIAN_CLS()
|
|
|
{
|
|
|
char endTag[3] = { 0x0d, 0x0a, 0x00 };
|
|
|
|
|
|
@@ -1940,7 +1390,7 @@ void CPosPrinter::BIAOQIAN_CLS()
|
|
|
WriteData(cls);
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::CalWord(string s, int& nHanzi, int& nZimu)
|
|
|
+void CPosPrinterData::CalWord(string s, int& nHanzi, int& nZimu)
|
|
|
{
|
|
|
nHanzi = 0;
|
|
|
nZimu = 0;
|
|
|
@@ -1967,7 +1417,7 @@ void CPosPrinter::CalWord(string s, int& nHanzi, int& nZimu)
|
|
|
/*
|
|
|
*规格 1:58mm 2:80mm
|
|
|
**/
|
|
|
-std::vector<std::string>CPosPrinter::HandleFoodname(std::string oldname, int guige)
|
|
|
+std::vector<std::string>CPosPrinterData::HandleFoodname(std::string oldname, int guige)
|
|
|
{
|
|
|
std::vector<std::string> newnameArray;
|
|
|
int nHanzi, nZimu;
|
|
|
@@ -2062,7 +1512,7 @@ std::vector<std::string>CPosPrinter::HandleFoodname(std::string oldname, int gui
|
|
|
return newnameArray;
|
|
|
}
|
|
|
|
|
|
-std::string CPosPrinter::HandleFoodItemPrice(std::string oldprice, int guige)
|
|
|
+std::string CPosPrinterData::HandleFoodItemPrice(std::string oldprice, int guige)
|
|
|
{
|
|
|
double price = atof(oldprice.c_str());
|
|
|
|
|
|
@@ -2116,7 +1566,7 @@ std::string CPosPrinter::HandleFoodItemPrice(std::string oldprice, int guige)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-std::string CPosPrinter::HandleFoodQuantity(std::string oldquantity, int guige)
|
|
|
+std::string CPosPrinterData::HandleFoodQuantity(std::string oldquantity, int guige)
|
|
|
{
|
|
|
int n = atoi(oldquantity.c_str());
|
|
|
|
|
|
@@ -2155,7 +1605,7 @@ std::string CPosPrinter::HandleFoodQuantity(std::string oldquantity, int guige)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-std::string CPosPrinter::HandleFoodTotalPrice(std::string oldprice, int guige)
|
|
|
+std::string CPosPrinterData::HandleFoodTotalPrice(std::string oldprice, int guige)
|
|
|
{
|
|
|
double price = atof(oldprice.c_str());
|
|
|
|
|
|
@@ -2209,7 +1659,7 @@ std::string CPosPrinter::HandleFoodTotalPrice(std::string oldprice, int guige)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-std::vector<std::string> CPosPrinter::HandleBiaoqianFoodname(std::string oldname, int nBiaoqianWidth)
|
|
|
+std::vector<std::string> CPosPrinterData::HandleBiaoqianFoodname(std::string oldname, int nBiaoqianWidth)
|
|
|
{
|
|
|
std::vector<std::string> newnameArray;
|
|
|
int nHanzi, nZimu;
|