c# 打印标签的可以调用第三方控件labelmanager2.dll来进行打印.具体可以调用串口的方式来处理。以前有一段是使用内部网络来打印的,方式如下:
亦可参考:https://blog.youkuaiyun.com/bodaowang/article/details/6645965
public async Task<Results> ContMesPrintServeStatue ()
{
Results rs;
try
{
string port = AppData.Read("Port");
string host = AppData.Read("Address");//ip地址
using (var ws = new WebSocket($"ws://{host}:{port}"))
{
ws.Connect();
if (ws.ReadyState != WebSocketState.Open)
{
return new Results() { Success = false, Message = "连接打印服务器失败!" };
}
}
}
catch (Exception ex)
{
return new Results() { Success = false, Message = "连接打印服务器异常!" };
}
return new Results() { Success = ok, Message = "连接打印服务器成功!" };
}
public void printserver(string labFile, IApplication labApp, Document doc,string boxcode,string printname)
{
labApp = new LabelManager2.Application();
labApp.Documents.Open(labFile, false);
System.DateTime nowdateshow = System.DateTime.Now;
string filePath = "C:\\img\\" + nowdateshow .Year + nowdateshow .Month + nowdateshow .Day + nowdateshow .Hour + nowdateshow .Minute + nowdateshow .Second + ".bmp";//保存图片的路径 为后面预览图片做准备
doc = labApp.ActiveDocument;
doc.Printer.SwitchTo(printname, "USB001", true);//选择打印机
doc.Variables.FreeVariables.Item("Serial").Value = boxcode;//向Label档传入变量
doc.Variables.FreeVariables.Item("PalletBarCode").Value = boxcode;//向Label档传入变量
doc.Variables.FreeVariables.Item("CreationTime").Value = boxcode;//向Label档传入变量
doc.Variables.FreeVariables.Item("cord").Value = boxcode;//向Label档传入变量
string st = doc.CopyImageToFile(8, "BMP", 0, 100, filePath);
pictureBox1.Load(filePath); //以图片的形式浏览打印的Label
doc.PrintDocument(2);
}