添加项目文件。
This commit is contained in:
17
Print.Application/ForumApplicationAutoMapperProfile.cs
Normal file
17
Print.Application/ForumApplicationAutoMapperProfile.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Print.Application
|
||||
{
|
||||
public class ForumApplicationAutoMapperProfile : Profile
|
||||
{
|
||||
public ForumApplicationAutoMapperProfile()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
34
Print.Application/ForumApplicationModule.cs
Normal file
34
Print.Application/ForumApplicationModule.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Print.Forum.Application.Contracts;
|
||||
using Volo.Abp.AutoMapper;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace Print.Application;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 项目模块依赖、组件依赖
|
||||
/// </summary>
|
||||
[DependsOn(
|
||||
typeof(AbpAutoMapperModule),
|
||||
typeof(ForumApplicationContractsModule)
|
||||
)]
|
||||
public class ForumApplicationModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var services = context.Services;
|
||||
// 添加ObjectMapper注入
|
||||
services.AddAutoMapperObjectMapper<ForumApplicationModule>();
|
||||
|
||||
// Abp AutoMapper设置
|
||||
Configure<AbpAutoMapperOptions>(config =>
|
||||
{
|
||||
// 添加对应依赖关系Profile
|
||||
config.AddMaps<ForumApplicationAutoMapperProfile>();
|
||||
});
|
||||
}
|
||||
}
|
29
Print.Application/Print.Application.csproj
Normal file
29
Print.Application/Print.Application.csproj
Normal file
@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.10" />
|
||||
<PackageReference Include="Volo.Abp.AutoMapper" Version="8.1.1" />
|
||||
<PackageReference Include="Volo.Abp.Ddd.Application" Version="8.1.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Print\x64lib\libezio.so.1.1.0" />
|
||||
<None Remove="Print\x64lib\libttf_x64.so" />
|
||||
<None Remove="Print\x64lib\libusb-1.0.so.0.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Print.Forum.Application.Contracts\Print.Forum.Application.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Print\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
302
Print.Application/Print/EzioInterop.cs
Normal file
302
Print.Application/Print/EzioInterop.cs
Normal file
@ -0,0 +1,302 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
public class EzioInterop
|
||||
{
|
||||
const string EzioLibrary = "ezio.so.1.1.0";
|
||||
const string Usblib = "usb-1.0.so.0";
|
||||
|
||||
/// <summary>
|
||||
/// Open 函数
|
||||
/// </summary>
|
||||
/// <param name="hostname"></param>
|
||||
/// <param name="port"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern bool Open(string hostname, int port);
|
||||
|
||||
/// <summary>
|
||||
/// Close 函数
|
||||
/// </summary>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Close();
|
||||
|
||||
// openUSB 函数
|
||||
[DllImport(Usblib, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int openUSB();
|
||||
|
||||
/// <summary>
|
||||
/// closeUSB 函数
|
||||
/// </summary>
|
||||
[DllImport(Usblib, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void closeUSB();
|
||||
|
||||
/// <summary>
|
||||
/// OpenDriver 函数
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int OpenDriver(string port);
|
||||
|
||||
/// <summary>
|
||||
/// closeport 函数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int closeport();
|
||||
|
||||
/// <summary>
|
||||
/// RcvBuf 函数
|
||||
/// </summary>
|
||||
/// <param name="buf"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int RcvBuf(IntPtr buf, UIntPtr count);
|
||||
|
||||
/// <summary>
|
||||
/// sendbuf 函数
|
||||
/// </summary>
|
||||
/// <param name="buf"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int sendbuf([MarshalAs(UnmanagedType.LPArray)] byte[] buf, int count);
|
||||
|
||||
/// <summary>
|
||||
/// sendcommand 函数
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int sendcommand(string cmd);
|
||||
|
||||
/// <summary>
|
||||
/// setup 函数
|
||||
/// </summary>
|
||||
/// <param name="mm"></param>
|
||||
/// <param name="dark"></param>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="mode"></param>
|
||||
/// <param name="gap"></param>
|
||||
/// <param name="top"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int setup(int mm, int dark, int speed, int mode, int gap, int top);
|
||||
|
||||
/// <summary>
|
||||
/// Bar 函数
|
||||
/// </summary>
|
||||
/// <param name="BarcodeType"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Narrow"></param>
|
||||
/// <param name="Wide"></param>
|
||||
/// <param name="Height"></param>
|
||||
/// <param name="Rotation"></param>
|
||||
/// <param name="Readable"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Bar(string BarcodeType, int PosX, int PosY, int Narrow, int Wide, int Height, int Rotation, int Readable, string data);
|
||||
|
||||
/// <summary>
|
||||
/// Bar_S 函数
|
||||
/// </summary>
|
||||
/// <param name="BarcodeType"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Bar_S(string BarcodeType, int PosX, int PosY, string data);
|
||||
|
||||
/// <summary>
|
||||
/// Bar_QRcode 函数
|
||||
/// </summary>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Mode"></param>
|
||||
/// <param name="Type"></param>
|
||||
/// <param name="ErrorLevel"></param>
|
||||
/// <param name="Mask"></param>
|
||||
/// <param name="Mul"></param>
|
||||
/// <param name="Len"></param>
|
||||
/// <param name="Rotation"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Bar_QRcode(int PosX, int PosY, int Mode, int Type, string ErrorLevel, int Mask, int Mul, int Len, int Rotation, string data);
|
||||
|
||||
/// <summary>
|
||||
/// Bar_QRcode_S 函数
|
||||
/// </summary>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Len"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Bar_QRcode_S(int PosX, int PosY, int Len, string data);
|
||||
|
||||
/// <summary>
|
||||
/// DrawHorLine 函数
|
||||
/// </summary>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Length"></param>
|
||||
/// <param name="Thick"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int DrawHorLine(int PosX, int PosY, int Length, int Thick);
|
||||
|
||||
/// <summary>
|
||||
/// DrawVerLine 函数
|
||||
/// </summary>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Length"></param>
|
||||
/// <param name="Thick"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int DrawVerLine(int PosX, int PosY, int Length, int Thick);
|
||||
|
||||
/// <summary>
|
||||
/// InternalFont_TextOut 函数
|
||||
/// </summary>
|
||||
/// <param name="FontType"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Mul_X"></param>
|
||||
/// <param name="Mul_Y"></param>
|
||||
/// <param name="Gap"></param>
|
||||
/// <param name="RotationInverse"></param>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int InternalFont_TextOut(string FontType, int PosX, int PosY, int Mul_X, int Mul_Y, int Gap, string RotationInverse, string Data);
|
||||
|
||||
/// <summary>
|
||||
/// InternalFont_TextOut_S 函数
|
||||
/// </summary>
|
||||
/// <param name="FontType"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int InternalFont_TextOut_S(string FontType, int PosX, int PosY, string Data);
|
||||
|
||||
/// <summary>
|
||||
/// DownloadFont_TextOut 函数
|
||||
/// </summary>
|
||||
/// <param name="FontName"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Mul_X"></param>
|
||||
/// <param name="Mul_Y"></param>
|
||||
/// <param name="Gap"></param>
|
||||
/// <param name="RotationInverse"></param>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int DownloadFont_TextOut(string FontName, int PosX, int PosY, int Mul_X, int Mul_Y, int Gap, string RotationInverse, string Data);
|
||||
|
||||
/// <summary>
|
||||
/// DownloadFont_TextOut_S 函数
|
||||
/// </summary>
|
||||
/// <param name="FontName"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int DownloadFont_TextOut_S(string FontName, int PosX, int PosY, string Data);
|
||||
|
||||
/// <summary>
|
||||
/// TrueTypeFont_TextOut 函数
|
||||
/// </summary>
|
||||
/// <param name="FontName"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Font_W"></param>
|
||||
/// <param name="Font_H"></param>
|
||||
/// <param name="SpaceChar"></param>
|
||||
/// <param name="RotationInverse"></param>
|
||||
/// <param name="TTFTable"></param>
|
||||
/// <param name="WidthMode"></param>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TrueTypeFont_TextOut(string FontName, int PosX, int PosY, int Font_W, int Font_H, int SpaceChar, string RotationInverse, string TTFTable, int WidthMode, string Data);
|
||||
|
||||
/// <summary>
|
||||
/// TrueTypeFont_TextOut_S 函数
|
||||
/// </summary>
|
||||
/// <param name="FontName"></param>
|
||||
/// <param name="PosX"></param>
|
||||
/// <param name="PosY"></param>
|
||||
/// <param name="Data"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TrueTypeFont_TextOut_S(string FontName, int PosX, int PosY, string Data);
|
||||
|
||||
/// <summary>
|
||||
/// ecTextOut 函数
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="fontname"></param>
|
||||
/// <param name="TEXT"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ecTextOut(int x, int y, int height, string fontname, string TEXT);
|
||||
|
||||
/// <summary>
|
||||
/// ecTextOutR 函数
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="fontname"></param>
|
||||
/// <param name="TEXT"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="degree"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ecTextOutR(int x, int y, int height, string fontname, string TEXT, int width, int degree);
|
||||
|
||||
/// <summary>
|
||||
/// ecTextOutW 函数
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="fontname"></param>
|
||||
/// <param name="TEXT"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ecTextOutW(int x, int y, int height, string fontname, [MarshalAs(UnmanagedType.LPWStr)] string TEXT);
|
||||
|
||||
/// <summary>
|
||||
/// ecTextOutRW 函数
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="fontname"></param>
|
||||
/// <param name="TEXT"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="degree"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ecTextOutRW(int x, int y, int height, string fontname, [MarshalAs(UnmanagedType.LPWStr)] string TEXT, int width, int degree);
|
||||
|
||||
[DllImport(EzioLibrary, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int putimage(int x, int y, [MarshalAs(UnmanagedType.LPStr)] string Filename, int Degree);
|
||||
}
|
||||
}
|
24
Print.Application/Print/GoDEXCommunication.cs
Normal file
24
Print.Application/Print/GoDEXCommunication.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印机配置
|
||||
/// </summary>
|
||||
public class GoDEXCommunication
|
||||
{
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public string Host { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
}
|
||||
}
|
34
Print.Application/Print/GoDEXEnum.cs
Normal file
34
Print.Application/Print/GoDEXEnum.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印机状态
|
||||
/// </summary>
|
||||
public enum GoDEXEnum
|
||||
{
|
||||
待機狀態 = 00,
|
||||
耗材用盡 = 01,
|
||||
卡紙 = 02,
|
||||
碳帶用盡 = 03,
|
||||
印表頭開啟 = 04,
|
||||
背紙回收器已滿 = 05,
|
||||
檔案系統已滿 = 06,
|
||||
找不到檔案 = 07,
|
||||
檔名重複 = 08,
|
||||
指令語法錯誤 = 09,
|
||||
裁刀卡住或未安裝裁刀 = 10,
|
||||
無延伸記憶體 = 11,
|
||||
等待取走標籤 = 13,
|
||||
暫停 = 20,
|
||||
設定模式 = 21,
|
||||
鍵盤模式 = 22,
|
||||
印表機列印中 = 50,
|
||||
資料處理中 = 60,
|
||||
印表頭過熱 = 62,
|
||||
}
|
||||
}
|
131
Print.Application/Print/GoDEXPrint.cs
Normal file
131
Print.Application/Print/GoDEXPrint.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
public class GoDEXPrint : IDisposable
|
||||
{
|
||||
private static object printLock = new object();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 连接打印机
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Open(GoDEXCommunication goDEXCommunication)
|
||||
{
|
||||
return EzioInterop.Open(goDEXCommunication.Host, goDEXCommunication.Port);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭打印机
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Close()
|
||||
{
|
||||
return EzioInterop.closeport() == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打印
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Print(IGoDEXPrintData goDEXPrintData)
|
||||
{
|
||||
bool printSuccess = false;
|
||||
//_logger.LogInformation("3.进入打印机方法,锁外");
|
||||
try
|
||||
{
|
||||
// 打印任务执行,可能是阻塞的,因此考虑异步执行
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
//GoDEX库因无法识别打印机,当前只适应用单任务打印
|
||||
//lock (printLock)
|
||||
//{
|
||||
|
||||
if (Open(goDEXPrintData.Communication))
|
||||
{
|
||||
LabelSetup(goDEXPrintData);
|
||||
|
||||
//^L(標籤起始符號設定,^L 正常列印,^LI 反白列印,^LM 鏡像列印,^LRn 整張旋轉 n=0, 0°列印 ; n=1, 90°列印 ; n=2, 180°列印 ; n=3, 270°列印)
|
||||
EzioInterop.sendcommand($"^L");
|
||||
// 尝试执行打印操作,成功返回
|
||||
if (goDEXPrintData.Print())
|
||||
{
|
||||
printSuccess = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("打印失败!");
|
||||
}
|
||||
//结束,打印机收到后开始打印
|
||||
EzioInterop.sendcommand("E");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("6.打印机连接失败");
|
||||
throw new Exception("打印机连接失败!");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常日志
|
||||
//_logger.LogInformation($"5.打印操作异常:{ex.Message}");
|
||||
Console.WriteLine($"打印操作异常:{ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Close();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
// 捕获整个过程中的异常
|
||||
//_logger.LogInformation($"打印失败,异常:{ex.Message}");
|
||||
Console.WriteLine($"打印失败:{ex.Message}");
|
||||
}
|
||||
return printSuccess;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设定参数
|
||||
/// </summary>
|
||||
/// <param name="goDEXPrintData"></param>
|
||||
private void LabelSetup(IGoDEXPrintData goDEXPrintData)
|
||||
{
|
||||
//標籤長度設定 x长,y不指定,z每张间隔)
|
||||
EzioInterop.sendcommand($"^Q{goDEXPrintData.LabelSetup.Height},0,{goDEXPrintData.LabelSetup.Speed}");
|
||||
|
||||
//^W54(標籤寬度設定)
|
||||
EzioInterop.sendcommand($"^W{goDEXPrintData.LabelSetup.Width}");
|
||||
|
||||
//^H10(列印黑度設定x = 00 ~ 19)
|
||||
EzioInterop.sendcommand($"^H{goDEXPrintData.LabelSetup.Dark}");
|
||||
|
||||
//^S3(列印速度設定x = 2 ~ 10)
|
||||
EzioInterop.sendcommand($"^H{goDEXPrintData.LabelSetup.Speed}");
|
||||
|
||||
//^P1(連續列印)
|
||||
EzioInterop.sendcommand($"^P1");
|
||||
|
||||
//^C1(複製張數x = 1 ~ 32767)
|
||||
EzioInterop.sendcommand($"^C1");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭打印机
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
36
Print.Application/Print/GoDEXPrintBase64Image.cs
Normal file
36
Print.Application/Print/GoDEXPrintBase64Image.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 按base64打印图片
|
||||
/// </summary>
|
||||
public class GoDEXPrintBase64Image : GoDEXPrintImage
|
||||
{
|
||||
/// <summary>
|
||||
/// Base64数据
|
||||
/// </summary>
|
||||
public string ImageBase64 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取图片数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override byte[] GetImageData()
|
||||
{
|
||||
var base64Content = ImageBase64;
|
||||
// 检查是否包含 Base64 前缀
|
||||
if (base64Content.Contains("base64,"))
|
||||
{
|
||||
// 去除 "data:image/<format>;base64," 头部信息
|
||||
base64Content = base64Content.Substring(base64Content.IndexOf(",") + 1);
|
||||
}
|
||||
|
||||
return Convert.FromBase64String(base64Content);
|
||||
}
|
||||
}
|
||||
}
|
26
Print.Application/Print/GoDEXPrintData.cs
Normal file
26
Print.Application/Print/GoDEXPrintData.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印数据基础数据结构
|
||||
/// </summary>
|
||||
public abstract class GoDEXPrintData : IGoDEXPrintData
|
||||
{
|
||||
public GoDEXCommunication Communication { get; set; }
|
||||
|
||||
public GoDEXPrintSetup LabelSetup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 1毫米的点数
|
||||
/// </summary>
|
||||
public readonly int Dots = 8;
|
||||
|
||||
public abstract bool Print();
|
||||
|
||||
}
|
||||
}
|
170
Print.Application/Print/GoDEXPrintImage.cs
Normal file
170
Print.Application/Print/GoDEXPrintImage.cs
Normal file
@ -0,0 +1,170 @@
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印图片
|
||||
/// </summary>
|
||||
public abstract class GoDEXPrintImage : GoDEXPrintData
|
||||
{
|
||||
/// <summary>
|
||||
/// X起始位置,单位mm
|
||||
/// </summary>
|
||||
public int PosX { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Y起始位置,单位mm
|
||||
/// </summary>
|
||||
public int PosY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片宽,单位mm
|
||||
/// </summary>
|
||||
public int Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片高,单位mm
|
||||
/// </summary>
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 打印图像
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool Print()
|
||||
{
|
||||
var imageData = ProcessImageData();
|
||||
|
||||
//Q10,10,102,484(圖案命令x,y,width,heigh)
|
||||
//x = 自左上角量起之水平位置(單位:dots).
|
||||
//y = 自左上角量起之垂直位置(單位:dots).
|
||||
//width = 圖檔寬度(單位:byte)
|
||||
//height = 圖檔高度(單位:dots)
|
||||
EzioInterop.sendcommand($"Q{PosX * Dots},{PosY * Dots},{imageData.Width},{imageData.Height}");
|
||||
//EzioInterop.sendcommand($"Q40,10,3,8");
|
||||
|
||||
//发送图片数据
|
||||
//EzioInterop.sendcommand(imageData);
|
||||
EzioInterop.sendbuf(imageData.Data, imageData.Data.Length);
|
||||
//EzioInterop.sendbuf(new byte[] { 0b01000001, 0b01000001, 0b01000001,
|
||||
//0b01000001,0b01000001,0b01000001,
|
||||
//0b01000001,0b01000001,0b01000001,
|
||||
//0b01000001,0b01000001,0b01000001,
|
||||
//0b01000001,0b01000001,0b01000001,
|
||||
//0b01000001,0b01000001,0b01000001,
|
||||
//0b01000001,0b01000001,0b01000001,
|
||||
//0b01000001,0b01000001,0b01000001,}, 24);
|
||||
|
||||
EzioInterop.sendcommand("\n");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理图片数据
|
||||
/// </summary>
|
||||
/// <param name="base64"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual (int Width, int Height, byte[] Data) ProcessImageData()
|
||||
{
|
||||
var imageBytes = GetImageData();
|
||||
|
||||
// 加载图像
|
||||
using (var image = Image.Load(imageBytes))
|
||||
{
|
||||
// 获取原始图像尺寸
|
||||
int originalWidth = image.Width;
|
||||
int originalHeight = image.Height;
|
||||
|
||||
image.Mutate(ctx =>
|
||||
{
|
||||
// 转换为灰度图像
|
||||
// 进行二值化,128是阈值,低于该值为黑色,高于为白色
|
||||
//image.Mutate(x => x.Grayscale().BinaryThreshold(128f / 255f));
|
||||
ctx.Grayscale();
|
||||
|
||||
//调整图像大小
|
||||
if (Width != 0 || Height != 0)
|
||||
ctx.Resize(originalWidth * 2, originalHeight * 2, KnownResamplers.Bicubic);
|
||||
|
||||
////适当锐化
|
||||
//ctx.GaussianSharpen(3f);
|
||||
|
||||
////调整对比度
|
||||
//ctx.Contrast(1.2f);
|
||||
|
||||
});
|
||||
|
||||
return ConvertImageToBytes(image);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取图片数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract byte[] GetImageData();
|
||||
|
||||
/// <summary>
|
||||
/// 获取图像数据
|
||||
/// </summary>
|
||||
/// <param name="imageBytes"></param>
|
||||
/// <returns></returns>
|
||||
protected (int Width, int Height, byte[] Data) ConvertImageToBytes(Image image)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
var clonedImage = image.CloneAs<Rgba32>();
|
||||
|
||||
|
||||
// 创建一个列表来存储字节数据
|
||||
List<byte> byteList = new List<byte>();
|
||||
|
||||
// 遍历每一行
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
{
|
||||
byte currentByte = 0;
|
||||
int bitCount = 0;
|
||||
|
||||
for (int x = 0; x < image.Width; x++)
|
||||
{
|
||||
// 获取当前像素的颜色
|
||||
var pixel = clonedImage[x, y];
|
||||
|
||||
// 黑色为1,白色为0(颠倒值)
|
||||
//将灰度转为黑白,选择适当灰度值转为黑色
|
||||
byte pixelValue = pixel.R <= 180 ? (byte)1 : (byte)0;
|
||||
|
||||
// 将像素值存入当前字节
|
||||
currentByte |= (byte)(pixelValue << (7 - bitCount));
|
||||
bitCount++;
|
||||
|
||||
// 如果一个字节已满,保存该字节并清空
|
||||
if (bitCount == 8)
|
||||
{
|
||||
sb.Append((char)currentByte);
|
||||
|
||||
byteList.Add(currentByte);
|
||||
currentByte = 0;
|
||||
bitCount = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 如果行末不足8个像素,则补充零
|
||||
if (bitCount > 0)
|
||||
{
|
||||
sb.Append((char)currentByte);
|
||||
byteList.Add(currentByte);
|
||||
}
|
||||
}
|
||||
|
||||
return (image.Width % 8 == 0 ? image.Width / 8 : image.Width / 8 + 1, image.Height, byteList.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
29
Print.Application/Print/GoDEXPrintImageFile.cs
Normal file
29
Print.Application/Print/GoDEXPrintImageFile.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 按图片打印
|
||||
/// </summary>
|
||||
public class GoDEXPrintImageFile : GoDEXPrintImage
|
||||
{
|
||||
/// <summary>
|
||||
/// 图片地址
|
||||
/// </summary>
|
||||
public string FilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取图片数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override byte[] GetImageData()
|
||||
{
|
||||
return File.ReadAllBytes(FilePath);
|
||||
}
|
||||
}
|
||||
}
|
34
Print.Application/Print/GoDEXPrintSetup.cs
Normal file
34
Print.Application/Print/GoDEXPrintSetup.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印页面配置
|
||||
/// </summary>
|
||||
public class GoDEXPrintSetup
|
||||
{
|
||||
/// <summary>
|
||||
/// 高
|
||||
/// </summary>
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 宽
|
||||
/// </summary>
|
||||
public int Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 间隔
|
||||
/// </summary>
|
||||
public int Speed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 黑度
|
||||
/// </summary>
|
||||
public int Dark { get; set; }
|
||||
}
|
||||
}
|
20
Print.Application/Print/IGoDEXPrintData.cs
Normal file
20
Print.Application/Print/IGoDEXPrintData.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印数据接口
|
||||
/// </summary>
|
||||
public interface IGoDEXPrintData
|
||||
{
|
||||
GoDEXCommunication Communication { get; set; }
|
||||
|
||||
GoDEXPrintSetup LabelSetup { get; set; }
|
||||
|
||||
abstract bool Print();
|
||||
}
|
||||
}
|
54
Print.Application/Print/PrintExtension.cs
Normal file
54
Print.Application/Print/PrintExtension.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace JingGong.Abp.Print.GoDEX
|
||||
{
|
||||
public static class PrintExtension
|
||||
{
|
||||
public static void AddGoDEX(this IApplicationBuilder applicationBuilder)
|
||||
{
|
||||
//注:docker运行时需添加环境变量:#ENV LD_LIBRARY_PATH=/app/libx64:$LD_LIBRARY_PATH
|
||||
ExtractResourceToFile("JingGong.Abp.Print.GoDEX.x64lib.libezio.so.1.1.0", "libx64/libezio.so.1.1.0");
|
||||
ExtractResourceToFile("JingGong.Abp.Print.GoDEX.x64lib.libttf_x64.so", "libx64/libttf_x64.so");
|
||||
ExtractResourceToFile("JingGong.Abp.Print.GoDEX.x64lib.libusb-1.0.so.0.3.0", "libx64/libusb-1.0.so.0");
|
||||
|
||||
//临时解决环境变量未生效问题
|
||||
ExtractResourceToFile("JingGong.Abp.Print.GoDEX.x64lib.libezio.so.1.1.0", "libezio.so.1.1.0");
|
||||
ExtractResourceToFile("JingGong.Abp.Print.GoDEX.x64lib.libttf_x64.so", "libttf_x64.so");
|
||||
ExtractResourceToFile("JingGong.Abp.Print.GoDEX.x64lib.libusb-1.0.so.0.3.0", "libusb-1.0.so.0");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源文件至本地文件
|
||||
/// </summary>
|
||||
/// <param name="resourceName"></param>
|
||||
/// <param name="fileFullName"></param>
|
||||
internal static void ExtractResourceToFile(string resourceName, string fileFullName)
|
||||
{
|
||||
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||
{
|
||||
if (stream == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(fileFullName);
|
||||
|
||||
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
using (FileStream fileStream = new FileStream(fileFullName, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"写入{fileFullName}失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
Print.Application/Print/x64lib/libezio.so.1.1.0
Normal file
BIN
Print.Application/Print/x64lib/libezio.so.1.1.0
Normal file
Binary file not shown.
BIN
Print.Application/Print/x64lib/libttf_x64.so
Normal file
BIN
Print.Application/Print/x64lib/libttf_x64.so
Normal file
Binary file not shown.
BIN
Print.Application/Print/x64lib/libusb-1.0.so.0.3.0
Normal file
BIN
Print.Application/Print/x64lib/libusb-1.0.so.0.3.0
Normal file
Binary file not shown.
Reference in New Issue
Block a user