| | |
| | | { |
| | | public Action<SeerAGVDriver, string> OnAGVPositoinChanged; |
| | | public Action<SeerAGVDriver, AGVTaskStatus> OnAGVTaskStatusChanged; |
| | | public Action<SeerAGVDriver, float, float> OnAGVBatteryLvlChanged; |
| | | |
| | | SeerAGVInitialConfig IConfig |
| | | { |
| | |
| | | |
| | | protected override void Init() |
| | | { |
| | | InitialTcpClient(client_State, IConfig.StatusPort); |
| | | InitialTcpClient(client_Guide, IConfig.GuidePort); |
| | | InitialTcpClient(ref client_State, IConfig.StatusPort); |
| | | InitialTcpClient(ref client_Guide, IConfig.GuidePort); |
| | | } |
| | | |
| | | private void InitialTcpClient(TcpClient client, int port) |
| | | private void InitialTcpClient(ref TcpClient client, int port) |
| | | { |
| | | if (client == null || !client_State.Connected) |
| | | if (client == null || !client.Connected) |
| | | { |
| | | client = new TcpClient(); |
| | | client.SendBufferSize = client.ReceiveBufferSize = 0; |
| | |
| | | { |
| | | msg_Position = new SeerMessage((int)AGVCode.QueryPosition, SID); |
| | | msg_GuideStatus = new SeerMessage((int)AGVCode.QueryTaskStatus, SID, IConfig.IsSimpleMonitor ? JsonConvert.SerializeObject(new { simple = true }) : ""); |
| | | msg_Battery = new SeerMessage((int)AGVCode.QueryBattery, SID, IConfig.IsSimpleMonitor ? JsonConvert.SerializeObject(new { simple = true }) : ""); |
| | | |
| | | Task.Run(() => |
| | | { |
| | |
| | | |
| | | protected override void Stop() |
| | | { |
| | | throw new NotImplementedException(); |
| | | if (client_Guide != null && client_Guide.Connected) |
| | | { |
| | | CancelTask(); |
| | | client_Guide.Close(); |
| | | client_Guide = null; |
| | | } |
| | | |
| | | if (client_State != null && client_State.Connected) |
| | | { |
| | | client_State.Close(); |
| | | client_State = null; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | float batteryLvl = 0; |
| | | public float BatteryLvl |
| | | { |
| | | get => batteryLvl; |
| | | set |
| | | { |
| | | if (batteryLvl != value) |
| | | { |
| | | float pre = batteryLvl; |
| | | batteryLvl = value; |
| | | OnAGVBatteryLvlChanged?.Invoke(this, pre, batteryLvl); |
| | | } |
| | | } |
| | | } |
| | | |
| | | SeerMessage msg_Position = new SeerMessage(); |
| | | SeerMessage msg_GuideStatus = new SeerMessage(); |
| | | SeerMessage msg_Battery = new SeerMessage(); |
| | | private void MonitorAGV() |
| | | { |
| | | while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept) |
| | | { |
| | | SendMsg(client_State, IConfig.StatusPort, msg_Position); |
| | | Thread.Sleep(IConfig.ScanInterval); |
| | | SendMsg(client_State, IConfig.StatusPort, msg_GuideStatus); |
| | | Thread.Sleep(IConfig.ScanInterval); |
| | | try |
| | | { |
| | | SendMsg(client_State, IConfig.StatusPort, msg_Position); |
| | | Thread.Sleep(IConfig.ScanInterval); |
| | | SendMsg(client_State, IConfig.StatusPort, msg_GuideStatus); |
| | | Thread.Sleep(IConfig.ScanInterval); |
| | | SendMsg(client_State, IConfig.StatusPort, msg_Battery); |
| | | Thread.Sleep(IConfig.ScanInterval); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | OnLog?.Invoke(DateTime.Now, this, $"{Name}监听异常:{ex.GetExceptionMessage()}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | InitialTcpClient(client, port); |
| | | InitialTcpClient(ref client, port); |
| | | |
| | | var stream = client.GetStream(); |
| | | stream.Write(msg.Frame, 0, msg.Frame.Length); |
| | |
| | | { |
| | | byte[] rec = buffer.Take(recSize).ToArray(); |
| | | SeerMessage recMsg = SeerMessage.GetSeerMessage(rec); |
| | | |
| | | if (recMsg.TypeCode != msg.TypeCode || recMsg.SeqNum != msg.SeqNum) |
| | | if (recMsg.TypeCode != (10000 + msg.TypeCode) || recMsg.SeqNum != msg.SeqNum) |
| | | { |
| | | throw new ProcessException("反馈信息和发送信息不一致", null); |
| | | } |
| | |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | switch (recMsg.TypeCode) |
| | | switch (recMsg.TypeCode - 10000) |
| | | { |
| | | case (int)AGVCode.QueryPosition: |
| | | CurrentPosition = recMsg.JValues.Value<string>("current_station"); |
| | | break; |
| | | case (int)AGVCode.QueryTaskStatus: |
| | | TaskStatus = (AGVTaskStatus)recMsg.JValues.Value<int>("task_status"); |
| | | break; |
| | | case (int)AGVCode.QueryBattery: |
| | | BatteryLvl = recMsg.JValues.Value<float>("battery_level"); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | { |
| | | CurrentPosition = ""; |
| | | SeerMessage msg = new SeerMessage((int)AGVCode.TaskOrder, SID, JsonConvert.SerializeObject(new { id = dest })); |
| | | |
| | | OnLog?.BeginInvoke(DateTime.Now, this, $"{Name}行驶向 {dest}", null, null); |
| | | SendMsg(client_Guide, IConfig.GuidePort, msg); |
| | | } |
| | | } |