轮胎外观检测添加思谋语义分割模型检测工具
C3204
2026-03-30 06c627ec032b3f3876fd7db8a3ff0ff1a6614fa2
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using ClassLibrary1;
using DeviceITisation;
using LB_VisionProcesses.Communicators;
using LB_VisionProcesses.Communicators.Tcom;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using System.Diagnostics;
 
namespace LB_VisionProcesses.Communicators.USerCommunicator.T306CommandTool
{
    public class T306CommandTool : CommunicatorConfig
    {
        string HDCP14CHECK = "0422CCF2";
        string HDCP22CHECK = "0422C2E8";
        string HDCPOFF = "05229900C0";
        string ok = "031114";
 
        bool isFirstRun = true;
        string lastHDMIType = "HDMI1";
        bool lastCheckHDCP14 = true;
        bool lastCheckHDCP22 = true;
 
        public T306CommandTool(ConcurrentDictionary<string, BaseCommunicator> dicCommunicators)
            : base(dicCommunicators)
        {
            strProcessName = "T306通讯";
            strProcessClass = "LB_VisionProcesses.Communicators.T306CommandTool";
 
            Params.Inputs.Add("通讯口名", "");
            Params.Inputs.Add("HDMI口", "HDMI1");
            Params.Inputs.Add("HDCP1.4", false);
            Params.Inputs.Add("HDCP2.2", false);
            Params.Outputs.Add("收到消息", "");
 
            Params.Inputs.Add("SN", "");
            Params.Inputs.Add("BOM", "");
            Params.Inputs.Add("是否自动切换HDCP检查", true);
 
            //修改基类CommunicatorConfig的默认值
            Params.Inputs.Add("通讯类型", CommunicatorType.Sender);
            Params.Inputs.Add("是否启用CRC校验", false);
            Params.Inputs.Add("通讯消息", "");
        }
 
        public override bool Run()
        {
            string strHDMIType = Params.Inputs["HDMI口"]?.ToString();
            bool isCheckHDCP14 = Convert.ToBoolean(Params.Inputs["HDCP1.4"]);
            bool isCheckHDCP22 = Convert.ToBoolean(Params.Inputs["HDCP2.2"]);
 
            try
            {
                InitRunParams();
                Params.Inputs.Add("通讯消息", "");
                Params.Outputs.Add("收到消息", "");
 
                string CommunicatorName = Params.Inputs["通讯口名"].ToString();
 
                if (!dicCommunicators.ContainsKey(CommunicatorName))
                {
                    Msg = $"通讯口[{CommunicatorName}]不存在";
                    Result = false;
                    return Result;
                }
 
                BaseCommunicator BaseCommunicator = dicCommunicators[CommunicatorName];
 
                if (BaseCommunicator == null)
                {
                    Msg = $"通讯口[{CommunicatorName}]未实例化";
                    Result = false;
                    return Result;
                }
 
                if (!(BaseCommunicator is UARTPort port))
                {
                    Msg = $"通讯口[{CommunicatorName}]不是UART串口";
                    Result = false;
                    return Result;
                }
 
                if (!BaseCommunicator.bConnected)
                {
                    Msg = $"通讯口[{CommunicatorName}]未连接";
                    Result = false;
                    return Result;
                }
 
                // 首次运行或HDMI口切换时 发送切换命令
                if (isFirstRun || lastHDMIType != strHDMIType)
                {
                    switch (strHDMIType)
                    {
                        case "HDMI1":
                            port.SendMessage(BaseCommunicator.strToHexByte("41"));
                            break;
                        default:
                            port.SendMessage(BaseCommunicator.strToHexByte("14"));
                            break;
                    }
                }
 
                try
                {
                    // 自动切换HDCP检查
                    if (Convert.ToBoolean(Params.Inputs["是否自动切换HDCP检查"]?.ToString()))
                    {
                        string SN = Params.Inputs["SN"]?.ToString();
                        string BOM = Params.Inputs["BOM"].ToString();
 
                        // SN为空 则不处理
                        if (string.IsNullOrEmpty(SN))
                            return true;
 
                        if (Class1.GetBOMAndODF(SN, out string NowBOM, out string NowODF))
                        {
                            string bomstring = Class1.getBOMDesc(NowBOM);
                            REject re = JsonConvert.DeserializeObject<REject>(bomstring);
                            eClass eClass = re.E_CLASS;
                            string BP = eClass.BP.ToUpper();
                            if (NowBOM != BOM)
                            {
                                Params.Inputs["BOM"] = NowBOM;
 
                                // 小米关闭HDCP检查 其余至少开启HDCP1.4检查
                                if (BP.Contains("MI"))
                                {
                                    Params.Inputs.Add("HDCP1.4", false);
                                    Params.Inputs.Add("HDCP2.2", false);
                                    return CheckHDMIHDCP(port, false, false);
                                }
                                else
                                {
                                    Params.Inputs.Add("HDCP1.4", true);
                                    return CheckHDMIHDCP(port, true, false);
                                }
                            }
                            else
                            {
                                // BOM未变化 复查HDCP勾选项是否正确
 
                                // 小米关闭HDCP检查 其余至少开启HDCP1.4检查
                                if (BP.Contains("MI"))
                                {
                                    if (isCheckHDCP14 || isCheckHDCP22)
                                    {
                                        Params.Inputs.Add("HDCP1.4", false);
                                        Params.Inputs.Add("HDCP2.2", false);
                                        return CheckHDMIHDCP(port, false, false);
                                    }
                                    return true;
                                }
                                else
                                {
                                    if (!isCheckHDCP14)
                                    {
                                        Params.Inputs.Add("HDCP1.4", true);
                                        return CheckHDMIHDCP(port, true, false);
                                    }
                                }
                            }
                        }
                        return false;
                    }
                }
                catch { }
 
                // 不切换HDCP检查时 执行以下逻辑
                if (!isCheckHDCP14 && !isCheckHDCP22)
                {
                    // 关闭HDCP检测
                    if (!CheckHDMIHDCP(port, false, false))
                    {
                        Msg = $"关闭HDCP检测失败";
                        Result = false;
                        return Result;
                    }
                }
                else
                {
                    if (isCheckHDCP14)
                    {
                        if (!CheckHDMIHDCP(port, true, false))
                        {
                            Msg = $"HDCP1.4检测失败";
                            Result = false;
                            return Result;
                        }
                    }
                    if (isCheckHDCP22)
                    {
                        if (!CheckHDMIHDCP(port, false, true))
                        {
                            Msg = $"HDCP2.2检测失败";
                            Result = false;
                            return Result;
                        }
                    }
                }
 
            }
            catch (Exception ex)
            {
                Msg = $"通讯异常,原因是:{ex.Message}";
                Result = false;
            }
            finally
            {
                isFirstRun = false;
                lastHDMIType = strHDMIType;
                lastCheckHDCP14 = (bool)Params.Inputs["HDCP1.4"];
                lastCheckHDCP22 = (bool)Params.Inputs["HDCP2.2"];
            }
            return Result;
        }
 
        bool CheckHDMIHDCP(UARTPort port, bool check14, bool check22)
        {
            string SendMsg = string.Empty;
            try
            {
                string response = string.Empty;
 
                response = string.Empty;
 
                // 关闭HDCP检测
                if (!check14 && !check22)
                    SendMsg = HDCPOFF;
                else
                {
                    // 检测HDCP1.4
                    if (check14 && !check22)
                        SendMsg = HDCP14CHECK;
 
                    // 检测HDCP2.2
                    if (!check14 && check22)
                        SendMsg = HDCP22CHECK;
                }
 
                for (int i = 0; i < 3; i++)
                {
                    port.SendMessage(BaseCommunicator.strToHexByte(SendMsg));
                    response += port.ReceiveMsg();
                    if (response.Contains(ok))
                        return true;
                }
 
                return false;
            }
            catch (Exception e) { Debug.WriteLine($"CheckHDMIHDCP:{e.Message}[{e.StackTrace}]"); return false; }
            finally
            {
                Params.Inputs.Add("通讯消息", SendMsg);
                Params.Outputs.Add("收到消息", port.ReceiveMsg());
            }
        }
    }
}