protected async void Update() { while (true) { var status = Task.Run(() => { byte[] result; eEnlaceState newState = default(eEnlaceState); lock (_port) { _port.Write(_serialize.Serialize(new ReadRandomCommand(eElementCode.M, 2 * 16))) .Read(out result); } if (null != result) { var res = _serialize.Deserialize <ReadRandomResult>(result); if (res.Code == ePlcResultCode.OK) { newState = (eEnlaceState)res.WordData; } } Thread.Sleep(100); return(newState); }); Status = await status; } }
public override void Reset(bool force = false) { byte[] result; lock (_port) { _option = Bit.Clr(_option, eEnlaceOption.Reset); _port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 3 * 16, (ushort)_option))); _option = Bit.Set(_option, eEnlaceOption.Reset); _port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 3 * 16, (ushort)_option))); _port.Read(out result); _option = default(eEnlaceOption); Status = default(eEnlaceState); } #if DEBUG var res = _serialize.Deserialize <WriteRandomResult>(result); Logger.LogInfo($"Enlace:reset, code:{res.Code.ToString()}"); #endif }