C3204
2025-12-18 d85cbf0ccd61d95b96695756e0c90db8b7679545
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
using LB_VisionProcesses.Communicators.TCom;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace LB_VisionProcesses.Communicators.UserCommunicator.T306Command
{
    internal class T306CommandTool : CommunicatorConfig
    {
        string HDCP14CHECK = "0422CCF2";
        string HDCP22CHECK = "0422C2E8";
        string ok = "031114";
 
        public T306CommandTool(ConcurrentDictionary<string, BaseCommunicator> dicCommunicators)
            : base(dicCommunicators)
        {
            strProcessName = "T306通讯";
            strProcessClass = "LB_VisionProcesses.Communicators.T306CommandTool";
 
            Params.Inputs.Add("通讯口名", "");
            Params.Inputs.Add("HDMI1", false);
            Params.Inputs.Add("HDMI2", false);
            Params.Inputs.Add("HDCP1.4", false);
            Params.Inputs.Add("HDCP2.2", false);
            Params.Outputs.Add("收到消息", "");
 
            //修改基类CommunicatorConfig的默认值
            Params.Inputs.Add("通讯类型", CommunicatorType.Sender);
            Params.Inputs.Add("是否启用CRC校验", false);
            Params.Inputs.Add("通讯消息", "T306系统预设指令");
        }
 
        public override bool Run()
        {
            try
            {
                InitRunParams();
                Params.Outputs["收到消息"] = "";
                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}]不是串口";
                    Result = false;
                    return Result;
                }
 
                if (!BaseCommunicator.bConnected)
                {
                    Msg = $"通讯口[{CommunicatorName}]未连接";
                    Result = false;
                    return Result;
                }
 
                bool isCheckHDMI1 = (bool)Params.Inputs["HDMI1"];
                bool isCheckHDMI2 = (bool)Params.Inputs["HDMI2"];
                bool isCheckHDCP14 = (bool)Params.Inputs["HDCP1.4"];
                bool isCheckHDCP22 = (bool)Params.Inputs["HDCP2.2"];
                bool bHDMI1 = true, bHDMI2 = true;
 
                if (isCheckHDMI1 && isCheckHDCP14)
                    bHDMI1 = CheckHDMIHDCP(port, "HDMI1", true, false);
 
                if (isCheckHDMI2 && bHDMI1 && isCheckHDCP22)
                    bHDMI2 = CheckHDMIHDCP(port, "HDMI2", false, false);
 
                if (!bHDMI1 || !bHDMI2)
                {
                    Msg = !bHDMI1 ? $"HDCP1.4检测失败" : $"HDCP2.2检测失败";
                    Result = false;
                    return Result;
                }
            }
            catch (Exception ex)
            {
                Msg = $"通讯异常,原因是:{ex.Message}";
                Result = false;
            }
            return Result;
        }
 
        bool CheckHDMIHDCP(UARTPort port, string strHDMI, bool check14, bool check22)
        {
            try
            {
                string response = string.Empty;
                switch (strHDMI)
                {
                    case "HDMI1":
                        port.SendMessageBytes(BaseCommunicator.strToHexByte("41"));
                        break;
                    case "HDMI2":
                        port.SendMessageBytes(BaseCommunicator.strToHexByte("14"));
                        break;
                    default:
                        return false;
                }
 
                response = string.Empty;
                for (int i = 0; i < 3; i++)
                {
                    if (check14)
                    {
                        port.SendMessageBytes(BaseCommunicator.strToHexByte(HDCP14CHECK));
                        response += port.ReceiveMsg();
                        if (response.Contains(ok))
                            return true;
                    }
 
                    if (check22)
                    {
                        port.SendMessageBytes(BaseCommunicator.strToHexByte(HDCP22CHECK));
                        response += port.ReceiveMsg();
                        if (response.Contains(ok))
                            return true;
                    }
                }
 
                return false;
            }
            catch (Exception e) { Debug.WriteLine($"CheckHDMIHDCP:{e.Message}[{e.StackTrace}]"); return false; }
        }
    }
 
}