|
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Text;
-
- namespace BPASmartClient.Argox
- {
- public class ArgoxHelper
- {
-
- private volatile static ArgoxHelper _Instance;
- public static ArgoxHelper GetInstance => _Instance ?? (_Instance = new ArgoxHelper());
- private ArgoxHelper() { }
-
- public void Print()
- {
- int nLen, ret, sw;
- byte[] pbuf = new byte[128];
- string strmsg;
- IntPtr ver;
- System.Text.Encoding encAscII = System.Text.Encoding.ASCII;
- System.Text.Encoding encUnicode = System.Text.Encoding.Unicode;
-
- // dll 版本.
- ver = DLLHelper.B_Get_DLL_Version(0);
-
- // 搜索端口号.
- nLen = DLLHelper.B_GetUSBBufferLen() + 1;
- strmsg = "DLL ";
- strmsg += Marshal.PtrToStringAnsi(ver);
- strmsg += "\r\n";
- if (nLen > 1)
- {
- byte[] buf1, buf2;
- int len1 = 128, len2 = 128;
- buf1 = new byte[len1];
- buf2 = new byte[len2];
- DLLHelper.B_EnumUSB(pbuf);
- DLLHelper.B_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
- sw = 1;
- if (1 == sw)
- {
- ret = DLLHelper.B_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// 打开 USB.
- }
- else
- {
- ret = DLLHelper.B_CreateUSBPort(1);// must call B_GetUSBBufferLen() function fisrt.
- }
- if (0 != ret)
- {
- strmsg += "Open USB fail!";
- }
- else
- {
- strmsg += "Open USB:\r\nDevice name: ";
- strmsg += encAscII.GetString(buf1, 0, len1);
- strmsg += "\r\nDevice path: ";
- strmsg += encAscII.GetString(buf2, 0, len2);
- //sw = 2;
- if (2 == sw)
- {
- //Immediate Error Report.
- DLLHelper.B_WriteData(1, encAscII.GetBytes("^ee\r\n"), 5);//^ee
- ret = DLLHelper.B_ReadData(pbuf, 4, 1000);
- }
- }
- }
- else
- {
- System.IO.Directory.CreateDirectory(DLLHelper.szSavePath);
- ret = DLLHelper.B_CreatePrn(0, DLLHelper.szSaveFile);// open file.
- strmsg += "Open ";
- strmsg += DLLHelper.szSaveFile;
- if (0 != ret)
- {
- strmsg += " file fail!";
- }
- else
- {
- strmsg += " file succeed!";
- }
- }
- Debug.WriteLine(strmsg);
- if (0 != ret)
- return;
-
- // 样品设置.
- DLLHelper.B_Set_DebugDialog(0);
- DLLHelper.B_Set_Originpoint(0, 0);
- DLLHelper.B_Select_Option(2);
- DLLHelper.B_Set_Darkness(8);
- DLLHelper.B_Del_Pcx("*");// delete all picture.
- DLLHelper.B_WriteData(0, encAscII.GetBytes(DLLHelper.sznop2), DLLHelper.sznop2.Length);
- DLLHelper.B_WriteData(1, encAscII.GetBytes(DLLHelper.sznop1), DLLHelper.sznop1.Length);
- DLLHelper.B_Set_LabelForSmartPrint(254 * 3, 30);//label information: length= 3 * 25.4 mm, gap= 3 mm.
-
- int TextX = 160;
- int BoxX = 150;
- DLLHelper.B_Draw_Box(BoxX, 20, 4, 670, 370);//画框
- DLLHelper.B_Prn_Text_TrueType(TextX, 40, 30, "楷体", 1, 400, 0, 0, 0, "AA", $"原料名称:榨菜配方");
- DLLHelper.B_Prn_Text_TrueType_W(TextX, 80, 30, 20, "楷体", 1, 400, 0, 0, 0, "AB", $"日期:{DateTime.Now.ToString("yyy-MM-dd")}");
- 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
- DLLHelper.B_Print_Out(1);//打印数量
- DLLHelper.B_ClosePrn();
- }
- }
- }
|