CPosPrinter.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "../pch/pch.h"
  3. #include "../order/CWaimaiOrder.h"
  4. //SetupDiGetInterfaceDeviceDetail所需要的输出长度,定义足够大
  5. #define INTERFACE_DETAIL_SIZE 1024
  6. //设备数量上限,假设16台上限
  7. #define MAX_DEVICE 16
  8. //USB类的GUID
  9. //const GUID USB_GUID = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}};
  10. const GUID USB_GUID = {0x28d78fad, 0x5a12, 0x11d1, {0xae, 0x5b, 0x00, 0x00, 0xf8, 0x03, 0xa8, 0xc2 }};
  11. //存储打印端口句柄的结构
  12. class PrinterHandle
  13. {
  14. public:
  15. HANDLE hPort;
  16. int type; //句柄类型 1:usb 2:并口 3:串口
  17. };
  18. class CPosPrinter
  19. {
  20. public:
  21. CPosPrinter();
  22. ~CPosPrinter();
  23. void PrintWaimaiOrderShouyin(CWaimaiOrder& order);
  24. void PrintWaimaiOrderChufang(CWaimaiOrder& order);
  25. private:
  26. bool InitShouyin();
  27. int GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath);
  28. int GetPrinterType(wstring vid, wstring pid);
  29. int WriteData(string meg);
  30. int WriteBuf(const char* buf, int len);
  31. bool PortTest(const TCHAR* Port, HANDLE hPort);
  32. int POS_Reset(void);
  33. int POS_FeedLine(void);
  34. int POS_Feed(void);
  35. int POS_SetMotionUnit(int x, int y);
  36. //设置横向跳格位置
  37. int POS_SET_MOVE_X();
  38. int POS_MOVE_X();
  39. int POS_SET_ABS_X(int x, int y);
  40. int POS_SET_PRINT_AREA(int x, int y);
  41. int POS_TextOut(string abc, bool is_double_width = false, bool is_double_height = false, int align_type = 0);
  42. int POS_CutPaper();
  43. int POS_OutQRCode();
  44. //字符空格计算的辅助函数
  45. void CalWord(string s, int& nHanzi, int& nZimu);
  46. //对名字进行换行处理
  47. std::vector<std::string> HandleFoodname(std::string oldname, int guige = 1);
  48. std::string HandleFoodItemPrice(std::string oldprice, int guige = 1);
  49. std::string HandleFoodQuantity(std::string oldquantity, int guige = 1);
  50. std::string HandleFoodTotalPrice(std::string oldprice, int guige = 1);
  51. private:
  52. std::vector<PrinterHandle> m_hPorts;
  53. boost::asio::io_service m_io;
  54. boost::asio::ip::tcp::socket m_socket;
  55. //这个是当前的输出模式,是收银模式还是厨房打印模式
  56. int m_type;
  57. };