LabelMachine.print.cs
7.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
using crc = OnlineStore.CodeResourceControl;
public partial class LabelMachine
{
public void InitPrint()
{
RobotManage.PrintBean.PrintStatusChanged += Print_PrintStatusChanged;
RobotManage.LoadPrintSetting();
}
public Asa.PrintLabel.PrinterStatus LastPrintStatus = Asa.PrintLabel.PrinterStatus.Unknown;
void Print_PrintStatusChanged(Asa.PrintLabel.PrinterStatus sta, string msg)
{
if (sta.Equals(LastPrintStatus).Equals(false))
{
LogUtil.info("PrintLabel 收到打印机新状态:【" + sta + "】【" + msg + "】,替换原来的状态【" + LastPrintStatus + "】 ");
}
else
{
if (sta == Asa.PrintLabel.PrinterStatus.Idle)
{
Task.Run(() => {
while (true)
{
if (MoveInfo.IsStep(MoveStep.Lbl_WaitPrint))
{
MoveInfo.NextMoveStep(MoveStep.Lbl_Printted);
break;
}
Task.Delay(500).Wait();
}
});
}
LogUtil.info(" PrintLabel 收到打印机新状态:【" + sta + "】【" + msg + "】,与之前状态一样 ");
}
LastPrintStatus = sta;
}
public string LastPrintLabel = "";
void StartPrintLabel(string wareCode, string wareCount, bool ReverseLabel=false)
{
try
{
LastPrintStatus = Asa.PrintLabel.PrinterStatus.Unknown;
LogUtil.info("调用 PrintLabel 打印标签 StartPrintLabel ,[" + wareCode + "] [" + wareCount + "] 开始");
Dictionary<string, string> text = new Dictionary<string, string>();
text.Add("Code", wareCode);
text.Add("Count", wareCount);
text.Add("DateTime", System.DateTime.Now.ToString("F"));
text.Add("FactoryCode", "");
LastPrintLabel = wareCode;
RobotManage.PrintBean.Rotate180 = ReverseLabel;
RobotManage.PrintBean.Print(text);
LogUtil.info("PrintLabel 打印标签 StartPrintLabel 结束 ");
}
catch (Exception ex)
{
LogUtil.error("PrintLabel 打印标签 StartPrintLabel 错误:" + ex.ToString());
}
}
public Task DoPrint(ReelParam labelParam, bool ReverseLabel = false)
{
LogUtil.info($"调用 PrintLabel 打印标签 WareCode:{labelParam.WareCode}, QTY:{labelParam.QTY}, ReverseLabel:{ReverseLabel}");
StartPrintLabel(labelParam.WareCode, labelParam.QTY.ToString(), ReverseLabel);
return Task.Run(() =>
{ });
}
/// <summary>
/// 扫码线程
/// </summary>
Task<(List<CodeInfo>,Bitmap)> ScanTask;
Task<(Point, double, bool)> ScanTask2;
Task<(List<CodeInfo>, Bitmap)> ScanCode()
{
MoveInfo.log("开始贴标扫码线程");
return Task.Run(new Func<(List<CodeInfo>, Bitmap)>(() =>
{
try
{
Bitmap bitmap;
//IOMove(IO_Label_Type.Camera_Led, IO_VALUE.HIGH);
//Task.Delay(10).Wait();
List<CodeInfo> LastCodeList = CodeManager.CameraScan(new List<string> { Config.CameraName },out bitmap);
if (LastCodeList.Count <= 0)
{
Task.Delay(500).Wait();
LastCodeList = CodeManager.CameraScan(new List<string> { Config.CameraName });
}
//IOMove(IO_Label_Type.Camera_Led, IO_VALUE.LOW);
return (LastCodeList,bitmap);
}
catch {
return (new List<CodeInfo>(),null);
}
}));
}
Task<(Point, double, bool)> ScanCode2()
{
MoveInfo.log("开始贴标扫码线程");
return Task.Run(new Func<(Point, double, bool)>(() =>
{
try
{
Bitmap bitmap;
Task.Delay(700).Wait();
List<CodeInfo> LastCodeList = CodeManager.CameraScan(new List<string> { Config.CameraName }, out bitmap);
if (LastCodeList.Count <= 0)
{
//Task.Delay(500).Wait();
//LastCodeList = CodeManager.CameraScan(new List<string> { Config.CameraName });
}
if (LastCodeList.Count == 0)
{
MoveInfo.NextMoveStep(MoveStep.Lbl_WaitCheckLabel);
MoveInfo.log($"未识别到有效二维码");
WaitCheckLabeltype = WaitCheckLabeltypeE.Scan_QRCode_Fail;
}
else
{
if (MoveInfo.ReelParam.WareCode != LastCodeList[0].CodeStr)
{
MoveInfo.NextMoveStep(MoveStep.Lbl_WaitCheckLabel);
Msg.add(crc.GetString("label_qrcode_different", "扫描到的Reelid与发出打印的可能不一致"), MsgLevel.warning);
MoveInfo.log($"扫描到的Reelid与发出打印的不一致,系统:{MoveInfo.ReelParam.WareCode},实际:{LastCodeList[0].CodeStr}");
WaitCheckLabeltype = WaitCheckLabeltypeE.Scan_Code_And_Print_are_different;
//MoveInfo.ReelParam.IsNg = true;
//MoveInfo.ReelParam.NgMsg = "扫描到的Reelid与发出打印的不一致";
//MoveInfo.ReelParam.logresult();
}
else
{
//MoveInfo.NextMoveStep(MoveStep.Lbl_Printted);
MoveInfo.ReelParam.codeInfos = LastCodeList;
MoveInfo.log($"已完成扫码, Count={LastCodeList.Count}");
MoveInfo.ReelParam.logresult();
}
MoveInfo.ReelParam.logresult();
//标签坐标
Point Label_Pix_Point = new Point(MoveInfo.ReelParam.codeInfos[0].X, MoveInfo.ReelParam.codeInfos[0].Y);
//照片坐标反转180度
var x = 5472 - Label_Pix_Point.X;
var y = 3648 - Label_Pix_Point.Y;
Label_Pix_Point.X = x;
Label_Pix_Point.Y = y;
//图像也旋转180度
bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
(p1, labelRAxisPos, ReverseLabel) = ClacLabel2(Label_Pix_Point, bitmap, MoveInfo.ReelParam);
return (p1, labelRAxisPos, ReverseLabel);
}
return (Point.Empty, 0, false);
}
catch
{
return (Point.Empty, 0, false);
}
}));
}
}
}