AgvClient.cs
4.7 KB
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
using BLL;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class AgvClient
{
private static string ServerIp = ConfigAppSettings.GetValue(Setting_Init.AgvServerIp);
//private string NodeName = "";
private static Client agvClient = new Client(ServerIp);
public static Dictionary<string, Asa.Actions> actionMap = new Dictionary<string, Asa.Actions>();
public static List<string> NodeList = new List<string>();
public static void Init( )
{
try
{
// this.NodeName = nodeID;
if (agvClient == null)
{
agvClient = new Client(ServerIp);
}
actionMap = new Dictionary<string, Asa.Actions>();
foreach(string key in NodeList)
{
actionMap.Add(key, Asa.Actions.ClientClose);
}
agvClient.Info += AgvClient_Info;
agvClient.Log += AgvClient_Log;
agvClient.Connected += AgvClient_Connected;
agvClient.Action += AgvClient_Action;
agvClient.Connect();
}
catch (Exception ex)
{
LogUtil.error("初始化agvClient " + ServerIp + " 出错:" + ex.ToString());
}
}
internal static bool ISConnected()
{
if (agvClient == null)
{
return false;
}
return agvClient.IsConn;
}
/// <summary>
///02 发送RFID
/// </summary>
/// <param name="NodeName"></param>
internal static void SendRFID(string NodeName, string shelfId)
{
byte[] data = null;
agvClient.SendRFID(NodeName, data);
}
/// <summary>
/// 10 准备空车
/// </summary>
/// <param name="NodeName"></param>
internal static void ReadyEmpty(string NodeName)
{
agvClient.ReadyEmpty(NodeName);
}
/// <summary>
/// 11 准备小车带料架
/// </summary>
/// <param name="NodeName"></param>
internal static void ReadyShelf(string NodeName)
{
agvClient.ReadyShelf(NodeName);
}
/// <summary>
/// 12 可以进入
/// </summary>
/// <param name="NodeName"></param>
internal static void MayEnter(string NodeName)
{
agvClient.MayEnter(NodeName);
}
/// <summary>
///13 完成进入
/// </summary>
/// <param name="NodeName"></param>
internal static void FinishEnter(string NodeName)
{
agvClient.FinishEnter(NodeName);
}
/// <summary>
/// 14 可以出去
/// </summary>
/// <param name="NodeName"></param>
internal static void MayOut(string NodeName)
{
agvClient.MayOut(NodeName);
}
/// <summary>
///17 小车离开
/// </summary>
/// <param name="NodeName"></param>
internal static void GetOut(string NodeName)
{
agvClient.GetOut(NodeName);
}
private static bool AgvClient_Action(string name, Asa.Actions action)
{
if (actionMap.ContainsKey(name))
{
actionMap[name] = action;
}
else
{
actionMap.Add(name, action);
}
return StoreManager.Store.AGVProcess(name, action);
}
private static void AgvClient_Connected()
{
agvClient.SetNodeID(NodeList.ToArray());
}
private static void AgvClient_Log(string s)
{
LogUtil.info("AGV "+ ServerIp + " Log:" + s);
}
private static void AgvClient_Info(string s)
{
LogUtil.info("AGV "+ ServerIp + " Info:" + s);
}
public static Asa.Actions GetAction(string NodeName)
{
if (actionMap.ContainsKey(NodeName))
{
return actionMap[NodeName];
}
return Asa.Actions.ClientClose;
}
public static void Dispose()
{
try
{
if (agvClient != null)
{
agvClient.Close();
}
}
catch (Exception ex)
{
LogUtil.error("释放 agvClient "+ ServerIp + " 出错:" + ex.ToString());
}
}
}
}