zxx
2025-06-04 291185b6c286ab72f3b90208a61cbed78fdbd9ce
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
using HH.WCS.JuShi.api;
using HH.WCS.JuShi.device;
using HH.WCS.JuShi.dispatch;
using HH.WCS.JuShi.util;
using HH.WCS.JuShi.wms;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using static HH.WCS.JuShi.LISTA.process.HttpModel;
using static HH.WCS.JuShi.util.Settings;
 
namespace HH.WCS.JuShi.process
{
    /// <summary>
    /// 设备信号处理,主要是tcp信号,我们做server被动接收信号来处理,根据项目定制的
    /// </summary>
    internal class DeviceProcess
    {
        public static string rgvSafeInteraction = null;
        internal static void Analysis(string data, string ip)
        {
            if (data != null)
            {
                //按钮盒
                //收
                //3A 00 01 00 01 05 73 00 02 01 01 B8
                //发
                //2A 00 01 00 01 05 73 00 02 01 01 A8
                if (data.Substring(0, 2) == "3a")
                {
                    //数据序号
                    data = data.Substring(18, 2);
                    LogHelper.Info($"Analysis======参数{data},{ip}");
                    //根据ip找到起点/终点货位
                    var plc = Settings.deviceInfos.Where(a => a.address == ip).FirstOrDefault();
                    var loc = plc.TN_Location;
                    //1入库2常规送检3紧急送检4三寸空托5六寸空托
                    bool result = false;
                    if (data.Equals("01"))
                    {
                        var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "立库入库区").FirstOrDefault();
                        result = TaskProcess.tcpOffline(loc, reservoirs.areaCode);
                    }
                    else if (data.Equals("02"))
                    {
                        var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "常规送检区").FirstOrDefault();
                        result = TaskProcess.tcpOffline(loc, reservoirs.areaCode);
                    }
                    else if (data.Equals("03"))
                    {
                        var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "紧急送检区").FirstOrDefault();
                        result = TaskProcess.tcpOffline(loc, reservoirs.areaCode);
                    }
                    else if (data.Equals("04"))
                    {
                        var reservoirs = Settings.linePlcInfos.Where(s => s.code == "拆托机1").FirstOrDefault();
                        result = TaskProcess.tcpEmptyTray(reservoirs.outLoca, loc);
                    }
                    else if (data.Equals("05"))
                    {
                        var reservoirs = Settings.linePlcInfos.Where(s => s.code == "拆托机2").FirstOrDefault();
                        result = TaskProcess.tcpEmptyTray(reservoirs.outLoca, loc);
                    }
                    //2A 00 01 00 01 05 73 00 02 01 01 A8
                    // 输入的十六进制字符串数组
                    string[] hexValues = { "2a", "00", "01", "00", "01", "05", "73", "00", "02", data, "01" };
                    // 计算总和
                    int sum = hexValues.Sum(hex => Convert.ToInt32(hex, 16));
                    string returndata = hexValues.ToString() + sum;
                    if (result)
                    {
                        PlcHelper.SendHex(ip, returndata);
                    }
                }
                //rgv安全交互
                else if (data.Substring(0, 4) == "3f00")
                {
                    ////无信号不管
                    //if (data.Trim() != "3f001020304050600d0a")
                    //{
                        LogHelper.Info($"RGV安全交互接收信号{data}");
                        rgvSafeInteraction = data.Substring(4,12);
                        //var reservoirs = Settings.SafeInteractions.Where(s => s.ip == ip).FirstOrDefault();
                        ////1允许卸货  2卸货完成确认
                        //string datastr = "";
                        //switch (reservoirs.pointCode)
                        //{
                        //    case "RGV1":
                        //        datastr = data.Substring(5, 1);
                        //        break;
                        //    case "RGV2":
                        //        datastr = data.Substring(7, 1);
                        //        break;
                        //    case "RGV3":
                        //        datastr = data.Substring(9, 1);
                        //        break;
                        //    case "RGV4":
                        //        datastr = data.Substring(11, 1);
                        //        break;
                        //    case "RGV5":
                        //        datastr = data.Substring(13, 1);
                        //        break;
                        //    case "RGV6":
                        //        datastr = data.Substring(15, 1);
                        //        break;
                        //}
 
                        ////接受信号存到内存
                        //if (rgvSafeInteraction != null)
                        //{
                        //    //string转成list
                        //    var jsonList = JsonConvert.DeserializeObject<List<SafeInteraction>>(rgvSafeInteraction);
                        //    var list = jsonList.Where(s => s.ip == ip).First();
                        //    if (list != null)
                        //    {
                        //        //不为空就先删再加上
                        //        jsonList.Remove(list);
                        //    }
                        //    jsonList.Add(new SafeInteraction { ip = ip, data = datastr });
                        //    rgvSafeInteraction = JsonConvert.SerializeObject(jsonList);
                        //}
                        //else
                        //{
                        //    //第一次进
                        //    var safeInteractions = new List<SafeInteraction>{new SafeInteraction { ip = ip, data = datastr }};
                        //    rgvSafeInteraction = JsonConvert.SerializeObject(safeInteractions);
                        //}
                        //LogHelper.Info($"RGV安全交互 存入内存参数{rgvSafeInteraction}");
                    //}
 
 
                }
            }
 
 
            //
            //if (data.Length >= 6)
            //{
            //    //去掉消息头3F 00
            //    data = data.Substring(4);
            //    //Console.WriteLine($"{ip}-{data}");
            //    var plc = Settings.deviceInfos.Where(a => a.address == ip && a.enable == 1).FirstOrDefault();
            //    if (plc != null)
            //    {
            //        if (plc.deviceType == 1)
            //        {
            //            if (data == "")
            //            {
            //                Traystacker(plc);
            //            }
            //        }
            //    }
            //    else
            //    {
            //        Console.WriteLine($"TCP信号处理:未查询到IP为{ip}的数据,请检查deviceInfo配置中心是否存在该IP的数据!");
            //    }
            //}
 
        }
 
 
 
        internal static void Traffic(string forkliftNo, string lockNo, bool v)
        {
 
        }
    }
}