static void TestThermalPrinter() { try { Console.ForegroundColor = ConsoleColor.White; WriteLineCenter("프린트 연결 테스트.."); var test = new SerialPrinter(portName: "COM1", baudRate: 9600); test.Dispose(); } catch (Exception e) { Console.BackgroundColor = ConsoleColor.Red; WriteLineCenter("프린트와 연결에 실패했습니다. 프로그램을 종료합니다."); Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine(e.ToString()); Environment.Exit(0); } }
/// <summary>Creates a new instance of a printer for the specified printer type.</summary> public static ILabelPrinter CreatePrinter(string printerType, string portName) { //Create a printer of type ILabelPrinter ILabelPrinter printer = null; switch (printerType.ToLower()) { case "console": printer = new ConsolePrinter(); break; case "serial": printer = new SerialPrinter(portName); break; case "zebra": case "110": printer = new Zebra(portName); break; case "zebraprp": printer = new Zebra(portName); break; case "zebrawin": printer = new ZebraWin(); break; default: throw new Exception("Printer type not found."); } return(printer); }
public void printOutSlip_Backup(responseSaveVn app) { try { SerialPrinter printer = new SerialPrinter(portName: "COM3", baudRate: 38400); EPSON e = new EPSON(); string fontName = "Tahoma"; Font fontRegular = new Font(fontName, 26, FontStyle.Regular, GraphicsUnit.Pixel); Font fontBoldUnderline = new Font(fontName, 26, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Pixel); Font fontBold = new Font(fontName, 26, FontStyle.Bold, GraphicsUnit.Pixel); Font fontJumbo = new Font(fontName, 48, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Pixel); byte[] ImgTitle = DrawText($"ใช้บริการโดยตู้ Kiosk {app.dateSave}", fontRegular); byte[] ImgEx = DrawText(app.ex, fontBoldUnderline); byte[] ImgVn = DrawText("HN : " + app.hn + "\nVN : " + app.vn, fontJumbo); byte[] ImgName = DrawText($"ชื่อ : {app.ptname}", fontRegular); byte[] ImgPtright = DrawText($"สิทธิ : {app.ptright}", fontBoldUnderline); string extraTxt = ""; if (!String.IsNullOrEmpty(app.hospCode)) { extraTxt += $"\n{app.hospCode}"; } if (!String.IsNullOrEmpty(app.doctor)) { extraTxt += $"\n{app.doctor}"; } byte[] ImgHn = DrawText($"อายุ {app.age}\nบัตร ปชช. : {app.idcard}\n{app.mx}{extraTxt}", fontRegular); printer.Write( ByteSplicer.Combine( e.CenterAlign(), e.PrintImage(File.ReadAllBytes("Images/LogoWithName2.png"), true, false, 500), e.PrintImage(ImgTitle, true), e.PrintImage(ImgEx, true), e.PrintImage(ImgVn, true), e.PrintImage(ImgName, true), e.PrintImage(ImgHn, true), e.PrintImage(ImgPtright, true), e.PrintLine(" "), e.SetBarcodeHeightInDots(350), e.SetBarWidth(BarWidth.Thin), e.PrintBarcode(BarcodeType.CODE128, app.hn), e.PrintLine(" "), e.FeedLines(6), e.FullCut() ) ); if (app.queueStatus == "y") { byte[] ImgTitleQueue = DrawText("ใช้บริการโดยตู้ Kiosk\nตรวจโรคทั่วไป\n", fontRegular); byte[] ImgHnVn = DrawText($"HN : {app.hn} VN : {app.vn} \n ชื่อ : {app.ptname}", fontBold); byte[] ImgDetail = DrawText($"ประเภท : {app.ptType}", fontRegular); byte[] ImgQueue = DrawText(app.queueNumber, fontJumbo); byte[] ImgQueueWait = DrawText($"จำนวนคิวที่รอ {app.queueWait} คิว", fontRegular); printer.Write( ByteSplicer.Combine( e.CenterAlign(), e.PrintImage(File.ReadAllBytes("Images/LogoWithNameOPD.png"), true, false, 500), e.PrintImage(ImgTitleQueue, true), e.PrintImage(ImgHnVn, true), e.PrintImage(ImgDetail, true), e.PrintImage(ImgQueue, true), e.PrintImage(ImgQueueWait, true), e.FeedLines(6), e.FullCut() ) ); printer.Dispose(); // close } } catch (Exception ex) { Console.WriteLine(ex.Message); } }