MainMachine_PrinterProcess.cs
4.3 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
using OnlineStore;
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
{
partial class MainMachine
{
void SetPrintJob(MoveInfo reel) {
reel.log("设置打印任务:"+reel.MoveParam.ToDetailStr());
PrintJob = reel.MoveParam.clone();
var cc = PrintJob.codeInfos.Select((a) => a.CodeType + ":" + a.CodeStr);
CountMoveInfo.log("打印时 Code:" + String.Join("##", cc));
}
readonly MoveInfo PrintMoveInfo = new MoveInfo("打印机", false);
ReelParam PrintJob = null;
ReelParam CurrentPrintJob = null;
Task<(bool, string)> PrintTask = null;
bool IsLabelPrinted = false;
void PrinterProcess()
{
if (CheckWait(PrintMoveInfo))
return;
switch (PrintMoveInfo.MoveStep)
{
case MoveStep.Wait:
if (PrintJob != null)
{
CurrentPrintJob = PrintJob.clone();
PrintJob = null;
PrintMoveInfo.NextMoveStep(MoveStep.Print_01);
}
break;
case MoveStep.Print_01:
PrintMoveInfo.NextMoveStep(MoveStep.Print_02);
IsLabelPrinted = false;
PrintTask = RobotManage.printerHelper.PrintLabel(CurrentPrintJob);
PrintMoveInfo.log("检测到打印任务开始打印:" + CurrentPrintJob.ToDetailStr());
break;
case MoveStep.Print_02:
if (PrintTask.IsCompleted)
{
var (result, msg) = PrintTask.Result;
if (result)
{
PrintMoveInfo.NextMoveStep(MoveStep.Print_04);
PrintMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
PrintMoveInfo.log("打印成功,等待标签被取走");
}
else
{
Msg.add("打印机反馈:" + msg, MsgLevel.alarm);
RobotManage.UserPause("打印机反馈:" + msg);
PrintMoveInfo.NextMoveStep(MoveStep.Print_01);
PrintMoveInfo.log("打印失败,再次打印");
}
}
else if (PrintMoveInfo.IsTimeOut(30)) {
Msg.add("打印标签超时请检查打印机状态", MsgLevel.alarm);
}
break;
case MoveStep.Print_04:
PrintMoveInfo.NextMoveStep(MoveStep.Print_WaitTakeLabel);
//PrintTask = RobotManage.printerHelper.IsLabelOnPeeler();
PrintMoveInfo.log("查询剥离器状态");
break;
case MoveStep.Print_WaitTakeLabel:
//if (PrintTask.IsCompleted)
//{
// if (PrintTask.Result.Item1)
// {
// PrintMoveInfo.log("等待标签被取走");
// PrintMoveInfo.NextMoveStep(MoveStep.Print_04);
// IsLabelPrinted = true;
// }
// else if (IsLabelPrinted)
// {
// PrintMoveInfo.log("标签已被取走");
// PrintMoveInfo.NextMoveStep(MoveStep.Print_06);
// }
//}
break;
case MoveStep.Print_LabelTaked:
PrintMoveInfo.log("标签已取走");
CurrentPrintJob = null;
RobotManage.printerHelper.Close();
PrintMoveInfo.NextMoveStep(MoveStep.Wait);
PrintMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
default:
LabelMoveInfo.log($"未找到对应步骤:{LabelMoveInfo.MoveStep}");
break;
}
}
}
}