Advertisement
Guest User

Untitled

a guest
May 25th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.27 KB | None | 0 0
  1. /*
  2.  * Description: Example source code for using the SAM4S POS Printer Linux library.  The example
  3.  *              demonstrates how to Print a Sample Receipt
  4.  *
  5.  * Copyright:   (c) 2014 SHC Corporation. All rights reserved.
  6.  */
  7.  
  8. #include <string>
  9. #include <iostream>
  10. #include <string.h>
  11. #include "PrinterInterface.h"
  12.  
  13. #if 0
  14.  
  15. typedef enum __PRINTER_STATUS__
  16. {
  17.     /* No Error */
  18.     STATUS_NO_ERROR = 0x00,
  19.     /*Printer is online */
  20.     STATUS_PRINTER_ONLINE = 0X01,
  21.     /* Printer is offline */
  22.     STATUS_PRINTER_OFFLINE = 0x02,
  23.     /*Drawer open/close signal is LOW (connector pin 3)*/
  24.     STATUS_DRAWER_OPEN = 0x03,
  25.     STATUS_DRAWER_OPEN_HIGH = 0x04,
  26.     STATUS_DRAWER_OPEN_LOW = 0x05,
  27.     /*Drawer open/close signal is HIGH (connector pin 3).*/
  28.     STATUS_DRAWER_CLOSED = 0x06,
  29.     /* Cover is open */
  30.     STATUS_PRINTER_COVER_OPEN = 0x07,
  31.     /*Cover is closed */
  32.     STATUS_PRINTER_COVER_CLOSED =  0x09,
  33.     /*Paper is not being fed by using the PAPER FEED button*/
  34.     STATUS_PAPERFEED_NOT_FED =  0x10,
  35.     /* Paper is being fed by the PAPER FEED button*/
  36.     STATUS_PAPERFEED_FED = 0x11,
  37.     /*Printing stops due to paper end.*/
  38.     STATUS_PAPER_END = 0x12,
  39.     /*No paper-end stops*/
  40.     STATUS_NO_PAPER = 0x13,
  41.    /* Auto-cutter error occurs. */
  42.     STATUS_ERROR_AUTO_CUTTER = 0x14,
  43.     /*Unrecoverable error occurs.*/
  44.     STATUS_ERROR_UNRECOVERABLE = 0x15,
  45.     /*Auto recoverable error occurs*/
  46.     STATUS_ERROR_AUTO_RECOVERABLE = 0x16,
  47.     /*Paper roll near-end sensor. Paper adequate.*/
  48.     STATUS_PAPER_ADEQUATE = 0x17,
  49.     /*Paper near-end is detected by the paper roll near-end sensor.*/
  50.     STATUS_PAPER_NEAR_END = 0x18,
  51.     /*Not roll end sensor. Paper present.*/
  52.     STATUS_NOT_ROLL_END_SENSOR = 0x19,
  53.     /*Paper is detected by the paper roll end sensor.*/
  54.     STATUS_PAPER_DETECTED = 0x20
  55. }PRINTER_STATUS;
  56. #endif
  57.  
  58. int  SAM4S_PrintSampleReceipt1(SAM4S_HANDLE handle);
  59. int  SAM4S_PrintSampleReceipt2(SAM4S_HANDLE handle);
  60. int  SAM4S_PrintSampleReceipt3(SAM4S_HANDLE handle);
  61. int  SAM4S_PrintSampleReceipt4(SAM4S_HANDLE handle);
  62.  
  63.  
  64. int PSCallBack(SAM4S_HANDLE, PRINTER_STATUS ps)
  65. {
  66.     std::cout << "Printer Status is " << ps;
  67.     return 0;
  68. }
  69.  
  70. /*-----------------------------------------------------------------------------
  71. -----------------------------------------------------------------------------*/
  72. int main()
  73. {
  74.     std::string fileName;
  75.     /* Enumerate the hardware on the system, and identify the target device */
  76.     SAM4S_HANDLE hardwareDetector = SAM4S_CreateHardwareDetector(NULL);
  77.  
  78.  
  79.     /**********Enable Below Line to Connect to IsB Port Printer***********/
  80.     std::string strXML = "<device><type>USB</type><path>None</path></device>" ;
  81.     /**********Enable Below Line to Connect to Serial Port Printer***********/
  82.     //std::string strXML = "<device><type>Serial</type><path> /dev/ttyS0</path></device>" ;
  83.     /**********Enable Below Line to Connect to Parallel Port Printer***********/
  84.     //std::string strXML = "<device><type>IEEE1284</type><path>/dev/lp0</path></device>" ;
  85.     /**********Enable Below Line to Connect to Ethernet Port Printer ***********/
  86.     //std::string strXML = "<device><type>Serial</type><path>10.1.6.35:6100</path></device>" ; //IPAddress:Port
  87.  
  88.     /* Perform the specified action on the target device */
  89.  
  90.     SAM4S_HANDLE deviceHandle = SAM4S_CreateDevicePointer((char *)strXML.c_str(), strXML.length());
  91.     SAM4S_PrintBarcode(deviceHandle, BARCODE_TYPE_PDF417,"111111111",strlen("111111111") );
  92.     SAM4S_PrintSampleReceipt1(deviceHandle);
  93.     SAM4S_PrintSampleReceipt2(deviceHandle);
  94.     SAM4S_PrintSampleReceipt3(deviceHandle);
  95.     SAM4S_PrintSampleReceipt4(deviceHandle);
  96.     SAM4S_PrintText(deviceHandle,"Hello World",strlen("Hello World"),0);
  97.     SAM4S_PrintImage(deviceHandle,"./camel8.bmp");
  98.     SAM4S_DestroyHardwareDetector(hardwareDetector);
  99.     SAM4S_DestroyDevicePointer(deviceHandle);
  100.  
  101.     return 0;
  102. } /* main */
  103.  
  104. int  SAM4S_PrintSampleReceipt1(SAM4S_HANDLE handle)
  105. {
  106.  
  107.     SelectCharFontADoubleHeight(handle);
  108.     SetCenterAllign(handle);
  109.     PrintText(handle,"JILABA SUPER MARKET");
  110.     LineFeed(handle);
  111.     SetCenterAllign(handle);
  112.     CancelDoubleHeight(handle);
  113.     PrintText(handle,"Chennai - 32.");
  114.     LineFeed(handle);
  115.     SetCenterAllign(handle);
  116.     SelectCharFontB(handle);
  117.     PrintText(handle,"January 14, 2002 15:00");
  118.     PrintNFeedNLines(handle,3);
  119.     SetLeftAllign(handle);
  120.     SelectCharFontB(handle);
  121.     PrintText(handle,"TM-U210B                              $20.00");
  122.     LineFeed(handle);
  123.     PrintText(handle,"TM-U210D                              $21.00");
  124.     LineFeed(handle);
  125.     PrintText(handle,"PS-170                                $17.00");
  126.     LineFeed(handle);
  127.     SelectCharFontADoubleHeight(handle);
  128.     PrintText(handle,"TOTAL                       $58.00");
  129.     LineFeed(handle);
  130.     CancelDoubleHeight(handle);
  131.     PrintText(handle,"---------------------------------------");
  132.     LineFeed(handle);
  133.     PrintText(handle,"PAID                        $60.00");
  134.     LineFeed(handle);
  135.     PrintText(handle,"CHANGE                      $ 2.00");
  136.     LineFeed(handle);
  137.     LineFeed(handle);
  138.     SelectCharFontADoubleHeight(handle);
  139.     SetCenterAllign(handle);
  140.     PrintText(handle,"Thank You !");
  141.     LineFeed(handle);
  142.     CancelDoubleHeight(handle);
  143.     PrintNFeedNLines(handle,2);
  144.     SAM4S_FeedAndCutPaper(handle);
  145.     return 0;
  146.  
  147.  
  148. }
  149.  
  150. int  SAM4S_PrintSampleReceipt2(SAM4S_HANDLE handle)
  151. {
  152.  
  153.     SelectCharFontADoubleHeight(handle);
  154.     SetCenterAllign(handle);
  155.     TurnBoldON(handle);
  156.     PrintText(handle,"PAZHAMUDHIR CHOLAI");
  157.     LineFeed(handle);
  158.     TurnBoldOFF(handle);
  159.     SetCenterAllign(handle);
  160.     CancelDoubleHeight(handle);
  161.     PrintText(handle,"220, Velachery Main Road, Camp Road.");
  162.     LineFeed(handle);
  163.     PrintText(handle,"Selaiyur, Chennai - 600 073");
  164.     LineFeed(handle);
  165.     PrintText(handle, "Phone : 42811999");
  166.     LineFeed(handle);
  167.     SetLeftAllign(handle);
  168.     PrintText(handle, "Date : 10/Mar/2014 8:17 pm");
  169.     LineFeed(handle);
  170.     TurnBoldON(handle);
  171.     PrintText(handle, "Bill No : 4/31      User : franklin");
  172.     TurnBoldOFF(handle);
  173.     PrintNFeedNLines(handle,2);;
  174.     PrintText(handle, "Sales Assistant : franklin");
  175.     LineFeed(handle);
  176.     PrintText(handle,"----------------------------------------");
  177.     LineFeed(handle);
  178.     PrintText(handle, "Product       Rate     Qty       Amount");
  179.     LineFeed(handle);
  180.     PrintText(handle,"----------------------------------------");
  181.     LineFeed(handle);
  182.     PrintText(handle,"SAPOTA        40.00   0.500       21.80");
  183.     LineFeed(handle);
  184.     PrintText(handle,"PUMPKIN       16.00   0.645        7.44");
  185.     LineFeed(handle);
  186.     PrintText(handle,"GINGER       110.00   0.055        6.05");
  187.     LineFeed(handle);
  188.     PrintText(handle,"CARROT        28.00   0.490       13.72");
  189.     LineFeed(handle);
  190.     PrintText(handle,"TOMOTO         9.00   1.160       10.44");
  191.     LineFeed(handle);
  192.     PrintText(handle,"PINE APPLE    30.00       1       30.00");
  193.     LineFeed(handle);
  194.     PrintText(handle,"COCOUNT       18.00       1       18.00");
  195.     LineFeed(handle);
  196.     PrintText(handle,"BEANS         46.00   0.410       18.86");
  197.     LineFeed(handle);
  198.     PrintText(handle,"LEMON         66.00   0.175       11.55");
  199.     LineFeed(handle);
  200.     PrintText(handle,"BIG CARRY      2.00       2        4.00");
  201.     LineFeed(handle);
  202.     PrintText(handle,"                                =======");
  203.     LineFeed(handle);
  204.     PrintText(handle,"Total Items  10 Total Amount     141.86");
  205.     LineFeed(handle);
  206.     PrintText(handle,"                                =======");
  207.     LineFeed(handle);
  208.     SelectCharFontADoubleHeight(handle);
  209.     PrintText(handle," Net Amount (Rounded Off)        142.00");
  210.     CancelDoubleHeight(handle);
  211.     LineFeed(handle);
  212.     PrintText(handle,"                                =======");
  213.     LineFeed(handle);
  214.     PrintText(handle,"***Tenders***");
  215.     LineFeed(handle);
  216.     PrintText(handle,"Paid    Rs.   500.00");
  217.     LineFeed(handle);
  218.     PrintText(handle,"Balance Rs.   358.00");
  219.     LineFeed(handle);
  220.     SetCenterAllign(handle);
  221.     SAM4S_PrintBarcode(handle , BARCODE_TYPE_PDF417,"142",3);
  222.     PrintNFeedNLines(handle,2);
  223.     SelectCharFontB(handle);
  224.     SetCenterAllign(handle);
  225.     PrintText(handle,"Thank You ! Visit Again");
  226.     PrintNFeedNLines(handle,4);
  227.     SAM4S_FeedAndCutPaper(handle);
  228.     return 0;
  229. }
  230.  
  231. int __stdcall SAM4S_PrintSampleReceipt3(SAM4S_HANDLE handle)
  232.  
  233. {
  234.  
  235.     SelectCharFontADoubleHeight(handle);
  236.     SetCenterAllign(handle);
  237.     Set_Motion_Units(handle,80,80);
  238.     Set_Reverse_PrintingON(handle);
  239.     PrintText(handle," Little Hong Kong ");
  240.     Set_Reverse_PrintingOFF(handle);
  241.     LineFeed(handle);
  242.     CancelDoubleHeight(handle);
  243.     SelectCharFontB(handle);
  244.     TurnUnderlineONThin(handle);
  245.     PrintText(handle,"We understand your world");
  246.     LineFeed(handle);
  247.     TurnUnderlineOFF(handle);
  248.     PrintText(handle,"South Korea, Asia");
  249.     PrintNFeedNLines(handle,2);
  250.     SelectCharFontADoubleHeight(handle);
  251.     TurnBoldON(handle);
  252.     PrintText(handle,"Sale");
  253.     CancelDoubleHeight(handle);
  254.     TurnBoldOFF(handle);
  255.     PrintNFeedNLines(handle,1);
  256.     SelectCharFontB(handle);
  257.     Turn90ClockwiseRotationON(handle);
  258.     SelectCharFontA(handle);
  259.     PrintText(handle," Rotataion Text ");
  260.     Turn90ClockwiseRotationOFF(handle);
  261.     SetAbsolutePosition(handle,60,70);
  262.     LineFeed(handle);
  263.     PrintText(handle,"MasterCard");
  264.     LineFeed(handle);
  265.     PrintText(handle,"CARD NUM : **** **** **** 1234 Chip");
  266.     LineFeed(handle);
  267.     PrintText(handle,"EXP DATE : **/** CARD TYPE : CHIP CARD");
  268.     LineFeed(handle);
  269.     SetLeftAllign(handle);
  270.     SelectCharFontA(handle);
  271.     PrintText(handle,"Char Size Height 2 to 8");
  272.     LineFeed(handle);
  273.     SelectCharSizeHeight2(handle);
  274.     PrintText(handle,"AAAA");
  275.     LineFeed(handle);
  276.     SelectCharSizeHeight3(handle);
  277.     PrintText(handle,"BBBB");
  278.     LineFeed(handle);
  279.     SelectCharSizeHeight4(handle);
  280.     PrintText(handle,"CCCC");
  281.     LineFeed(handle);
  282.     SelectCharSizeHeight5(handle);
  283.     PrintText(handle,"DDDD");
  284.     LineFeed(handle);
  285.     SelectCharSizeHeight6(handle);
  286.     PrintText(handle,"EEEE");
  287.     LineFeed(handle);
  288.     SelectCharSizeHeight7(handle);
  289.     PrintText(handle,"FFFF");
  290.     LineFeed(handle);
  291.     SelectCharSizeHeight8(handle);
  292.     PrintText(handle,"GGGGG");
  293.     LineFeed(handle);
  294.     SelectCharSizeNormal(handle);
  295.     PrintText(handle,"Char Size Width 2 to 8");
  296.     LineFeed(handle);
  297.     SelectCharSizeWidth2(handle);
  298.     PrintText(handle,"AAAAA");
  299.     LineFeed(handle);
  300.     SelectCharSizeWidth3(handle);
  301.     PrintText(handle,"BBBBB");
  302.     LineFeed(handle);
  303.     SelectCharSizeWidth4(handle);
  304.     PrintText(handle,"CCCCC");
  305.     LineFeed(handle);
  306.     SelectCharSizeWidth5(handle);
  307.     PrintText(handle,"DDDDD");
  308.     LineFeed(handle);
  309.     SelectCharSizeWidth6(handle);
  310.     PrintText(handle,"EEEEE");
  311.     LineFeed(handle);
  312.     SelectCharSizeWidth7(handle);
  313.     PrintText(handle,"FFFFF");
  314.     LineFeed(handle);
  315.     SelectCharSizeWidth8(handle);
  316.     PrintText(handle,"GGGGG");
  317.     LineFeed(handle);
  318.     SelectCharSizeNormal(handle);
  319.     LineFeed(handle);
  320.     PrintNFeedNLines(handle,4);
  321.     SAM4S_FeedAndCutPaper(handle);
  322.     return 0;
  323.  
  324. }
  325.  
  326. int  SAM4S_PrintSampleReceipt4(SAM4S_HANDLE handle)
  327.  
  328. {
  329.     SetLeftAllign(handle);
  330.     PrintText(handle," Barcode Test ");
  331.     LineFeed(handle);
  332.     PrintText(handle," ************** ");
  333.     LineFeed(handle);
  334.     PrintText(handle," UPCA Barcode Test ");
  335.     LineFeed(handle);
  336.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_UPCA,"0123456789",strlen("0123456789") );
  337.     PrintText(handle," EAN8 Barcode Test ");
  338.     PrintNFeedNLines(handle,4);
  339.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_EAN8,"0123456789",strlen("0123456789") );
  340.     PrintText(handle," EAN13 Barcode Test ");
  341.     PrintNFeedNLines(handle,4);
  342.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_EAN13,"0123456789",strlen("0123456789") );\
  343.     PrintText(handle,"ITF Barcode Test ");
  344.     PrintNFeedNLines(handle,4);
  345.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_ITF,"0123456789",strlen("0123456789") );
  346.     PrintText(handle,"CodaBar Barcode Test ");
  347.     PrintNFeedNLines(handle,4);
  348.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODABAR,"0123456789",strlen("0123456789") );
  349.     PrintText(handle," Code39 Barcode Test ");
  350.     PrintNFeedNLines(handle,4);
  351.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODE39,"0123456789",strlen("0123456789") );
  352.     PrintText(handle,"Code93 Barcode Test ");
  353.     PrintNFeedNLines(handle,4);
  354.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODE93,"0123456789",strlen("0123456789") );
  355.     PrintNFeedNLines(handle,4);
  356.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODE128,"0123456789",strlen("0123456789") );
  357.     PrintText(handle,"QR Code Barcode Test ");
  358.     PrintNFeedNLines(handle,4);
  359.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_QRCODE,"SAM4STESTPRINT",strlen("SAM4STESTPRINT") );
  360.     PrintText(handle,"PDF417 Barcode Test ");
  361.     PrintNFeedNLines(handle,4);
  362.     SAM4S_PrintBarcode(handle, BARCODE_TYPE_PDF417,"SAM4STESTPRINT",strlen("SAM4STESTPRINT") );
  363.     PrintNFeedNLines(handle,4);
  364.     SelectCharFontADoubleHeight(handle);
  365.     PrintText(handle,"THE END ");
  366.     LineFeed(handle);
  367.     PrintNFeedNLines(handle,4);
  368.     SAM4S_FeedAndCutPaper(handle);
  369.  
  370.     return 0;
  371.  
  372. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement