1
hwh
2024-08-23 3d1df57ccc06c0c84813fac71f19ee5a4187b3da
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
 
using IoTClient;
 
namespace WCS.Application;
public static class PLCService
{
 
    public static void OnChangeEvent(object sender, EventArgs e)
    {
        var mod = sender as WcsDeviceDto;
        Console.WriteLine("PLC值为" + mod.Value);
        switch (mod.Type)
        {
            case PLCTypeEnum.StackingMachine:
                //写死测试读string
                var (res, val) = mod.PLCUtil.GetPlcDBValue(PLCDataTypeEnum.String, "DB100", "64");
                Console.WriteLine("DB100.64----" + val);
                //测试批量读取
                Dictionary<string, PLCDataTypeEnum> listaddress = new Dictionary<string, PLCDataTypeEnum>();
                foreach (var modStation in mod.listStation)
                {
                    listaddress.Add(modStation.PlcPos, modStation.PosType.Value);
                }
                var result = mod.PLCUtil.GetPlcBatchDBValue(listaddress);
                if (result.Value.Count > 0)
                {
                    foreach (var value in result.Value)
                    {
                        Console.WriteLine("地址" + value.Key + "----值" + value, value);
                    }
                }
                if (!result.IsSucceed)
                {
                    foreach (var err in result.ErrList)
                    {
                        Console.WriteLine(err);
                    }
                    if (result.Value.Count > 0)//有错误的也有成功的
                    {
 
                    }
                }
                if (mod.Value == 820)
                {
                    //测试写入830
                    //var result = mod.PLCUtil.SetPlcDBValue(mod.PosType.Value, mod.DbNumber, mod.PlcPos, "830");
                    ////写入是否成功
                    //if (result.IsSucceed)
                    //{
 
                    //}
                }
                else if (mod.Value == 840)
                {
 
                }
                else if (mod.Value == 860)
                {
 
                }
                break;
            case PLCTypeEnum.ConveyorLine:
 
                break;
            case PLCTypeEnum.AGV:
                break;
            case PLCTypeEnum.PalletMachine:
 
                break;
            default:
                break;
        }
    }
 
}