Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Description: Example source code for using the SAM4S POS Printer Linux library. The example
- * demonstrates how to Print a Sample Receipt
- *
- * Copyright: (c) 2014 SHC Corporation. All rights reserved.
- */
- #include <string>
- #include <iostream>
- #include <string.h>
- #include "PrinterInterface.h"
- #if 0
- typedef enum __PRINTER_STATUS__
- {
- /* No Error */
- STATUS_NO_ERROR = 0x00,
- /*Printer is online */
- STATUS_PRINTER_ONLINE = 0X01,
- /* Printer is offline */
- STATUS_PRINTER_OFFLINE = 0x02,
- /*Drawer open/close signal is LOW (connector pin 3)*/
- STATUS_DRAWER_OPEN = 0x03,
- STATUS_DRAWER_OPEN_HIGH = 0x04,
- STATUS_DRAWER_OPEN_LOW = 0x05,
- /*Drawer open/close signal is HIGH (connector pin 3).*/
- STATUS_DRAWER_CLOSED = 0x06,
- /* Cover is open */
- STATUS_PRINTER_COVER_OPEN = 0x07,
- /*Cover is closed */
- STATUS_PRINTER_COVER_CLOSED = 0x09,
- /*Paper is not being fed by using the PAPER FEED button*/
- STATUS_PAPERFEED_NOT_FED = 0x10,
- /* Paper is being fed by the PAPER FEED button*/
- STATUS_PAPERFEED_FED = 0x11,
- /*Printing stops due to paper end.*/
- STATUS_PAPER_END = 0x12,
- /*No paper-end stops*/
- STATUS_NO_PAPER = 0x13,
- /* Auto-cutter error occurs. */
- STATUS_ERROR_AUTO_CUTTER = 0x14,
- /*Unrecoverable error occurs.*/
- STATUS_ERROR_UNRECOVERABLE = 0x15,
- /*Auto recoverable error occurs*/
- STATUS_ERROR_AUTO_RECOVERABLE = 0x16,
- /*Paper roll near-end sensor. Paper adequate.*/
- STATUS_PAPER_ADEQUATE = 0x17,
- /*Paper near-end is detected by the paper roll near-end sensor.*/
- STATUS_PAPER_NEAR_END = 0x18,
- /*Not roll end sensor. Paper present.*/
- STATUS_NOT_ROLL_END_SENSOR = 0x19,
- /*Paper is detected by the paper roll end sensor.*/
- STATUS_PAPER_DETECTED = 0x20
- }PRINTER_STATUS;
- #endif
- int SAM4S_PrintSampleReceipt1(SAM4S_HANDLE handle);
- int SAM4S_PrintSampleReceipt2(SAM4S_HANDLE handle);
- int SAM4S_PrintSampleReceipt3(SAM4S_HANDLE handle);
- int SAM4S_PrintSampleReceipt4(SAM4S_HANDLE handle);
- int PSCallBack(SAM4S_HANDLE, PRINTER_STATUS ps)
- {
- std::cout << "Printer Status is " << ps;
- return 0;
- }
- /*-----------------------------------------------------------------------------
- -----------------------------------------------------------------------------*/
- int main()
- {
- std::string fileName;
- /* Enumerate the hardware on the system, and identify the target device */
- SAM4S_HANDLE hardwareDetector = SAM4S_CreateHardwareDetector(NULL);
- /**********Enable Below Line to Connect to IsB Port Printer***********/
- std::string strXML = "<device><type>USB</type><path>None</path></device>" ;
- /**********Enable Below Line to Connect to Serial Port Printer***********/
- //std::string strXML = "<device><type>Serial</type><path> /dev/ttyS0</path></device>" ;
- /**********Enable Below Line to Connect to Parallel Port Printer***********/
- //std::string strXML = "<device><type>IEEE1284</type><path>/dev/lp0</path></device>" ;
- /**********Enable Below Line to Connect to Ethernet Port Printer ***********/
- //std::string strXML = "<device><type>Serial</type><path>10.1.6.35:6100</path></device>" ; //IPAddress:Port
- /* Perform the specified action on the target device */
- SAM4S_HANDLE deviceHandle = SAM4S_CreateDevicePointer((char *)strXML.c_str(), strXML.length());
- SAM4S_PrintBarcode(deviceHandle, BARCODE_TYPE_PDF417,"111111111",strlen("111111111") );
- SAM4S_PrintSampleReceipt1(deviceHandle);
- SAM4S_PrintSampleReceipt2(deviceHandle);
- SAM4S_PrintSampleReceipt3(deviceHandle);
- SAM4S_PrintSampleReceipt4(deviceHandle);
- SAM4S_PrintText(deviceHandle,"Hello World",strlen("Hello World"),0);
- SAM4S_PrintImage(deviceHandle,"./camel8.bmp");
- SAM4S_DestroyHardwareDetector(hardwareDetector);
- SAM4S_DestroyDevicePointer(deviceHandle);
- return 0;
- } /* main */
- int SAM4S_PrintSampleReceipt1(SAM4S_HANDLE handle)
- {
- SelectCharFontADoubleHeight(handle);
- SetCenterAllign(handle);
- PrintText(handle,"JILABA SUPER MARKET");
- LineFeed(handle);
- SetCenterAllign(handle);
- CancelDoubleHeight(handle);
- PrintText(handle,"Chennai - 32.");
- LineFeed(handle);
- SetCenterAllign(handle);
- SelectCharFontB(handle);
- PrintText(handle,"January 14, 2002 15:00");
- PrintNFeedNLines(handle,3);
- SetLeftAllign(handle);
- SelectCharFontB(handle);
- PrintText(handle,"TM-U210B $20.00");
- LineFeed(handle);
- PrintText(handle,"TM-U210D $21.00");
- LineFeed(handle);
- PrintText(handle,"PS-170 $17.00");
- LineFeed(handle);
- SelectCharFontADoubleHeight(handle);
- PrintText(handle,"TOTAL $58.00");
- LineFeed(handle);
- CancelDoubleHeight(handle);
- PrintText(handle,"---------------------------------------");
- LineFeed(handle);
- PrintText(handle,"PAID $60.00");
- LineFeed(handle);
- PrintText(handle,"CHANGE $ 2.00");
- LineFeed(handle);
- LineFeed(handle);
- SelectCharFontADoubleHeight(handle);
- SetCenterAllign(handle);
- PrintText(handle,"Thank You !");
- LineFeed(handle);
- CancelDoubleHeight(handle);
- PrintNFeedNLines(handle,2);
- SAM4S_FeedAndCutPaper(handle);
- return 0;
- }
- int SAM4S_PrintSampleReceipt2(SAM4S_HANDLE handle)
- {
- SelectCharFontADoubleHeight(handle);
- SetCenterAllign(handle);
- TurnBoldON(handle);
- PrintText(handle,"PAZHAMUDHIR CHOLAI");
- LineFeed(handle);
- TurnBoldOFF(handle);
- SetCenterAllign(handle);
- CancelDoubleHeight(handle);
- PrintText(handle,"220, Velachery Main Road, Camp Road.");
- LineFeed(handle);
- PrintText(handle,"Selaiyur, Chennai - 600 073");
- LineFeed(handle);
- PrintText(handle, "Phone : 42811999");
- LineFeed(handle);
- SetLeftAllign(handle);
- PrintText(handle, "Date : 10/Mar/2014 8:17 pm");
- LineFeed(handle);
- TurnBoldON(handle);
- PrintText(handle, "Bill No : 4/31 User : franklin");
- TurnBoldOFF(handle);
- PrintNFeedNLines(handle,2);;
- PrintText(handle, "Sales Assistant : franklin");
- LineFeed(handle);
- PrintText(handle,"----------------------------------------");
- LineFeed(handle);
- PrintText(handle, "Product Rate Qty Amount");
- LineFeed(handle);
- PrintText(handle,"----------------------------------------");
- LineFeed(handle);
- PrintText(handle,"SAPOTA 40.00 0.500 21.80");
- LineFeed(handle);
- PrintText(handle,"PUMPKIN 16.00 0.645 7.44");
- LineFeed(handle);
- PrintText(handle,"GINGER 110.00 0.055 6.05");
- LineFeed(handle);
- PrintText(handle,"CARROT 28.00 0.490 13.72");
- LineFeed(handle);
- PrintText(handle,"TOMOTO 9.00 1.160 10.44");
- LineFeed(handle);
- PrintText(handle,"PINE APPLE 30.00 1 30.00");
- LineFeed(handle);
- PrintText(handle,"COCOUNT 18.00 1 18.00");
- LineFeed(handle);
- PrintText(handle,"BEANS 46.00 0.410 18.86");
- LineFeed(handle);
- PrintText(handle,"LEMON 66.00 0.175 11.55");
- LineFeed(handle);
- PrintText(handle,"BIG CARRY 2.00 2 4.00");
- LineFeed(handle);
- PrintText(handle," =======");
- LineFeed(handle);
- PrintText(handle,"Total Items 10 Total Amount 141.86");
- LineFeed(handle);
- PrintText(handle," =======");
- LineFeed(handle);
- SelectCharFontADoubleHeight(handle);
- PrintText(handle," Net Amount (Rounded Off) 142.00");
- CancelDoubleHeight(handle);
- LineFeed(handle);
- PrintText(handle," =======");
- LineFeed(handle);
- PrintText(handle,"***Tenders***");
- LineFeed(handle);
- PrintText(handle,"Paid Rs. 500.00");
- LineFeed(handle);
- PrintText(handle,"Balance Rs. 358.00");
- LineFeed(handle);
- SetCenterAllign(handle);
- SAM4S_PrintBarcode(handle , BARCODE_TYPE_PDF417,"142",3);
- PrintNFeedNLines(handle,2);
- SelectCharFontB(handle);
- SetCenterAllign(handle);
- PrintText(handle,"Thank You ! Visit Again");
- PrintNFeedNLines(handle,4);
- SAM4S_FeedAndCutPaper(handle);
- return 0;
- }
- int __stdcall SAM4S_PrintSampleReceipt3(SAM4S_HANDLE handle)
- {
- SelectCharFontADoubleHeight(handle);
- SetCenterAllign(handle);
- Set_Motion_Units(handle,80,80);
- Set_Reverse_PrintingON(handle);
- PrintText(handle," Little Hong Kong ");
- Set_Reverse_PrintingOFF(handle);
- LineFeed(handle);
- CancelDoubleHeight(handle);
- SelectCharFontB(handle);
- TurnUnderlineONThin(handle);
- PrintText(handle,"We understand your world");
- LineFeed(handle);
- TurnUnderlineOFF(handle);
- PrintText(handle,"South Korea, Asia");
- PrintNFeedNLines(handle,2);
- SelectCharFontADoubleHeight(handle);
- TurnBoldON(handle);
- PrintText(handle,"Sale");
- CancelDoubleHeight(handle);
- TurnBoldOFF(handle);
- PrintNFeedNLines(handle,1);
- SelectCharFontB(handle);
- Turn90ClockwiseRotationON(handle);
- SelectCharFontA(handle);
- PrintText(handle," Rotataion Text ");
- Turn90ClockwiseRotationOFF(handle);
- SetAbsolutePosition(handle,60,70);
- LineFeed(handle);
- PrintText(handle,"MasterCard");
- LineFeed(handle);
- PrintText(handle,"CARD NUM : **** **** **** 1234 Chip");
- LineFeed(handle);
- PrintText(handle,"EXP DATE : **/** CARD TYPE : CHIP CARD");
- LineFeed(handle);
- SetLeftAllign(handle);
- SelectCharFontA(handle);
- PrintText(handle,"Char Size Height 2 to 8");
- LineFeed(handle);
- SelectCharSizeHeight2(handle);
- PrintText(handle,"AAAA");
- LineFeed(handle);
- SelectCharSizeHeight3(handle);
- PrintText(handle,"BBBB");
- LineFeed(handle);
- SelectCharSizeHeight4(handle);
- PrintText(handle,"CCCC");
- LineFeed(handle);
- SelectCharSizeHeight5(handle);
- PrintText(handle,"DDDD");
- LineFeed(handle);
- SelectCharSizeHeight6(handle);
- PrintText(handle,"EEEE");
- LineFeed(handle);
- SelectCharSizeHeight7(handle);
- PrintText(handle,"FFFF");
- LineFeed(handle);
- SelectCharSizeHeight8(handle);
- PrintText(handle,"GGGGG");
- LineFeed(handle);
- SelectCharSizeNormal(handle);
- PrintText(handle,"Char Size Width 2 to 8");
- LineFeed(handle);
- SelectCharSizeWidth2(handle);
- PrintText(handle,"AAAAA");
- LineFeed(handle);
- SelectCharSizeWidth3(handle);
- PrintText(handle,"BBBBB");
- LineFeed(handle);
- SelectCharSizeWidth4(handle);
- PrintText(handle,"CCCCC");
- LineFeed(handle);
- SelectCharSizeWidth5(handle);
- PrintText(handle,"DDDDD");
- LineFeed(handle);
- SelectCharSizeWidth6(handle);
- PrintText(handle,"EEEEE");
- LineFeed(handle);
- SelectCharSizeWidth7(handle);
- PrintText(handle,"FFFFF");
- LineFeed(handle);
- SelectCharSizeWidth8(handle);
- PrintText(handle,"GGGGG");
- LineFeed(handle);
- SelectCharSizeNormal(handle);
- LineFeed(handle);
- PrintNFeedNLines(handle,4);
- SAM4S_FeedAndCutPaper(handle);
- return 0;
- }
- int SAM4S_PrintSampleReceipt4(SAM4S_HANDLE handle)
- {
- SetLeftAllign(handle);
- PrintText(handle," Barcode Test ");
- LineFeed(handle);
- PrintText(handle," ************** ");
- LineFeed(handle);
- PrintText(handle," UPCA Barcode Test ");
- LineFeed(handle);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_UPCA,"0123456789",strlen("0123456789") );
- PrintText(handle," EAN8 Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_EAN8,"0123456789",strlen("0123456789") );
- PrintText(handle," EAN13 Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_EAN13,"0123456789",strlen("0123456789") );\
- PrintText(handle,"ITF Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_ITF,"0123456789",strlen("0123456789") );
- PrintText(handle,"CodaBar Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODABAR,"0123456789",strlen("0123456789") );
- PrintText(handle," Code39 Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODE39,"0123456789",strlen("0123456789") );
- PrintText(handle,"Code93 Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODE93,"0123456789",strlen("0123456789") );
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_CODE128,"0123456789",strlen("0123456789") );
- PrintText(handle,"QR Code Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_QRCODE,"SAM4STESTPRINT",strlen("SAM4STESTPRINT") );
- PrintText(handle,"PDF417 Barcode Test ");
- PrintNFeedNLines(handle,4);
- SAM4S_PrintBarcode(handle, BARCODE_TYPE_PDF417,"SAM4STESTPRINT",strlen("SAM4STESTPRINT") );
- PrintNFeedNLines(handle,4);
- SelectCharFontADoubleHeight(handle);
- PrintText(handle,"THE END ");
- LineFeed(handle);
- PrintNFeedNLines(handle,4);
- SAM4S_FeedAndCutPaper(handle);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement