杨张扬
2025-05-14 5729cd163328fc6b53e5db84662ffc06dd6a9bd1
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
using HH.WCS.JunzhouNongfu.device;
using HH.WCS.Mobox3.DoubleCoin.device;
using HH.WCS.Mobox3.DoubleCoin.dispatch;
using HH.WCS.Mobox3.DoubleCoin.util;
using HH.WCS.Mobox3.DoubleCoin.wms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
 
namespace HH.WCS.Mobox3.DoubleCoin.process
{
    /// <summary>
    /// 设备信号处理,主要是tcp信号,我们做server被动接收信号来处理,根据项目定制的
    /// </summary>
    internal class DeviceProcess
    {
        internal static void Analysis(string data, string ip) {
            if (data.Length >= 6) {
                //去掉消息头3F 00
                data = data.Substring(4);
                //Console.WriteLine($"{ip}-{data}");
            }
        }
 
        internal static bool OpenOrCloseDoor(string doorCode, int state) 
        {
            var plc = Settings.SafeDoorDevices.FirstOrDefault(a=>a.DeviceCode == doorCode);
            if (plc != null)
            {
                if (state == 1023)//进入安全门
                {
                    byte[] its = new byte[] {0x3F, 0x00, 0x11, 0x0d, 0x0a };
                    if (!TcpServer.isSend.ContainsKey(plc.IPAddress))
                    {
                        TcpServer.isSend.Add(plc.IPAddress, true);
                    }
                    else
                    {
                        TcpServer.isSend[plc.IPAddress] = true;
                    }
                    return TcpServer.TcpServerSend( plc.IPAddress, its);
                }
 
                if (state == 1025)//离开安全门
                {
                    byte[] its = new byte[] { 0x3F, 0x00, 0x10, 0x0d, 0x0a };
                    if (!TcpServer.isSend.ContainsKey(plc.IPAddress))
                    {
                        TcpServer.isSend.Add(plc.IPAddress, true);
                    }
                    else
                    {
                        TcpServer.isSend[plc.IPAddress] = true;
                    }
                    return TcpServer.TcpServerSend(plc.IPAddress, its);
                }
            }
            return false;
        }
    }
}