终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ArgoxHelper.cs 4.1 KiB

vor 2 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Diagnostics;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. namespace BPASmartClient.Argox
  5. {
  6. public class ArgoxHelper
  7. {
  8. private volatile static ArgoxHelper _Instance;
  9. public static ArgoxHelper GetInstance => _Instance ?? (_Instance = new ArgoxHelper());
  10. private ArgoxHelper() { }
  11. public void Print()
  12. {
  13. int nLen, ret, sw;
  14. byte[] pbuf = new byte[128];
  15. string strmsg;
  16. IntPtr ver;
  17. System.Text.Encoding encAscII = System.Text.Encoding.ASCII;
  18. System.Text.Encoding encUnicode = System.Text.Encoding.Unicode;
  19. // dll 版本.
  20. ver = DLLHelper.B_Get_DLL_Version(0);
  21. // 搜索端口号.
  22. nLen = DLLHelper.B_GetUSBBufferLen() + 1;
  23. strmsg = "DLL ";
  24. strmsg += Marshal.PtrToStringAnsi(ver);
  25. strmsg += "\r\n";
  26. if (nLen > 1)
  27. {
  28. byte[] buf1, buf2;
  29. int len1 = 128, len2 = 128;
  30. buf1 = new byte[len1];
  31. buf2 = new byte[len2];
  32. DLLHelper.B_EnumUSB(pbuf);
  33. DLLHelper.B_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
  34. sw = 1;
  35. if (1 == sw)
  36. {
  37. ret = DLLHelper.B_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// 打开 USB.
  38. }
  39. else
  40. {
  41. ret = DLLHelper.B_CreateUSBPort(1);// must call B_GetUSBBufferLen() function fisrt.
  42. }
  43. if (0 != ret)
  44. {
  45. strmsg += "Open USB fail!";
  46. }
  47. else
  48. {
  49. strmsg += "Open USB:\r\nDevice name: ";
  50. strmsg += encAscII.GetString(buf1, 0, len1);
  51. strmsg += "\r\nDevice path: ";
  52. strmsg += encAscII.GetString(buf2, 0, len2);
  53. //sw = 2;
  54. if (2 == sw)
  55. {
  56. //Immediate Error Report.
  57. DLLHelper.B_WriteData(1, encAscII.GetBytes("^ee\r\n"), 5);//^ee
  58. ret = DLLHelper.B_ReadData(pbuf, 4, 1000);
  59. }
  60. }
  61. }
  62. else
  63. {
  64. System.IO.Directory.CreateDirectory(DLLHelper.szSavePath);
  65. ret = DLLHelper.B_CreatePrn(0, DLLHelper.szSaveFile);// open file.
  66. strmsg += "Open ";
  67. strmsg += DLLHelper.szSaveFile;
  68. if (0 != ret)
  69. {
  70. strmsg += " file fail!";
  71. }
  72. else
  73. {
  74. strmsg += " file succeed!";
  75. }
  76. }
  77. Debug.WriteLine(strmsg);
  78. if (0 != ret)
  79. return;
  80. // 样品设置.
  81. DLLHelper.B_Set_DebugDialog(0);
  82. DLLHelper.B_Set_Originpoint(0, 0);
  83. DLLHelper.B_Select_Option(2);
  84. DLLHelper.B_Set_Darkness(8);
  85. DLLHelper.B_Del_Pcx("*");// delete all picture.
  86. DLLHelper.B_WriteData(0, encAscII.GetBytes(DLLHelper.sznop2), DLLHelper.sznop2.Length);
  87. DLLHelper.B_WriteData(1, encAscII.GetBytes(DLLHelper.sznop1), DLLHelper.sznop1.Length);
  88. DLLHelper.B_Set_LabelForSmartPrint(254 * 3, 30);//label information: length= 3 * 25.4 mm, gap= 3 mm.
  89. int TextX = 160;
  90. int BoxX = 150;
  91. DLLHelper.B_Draw_Box(BoxX, 20, 4, 670, 370);//画框
  92. DLLHelper.B_Prn_Text_TrueType(TextX, 40, 30, "楷体", 1, 400, 0, 0, 0, "AA", $"原料名称:榨菜配方");
  93. DLLHelper.B_Prn_Text_TrueType_W(TextX, 80, 30, 20, "楷体", 1, 400, 0, 0, 0, "AB", $"日期:{DateTime.Now.ToString("yyy-MM-dd")}");
  94. DLLHelper.B_Prn_Text_TrueType_Uni(TextX, 120, 30, "楷体", 1, 400, 0, 0, 0, "AC", Encoding.Unicode.GetBytes($"时间:{DateTime.Now.ToString("HH:mm:ss")}"), 1);//UTF-16
  95. DLLHelper.B_Print_Out(1);//打印数量
  96. DLLHelper.B_ClosePrn();
  97. }
  98. }
  99. }