private void HandleMessage(object sender, TransportMessageEventArgs args) { var buffer = args.Buffer; var message = _messageSerializer.Deserialize(buffer.Span); var remote = new SwimHost(args.RemoteEndpoint); switch (message.Type) { case SwimMessageType.Ping: OnPing?.Invoke(this, new TransportPingEventArgs(message as PingMessage, remote)); break; case SwimMessageType.PingReq: OnPingReq?.Invoke(this, new TransportPingReqEventArgs(message as PingReqMessage, remote)); break; case SwimMessageType.Ack: OnAck?.Invoke(this, new TransportAckEventArgs(message as AckMessage, remote)); break; case SwimMessageType.Sync: OnSync?.Invoke(this, new TransportSyncEventArgs(message as SyncMessage, remote)); break; case SwimMessageType.Update: OnUpdate?.Invoke(this, new TransportUpdateEventArgs(message as UpdateMessage, remote)); break; default: throw new ArgumentOutOfRangeException(); } }
private void UpdateFromBuffer() { // The buffer is full FastPoseFrame receivedFrame = new FastPoseFrame(this.MessageBuffer); OnSync?.Invoke(this, new OnSyncEventArgs(receivedFrame)); this.UpdateID = receivedFrame.ID; if (this.UpdateID == STOP_CODE_ID) { // We won't be getting more! Disconnect(); } }
protected async void Update() { while (true) { var status = Task.Run(() => { eVulcanizeState newState = default(eVulcanizeState); lock (_port) { byte[] result; _port.Write(_serialize.Serialize(new ReadRandomCommand(eElementCode.M, 3 * 16))) .Read(out result); var res = _serialize.Deserialize <ReadRandomResult>(result); if (ePlcResultCode.OK == res.Code) { newState = (eVulcanizeState)res.WordData; //Sync OnSync?.Invoke(this, newState); } _port.Write(_serialize.Serialize(new ReadRandomCommand(eElementCode.M, 4 * 16))) .Read(out result); res = _serialize.Deserialize <ReadRandomResult>(result); if (ePlcResultCode.OK == res.Code) { try { newState |= (eVulcanizeState)((res.WordData << 16) & 0xFFFF0000); //Sync OnSync?.Invoke(this, newState); } catch (Exception ex) { Logger.ErrorInfo("主同步副调用", ex); } } } Thread.Sleep(100); return(newState); }); Status = await status; } }
public IAGV <TState, TPosition> Goto(TPosition position, int mode = 0) { byte[] result = null; try { lock (_port) { switch ((int)(eNodeNumber)System.Enum.ToObject(typeof(eNodeNumber), position)) { case 1: _port.Write(_serialize.Serialize(new MotionControlCommand(_AGVNo, eMoveDirection.FrontPatrol, eSpeed.Speed4, eLogicalDirection.LogicalGo, 2))); Thread.Sleep(300); _port.Read(out result, 0, 20); break; case 2: _port.Write(_serialize.Serialize(new MotionControlCommand(_AGVNo, eMoveDirection.FrontPatrol, eSpeed.Speed1, eLogicalDirection.LogicalGo, 2))); Thread.Sleep(300); _port.Read(out result, 0, 20); break; case 3: _port.Write(_serialize.Serialize(new MotionControlCommand(_AGVNo, eMoveDirection.FrontPatrol, eSpeed.Speed1, eLogicalDirection.LogicalGo, 2))); Thread.Sleep(300); _port.Read(out result, 0, 20); break; case 4: _port.Write(_serialize.Serialize(new MotionControlCommand(_AGVNo, eMoveDirection.FrontPatrol, eSpeed.Speed3, eLogicalDirection.LogicalGo, 2))); Thread.Sleep(300); _port.Read(out result, 0, 20); break; case 5: _port.Write(_serialize.Serialize(new MotionControlCommand(_AGVNo, eMoveDirection.FrontPatrol, eSpeed.Speed1, eLogicalDirection.LogicalGo, 2))); Thread.Sleep(300); _port.Read(out result, 0, 20); break; } } #if DEBUG try { var pos = System.Enum.GetName(typeof(TPosition), position); var res = BitConverter.ToString(result).Replace('-', ' '); Logger.LogInfo($"AGV{_AGVNo}:goto {pos}@{mode}, res:{res}"); } catch { } #endif } catch (Exception ex) { Logger.ErrorInfo("Goto cmd", ex); } //_port.Write(_serialize.Serialize(new MotionControlCommand(_AGVNo, eMoveDirection.FrontPatrol, (eSpeed)System.Enum.ToObject(typeof(eSpeed), mode), eLogicalDirection.LogicalGo, 2))); //Thread.Sleep(300); //_port.Read(out result, 0, 20); SyncU3D sync = null; try { switch (_AGVNo) { case 3: switch ((int)(eNodeNumber)System.Enum.ToObject(typeof(eNodeNumber), position)) { case 1: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 0, Position = 1, Operate = true }; OnSync?.Invoke(this, sync); break; case 2: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 0, Position = 1, Operate = true }; OnSync?.Invoke(this, sync); break; case 3: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 0, Position = 2, Operate = true }; OnSync?.Invoke(this, sync); break; case 4: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 0, Position = 3, Operate = true }; OnSync?.Invoke(this, sync); break; case 5: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 0, Position = 4, Operate = true }; OnSync?.Invoke(this, sync); break; } break; case 4: switch ((int)(eNodeNumber)System.Enum.ToObject(typeof(eNodeNumber), position)) { case 1: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 1, Position = 1, Operate = true }; OnSync?.Invoke(this, sync); break; case 2: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 1, Position = 1, Operate = true }; OnSync?.Invoke(this, sync); break; case 3: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 1, Position = 2, Operate = true }; OnSync?.Invoke(this, sync); break; case 4: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 1, Position = 3, Operate = true }; OnSync?.Invoke(this, sync); break; case 5: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 1, Position = 4, Operate = true }; OnSync?.Invoke(this, sync); break; } break; case 6: switch ((int)(eNodeNumber)System.Enum.ToObject(typeof(eNodeNumber), position)) { case 1: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 2, Position = 1, Operate = true }; OnSync?.Invoke(this, sync); break; case 2: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 2, Position = 1, Operate = true }; OnSync?.Invoke(this, sync); break; case 3: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 2, Position = 2, Operate = true }; OnSync?.Invoke(this, sync); break; case 4: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 2, Position = 3, Operate = true }; OnSync?.Invoke(this, sync); break; case 5: sync = new SyncU3D() { type = eSyncU3D.AGV, number = 2, Position = 4, Operate = true }; OnSync?.Invoke(this, sync); break; } break; } } catch (Exception ex) { Logger.ErrorInfo("Goto", ex); } //Thread.Sleep(300); // _port.Read(out result, 0, 20 * 3); return(this); }
public async void Update() { while (true) { SyncU3D sync = null; var status = Task.Run(() => { if (Bit.Tst(_vulcanize.Status, eVulcanizeState.VulcanizationDoorUp)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 1, Operate = true }; } ; if (Bit.Tst(_vulcanize.Status, eVulcanizeState.VulcanizationDoorDown)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 2, Operate = true }; } ; if (Bit.Tst(_vulcanize.Status, eVulcanizeState.CoolerDoorUp)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 3, Operate = true }; } ; if (Bit.Tst(_vulcanize.Status, eVulcanizeState.CoolerDoorDown)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 4, Operate = true }; } ; if (Bit.Tst(_vulcanizeVice.Status, eVulcanizeViceState.CoolerDoorUpReady)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 5, Operate = true }; } ; if (Bit.Tst(_vulcanizeVice.Status, eVulcanizeViceState.CoolerDoorDownReady)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 6, Operate = true }; } ; if (Bit.Tst(_vulcanizeVice.Status, eVulcanizeViceState.VulcanizationDoorUpReady)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 7, Operate = true }; } ; if (Bit.Tst(_vulcanizeVice.Status, eVulcanizeViceState.VulcanizationDoorDownReady)) { sync = new SyncU3D() { type = eSyncU3D.Vulcanize, number = 8, Operate = true }; } ; Thread.Sleep(1000); return(sync); }); sync = await status; OnSync?.Invoke(this, sync); Thread.Sleep(5000); } }