예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter printer IP address: (e.g. 192.168.0.2) default port is 9100");
            var ip      = Console.ReadLine();
            var printer = new NetworkPrinter(string.IsNullOrEmpty(ip) ? "192.168.3.100" : ip, 9100, true);

            var e = new EPSON();

            printer.Write(ByteSplicer.Combine(
                              e.Initialize(),
                              e.PrintLine("Hello Xprinter!"),
                              e.CodePage(CodePage.CHINA),
                              e.PrintLine("中文菜单"),
                              e.FullCutAfterFeed(3)
                              ));

            Console.Read();
        }
예제 #2
0
        public async Task PrintText(string input, string printerName)
        {
            using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter)
            {
                if (bluetoothAdapter == null)
                {
                    throw new Exception("No default adapter");
                    //return;
                }

                if (!bluetoothAdapter.IsEnabled)
                {
                    throw new Exception("Bluetooth not enabled");
                }

                BluetoothDevice device = (from bd in bluetoothAdapter.BondedDevices
                                          where bd.Name == printerName
                                          select bd).FirstOrDefault();
                if (device == null)
                {
                    throw new Exception(printerName + " device not found.");
                }

                try
                {
                    using (BluetoothSocket _socket = device.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb")))
                    {
                        await _socket.ConnectAsync();


                        switch (input)
                        {
                        case "LF":
                            _socket.OutputStream.WriteByte(0x0A);
                            break;

                        default:
                            byte[] message = System.Text.Encoding.ASCII.GetBytes(input);
                            await _socket.OutputStream.WriteAsync(message, 0, message.Length);

                            _socket.OutputStream.WriteByte(0x0A);

                            //try ESCPOS_NET
                            var e      = new EPSON();
                            var buffer = ByteSplicer.Combine(
                                e.CenterAlign(),
                                e.PrintLine("Receipt"),
                                e.Print("From "), e.SetStyles(PrintStyle.Bold), e.Print($"bold"), e.SetStyles(PrintStyle.None),
                                e.SetBarcodeHeightInDots(48), e.PrintBarcode(BarcodeType.CODE39, "ABC"), e.PrintLine(""),
                                e.LeftAlign(), e.PrintLine("left"),
                                e.PrintLine("user: "******"username")
                                );
                            await _socket.OutputStream.WriteAsync(buffer, 0, buffer.Length);

                            break;
                        }

                        _socket.Close();
                    }
                }
                catch (Exception exp)
                {
                    throw exp;
                }
            }
        }
예제 #3
0
        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);
            }
        }