|
@@ -20,10 +20,13 @@ CPosPrinter::~CPosPrinter()
|
|
|
bool CPosPrinter::InitShouyin()
|
|
bool CPosPrinter::InitShouyin()
|
|
|
{
|
|
{
|
|
|
//遍历USB设备,找到POS打印机路径
|
|
//遍历USB设备,找到POS打印机路径
|
|
|
|
|
+
|
|
|
//设备路径
|
|
//设备路径
|
|
|
TCHAR* szDevicePath[MAX_DEVICE];
|
|
TCHAR* szDevicePath[MAX_DEVICE];
|
|
|
|
|
+
|
|
|
//设置中文字符
|
|
//设置中文字符
|
|
|
setlocale(LC_CTYPE, "chs");
|
|
setlocale(LC_CTYPE, "chs");
|
|
|
|
|
+
|
|
|
TCHAR* Port = NULL;
|
|
TCHAR* Port = NULL;
|
|
|
|
|
|
|
|
//分配需要的空间
|
|
//分配需要的空间
|
|
@@ -34,6 +37,7 @@ bool CPosPrinter::InitShouyin()
|
|
|
|
|
|
|
|
//取设备路径
|
|
//取设备路径
|
|
|
int nDevice = GetDevicePath((LPGUID)&USB_GUID, szDevicePath);
|
|
int nDevice = GetDevicePath((LPGUID)&USB_GUID, szDevicePath);
|
|
|
|
|
+ LOG_INFO("nDevice:" << nDevice);
|
|
|
int i = 0;
|
|
int i = 0;
|
|
|
|
|
|
|
|
while(i < nDevice)
|
|
while(i < nDevice)
|
|
@@ -58,11 +62,12 @@ bool CPosPrinter::InitShouyin()
|
|
|
|
|
|
|
|
void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
{
|
|
{
|
|
|
- //设置模式,后面输出数据不会错
|
|
|
|
|
- m_type = 1;
|
|
|
|
|
|
|
+ //设置模式,后面输出数据不会错
|
|
|
|
|
+ m_type = 1;
|
|
|
|
|
|
|
|
//初始化收银打印机的链接
|
|
//初始化收银打印机的链接
|
|
|
bool ret = InitShouyin();
|
|
bool ret = InitShouyin();
|
|
|
|
|
+
|
|
|
if(ret == false)
|
|
if(ret == false)
|
|
|
{
|
|
{
|
|
|
LOG_INFO("打开收银打印机端口失败!");
|
|
LOG_INFO("打开收银打印机端口失败!");
|
|
@@ -223,20 +228,22 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::string firstLine = m_names[0];
|
|
std::string firstLine = m_names[0];
|
|
|
-
|
|
|
|
|
- int nGuige;
|
|
|
|
|
- if (guige == "58")
|
|
|
|
|
- {
|
|
|
|
|
- nGuige = 1;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- nGuige = 2;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
|
|
|
|
|
- std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
|
|
|
|
|
- std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ int nGuige;
|
|
|
|
|
+
|
|
|
|
|
+ if(guige == "58")
|
|
|
|
|
+ {
|
|
|
|
|
+ nGuige = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ nGuige = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
|
|
|
|
|
+ std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
|
|
|
|
|
+ std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
|
|
|
|
|
|
|
|
std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
|
|
std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
|
|
|
|
|
|
|
@@ -381,8 +388,8 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
|
|
|
|
|
void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
{
|
|
{
|
|
|
- //设置模式,后面输出数据不会错
|
|
|
|
|
- m_type = 2;
|
|
|
|
|
|
|
+ //设置模式,后面输出数据不会错
|
|
|
|
|
+ m_type = 2;
|
|
|
|
|
|
|
|
//读取厨房打印机信息
|
|
//读取厨房打印机信息
|
|
|
std::vector<ChufangPrinter> total_printers = CSetting::getChufangPrints();
|
|
std::vector<ChufangPrinter> total_printers = CSetting::getChufangPrints();
|
|
@@ -415,15 +422,18 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
std::string fenlei_ids = printer.fenlei_ids;
|
|
std::string fenlei_ids = printer.fenlei_ids;
|
|
|
|
|
|
|
|
std::vector<CWaimaiOrderItem> cur_printer_use;
|
|
std::vector<CWaimaiOrderItem> cur_printer_use;
|
|
|
|
|
+
|
|
|
if(fenlei == "0")
|
|
if(fenlei == "0")
|
|
|
{
|
|
{
|
|
|
cur_printer_use = order.m_order_items;
|
|
cur_printer_use = order.m_order_items;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
//如果开启了分类打印,就要比对了
|
|
//如果开启了分类打印,就要比对了
|
|
|
std::map<string, bool> ids_map;
|
|
std::map<string, bool> ids_map;
|
|
|
std::vector<string> ids = CLewaimaiString::Split(fenlei_ids, ",");
|
|
std::vector<string> ids = CLewaimaiString::Split(fenlei_ids, ",");
|
|
|
|
|
+
|
|
|
for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
|
|
for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
|
|
|
{
|
|
{
|
|
|
ids_map[(*it)] = true;
|
|
ids_map[(*it)] = true;
|
|
@@ -515,20 +525,22 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::string firstLine = m_names[0];
|
|
std::string firstLine = m_names[0];
|
|
|
-
|
|
|
|
|
- int nGuige;
|
|
|
|
|
- if (guige == "58")
|
|
|
|
|
- {
|
|
|
|
|
- nGuige = 1;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- nGuige = 2;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
|
|
|
|
|
- std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
|
|
|
|
|
- std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ int nGuige;
|
|
|
|
|
+
|
|
|
|
|
+ if(guige == "58")
|
|
|
|
|
+ {
|
|
|
|
|
+ nGuige = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ nGuige = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
|
|
|
|
|
+ std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
|
|
|
|
|
+ std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
|
|
|
|
|
|
|
|
std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
|
|
std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
|
|
|
|
|
|
|
@@ -559,6 +571,7 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
|
|
|
|
|
POS_CutPaper();
|
|
POS_CutPaper();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
POS_Reset();
|
|
POS_Reset();
|
|
@@ -669,7 +682,7 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- m_socket.close();
|
|
|
|
|
|
|
+ m_socket.close();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -690,17 +703,21 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
int nCount;
|
|
int nCount;
|
|
|
int nTotle;
|
|
int nTotle;
|
|
|
BOOL bResult;
|
|
BOOL bResult;
|
|
|
|
|
+
|
|
|
|
|
+ //这2个字符串,用于根据usb的名字对比是否为打印机设备
|
|
|
wstring strUSBPrint = TEXT("USB 打印支持");
|
|
wstring strUSBPrint = TEXT("USB 打印支持");
|
|
|
|
|
+ wstring strUSBPrint_EN = L"USB Printing Support";
|
|
|
|
|
+
|
|
|
// 取得一个该GUID相关的设备信息集句柄
|
|
// 取得一个该GUID相关的设备信息集句柄
|
|
|
hDevInfoSet = ::SetupDiGetClassDevs(lpGuid, // class GUID
|
|
hDevInfoSet = ::SetupDiGetClassDevs(lpGuid, // class GUID
|
|
|
NULL, // 无关键字
|
|
NULL, // 无关键字
|
|
|
NULL, // 不指定父窗口句柄
|
|
NULL, // 不指定父窗口句柄
|
|
|
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // 目前存在的设备
|
|
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // 目前存在的设备
|
|
|
|
|
|
|
|
- // 失败...
|
|
|
|
|
|
|
+// 失败...
|
|
|
if(hDevInfoSet == INVALID_HANDLE_VALUE)
|
|
if(hDevInfoSet == INVALID_HANDLE_VALUE)
|
|
|
{
|
|
{
|
|
|
- printf("failed \r\n");
|
|
|
|
|
|
|
+ LOG_INFO("failed \r\n");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -732,25 +749,28 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
|
SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
|
SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
lstrcpy(buf, _T("Unknown"));
|
|
lstrcpy(buf, _T("Unknown"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _tprintf(_T("buf = %s \r\n"), buf);
|
|
|
|
|
|
|
+ //LOG_INFO("buf:" << buf);
|
|
|
|
|
|
|
|
//是否是要找的设备类型
|
|
//是否是要找的设备类型
|
|
|
- if(_tcscmp(buf, strUSBPrint.c_str()) != 0)
|
|
|
|
|
|
|
+ if(_tcscmp(buf, strUSBPrint.c_str()) != 0 && _tcscmp(buf, strUSBPrint_EN.c_str()) != 0)
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _tprintf(_T("OK\r\n"));
|
|
|
|
|
|
|
+ //LOG_INFO("找到打印的USB设备!");
|
|
|
|
|
+
|
|
|
ifData.cbSize = sizeof(ifData);
|
|
ifData.cbSize = sizeof(ifData);
|
|
|
// 枚舉符合該GUID的設備接口
|
|
// 枚舉符合該GUID的設備接口
|
|
|
bResult = ::SetupDiEnumDeviceInterfaces(
|
|
bResult = ::SetupDiEnumDeviceInterfaces(
|
|
@@ -775,8 +795,10 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
{
|
|
{
|
|
|
// 复制设备路径到输出缓冲区
|
|
// 复制设备路径到输出缓冲区
|
|
|
::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);
|
|
::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);
|
|
|
|
|
+
|
|
|
// 调整计数值
|
|
// 调整计数值
|
|
|
nCount++;
|
|
nCount++;
|
|
|
|
|
+
|
|
|
_tprintf(_T("Cnt = %d,pDetail->DevicePath =%s\r\n"), nCount, pDetail->DevicePath);
|
|
_tprintf(_T("Cnt = %d,pDetail->DevicePath =%s\r\n"), nCount, pDetail->DevicePath);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -785,8 +807,10 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
|
|
|
|
|
// 释放设备接口数据空间
|
|
// 释放设备接口数据空间
|
|
|
::GlobalFree(pDetail);
|
|
::GlobalFree(pDetail);
|
|
|
|
|
+
|
|
|
// 关闭设备信息集句柄
|
|
// 关闭设备信息集句柄
|
|
|
::SetupDiDestroyDeviceInfoList(hDevInfoSet);
|
|
::SetupDiDestroyDeviceInfoList(hDevInfoSet);
|
|
|
|
|
+
|
|
|
return nCount;
|
|
return nCount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -800,16 +824,17 @@ int CPosPrinter::WriteData(string msg)
|
|
|
|
|
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- m_socket.write_some(boost::asio::buffer(msg.c_str(), msg.length()));
|
|
|
|
|
- }
|
|
|
|
|
- catch (const std::exception& e)
|
|
|
|
|
- {
|
|
|
|
|
- LOG_INFO(e.what());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ m_socket.write_some(boost::asio::buffer(msg.c_str(), msg.length()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ catch(const std::exception& e)
|
|
|
|
|
+ {
|
|
|
|
|
+ LOG_INFO(e.what());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -823,16 +848,17 @@ int CPosPrinter::WriteBuf(char* buf, int len)
|
|
|
|
|
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- m_socket.write_some(boost::asio::buffer(buf, len));
|
|
|
|
|
- }
|
|
|
|
|
- catch (const std::exception& e)
|
|
|
|
|
- {
|
|
|
|
|
- LOG_INFO(e.what());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ m_socket.write_some(boost::asio::buffer(buf, len));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ catch(const std::exception& e)
|
|
|
|
|
+ {
|
|
|
|
|
+ LOG_INFO(e.what());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|