我试图将字符串数据发送到我的vkp80ii打印机,我使用原始二进制文件执行此操作并打印但是当我尝试使用字符串时它不会产生任何影响。 有什么帮助吗?
class VKP80II_Driver
{
static USBH_Printer printer;
static AutoResetEvent printerConnected = new AutoResetEvent(false);
public static void Main()
{
// Subscribe to USBH event.
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
// wait for printer to be connectoed.
printerConnected.WaitOne();
// Get file to print
//byte[] buffer = Resources.GetBytes(Resources.BinaryResources.beep);
byte[] buffer = StrToByteArray("$0AHello World");
// Printing can take a long time, give it a 5 seconds timeout here
printer.SendData(buffer, 0, buffer.Length, 5000);
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
// Is printer connected event
static void DeviceConnectedEvent(USBH_Device device)
{
if (device.TYPE == USBH_DeviceType.Printer)
{
printer = new USBH_Printer(device);
printerConnected.Set();
}
}
// Parse string object to byte array
static byte [] StrToByteArray(string str)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetBytes(str);
}
}
答案 0 :(得分:1)
回答问题
我必须将实际字节发送到打印机
示例:
byte[] newByte = new bytes [] {0x0A};
printer.SendData(newByte, 0, buffer.Length, 5000);
答案 1 :(得分:0)
当我需要这样的功能时,我找不到任何与此相关的库。 所以我决定做一个。
ESC-POS-USB-NET是使用USB设备驱动程序的爱普生ESC / POS打印的免费开放源.NET(C#)实现。
此库可通过开源@ MIT许可证获得。
您可以从Nuget Packages
安装请遵循以下步骤:
⏳安装 使用此快速入门命令安装Strapi可以立即创建项目:
(使用nuget软件包管理器进行安装(推荐))
Install-Package ESC-POS-USB-NET
或
(使用.Net Cli安装)
dotnet add package ESC-POS-USB-NET
此命令随项目一起安装ESC-POS-USB-NET。
享受?
❤️使用C#的示例 导入ESC_POS_USB_NET打印机类:
using ESC_POS_USB_NET.Printer;
您可以在(Windows)中找到打印机名称:控制面板->硬件和声音->设备和打印机->您的打印机名称
测试打印:
Printer printer = new Printer("Printer Name");
printer.TestPrinter();
printer.FullPaperCut();
printer.PrintDocument();
打印图像:
Printer printer = new Printer("Printer Name");
Bitmap image =new Bitmap ( Bitmap.FromFile("Icon.bmp"));
printer.Image(image);
printer.FullPaperCut();
printer.PrintDocument();
打印条形码:
Printer printer = new Printer("Printer Name");
printer.Append("Code 128");
printer.Code128("123456789");
printer.Separator();
printer.Append("Code39");
printer.Code39("123456789");
printer.Separator();
printer.Append("Ean13");
printer.Ean13("1234567891231");
printer.FullPaperCut();
printer.PrintDocument();
打开抽屉:
Printer printer = new Printer("Printer Name");
printer.OpenDrawer();
printer.PrintDocument();
版式测试:
Printer printer = new Printer("Printer Name");
printer.Append("NORMAL - 48 COLUMNS");
printer.Append("1...5...10...15...20...25...30...35...40...45.48");
printer.Separator();
printer.Append("Text Normal");
printer.BoldMode("Bold Text");
printer.UnderlineMode("Underlined text");
printer.Separator();
printer.ExpandedMode(PrinterModeState.On);
printer.Append("Expanded - 23 COLUMNS");
printer.Append("1...5...10...15...20..23");
printer.ExpandedMode(PrinterModeState.Off);
printer.Separator();
printer.CondensedMode(PrinterModeState.On);
printer.Append("Condensed - 64 COLUMNS");
printer.Append("1...5...10...15...20...25...30...35...40...45...50...55...60..64");
printer.CondensedMode(PrinterModeState.Off);
printer.Separator();
printer.DoubleWidth2();
printer.Append("Font Width 2");
printer.DoubleWidth3();
printer.Append("Font Width 3");
printer.NormalWidth();
printer.Append("Normal width");
printer.Separator();
printer.AlignRight();
printer.Append("Right aligned text");
printer.AlignCenter();
printer.Append("Center-aligned text");
printer.AlignLeft();
printer.Append("Left aligned text");
printer.Separator();
printer.Font("Font A", Fonts.FontA);
printer.Font("Font B", Fonts.FontB);
printer.Font("Font C", Fonts.FontC);
printer.Font("Font D", Fonts.FontD);
printer.Font("Font E", Fonts.FontE);
printer.Font("Font Special A", Fonts.SpecialFontA);
printer.Font("Font Special B", Fonts.SpecialFontB);
printer.Separator();
printer.InitializePrint();
printer.SetLineHeight(24);
printer.Append("This is first line with line height of 30 dots");
printer.SetLineHeight(40);
printer.Append("This is second line with line height of 24 dots");
printer.Append("This is third line with line height of 40 dots");
printer.NewLines(3);
printer.Append("End of Test :)");
printer.Separator();
printer.FullPaperCut();
printer.PrintDocument();
?功能: