public void Sync(object sender, eVulcanizeState state) { lock (_port) { //冷却到出口 _option = (Bit.Tst(state, eVulcanizeState.CoolerToExit) ? Bit.Set(_option, eVulcanizeViceOption.CoolerToExit) : Bit.Clr(_option, eVulcanizeViceOption.CoolerToExit)); //硫化门升 _option = (Bit.Tst(state, eVulcanizeState.VulcanizationDoorUp) ? Bit.Set(_option, eVulcanizeViceOption.VulcanizationDoorUp) : Bit.Clr(_option, eVulcanizeViceOption.VulcanizationDoorUp)); //冷却门升 _option = (Bit.Tst(state, eVulcanizeState.CoolerDoorUp) ? Bit.Set(_option, eVulcanizeViceOption.CoolerDoorUp) : Bit.Clr(_option, eVulcanizeViceOption.CoolerDoorUp)); //硫化到冷却 _option = (Bit.Tst(state, eVulcanizeState.VulcanizationToCooler) ? Bit.Set(_option, eVulcanizeViceOption.CoolerReady) : Bit.Clr(_option, eVulcanizeViceOption.CoolerReady)); //硫化门降 _option = (Bit.Tst(state, eVulcanizeState.VulcanizationDoorDown) ? Bit.Set(_option, eVulcanizeViceOption.VulcanizationDoorDown) : Bit.Clr(_option, eVulcanizeViceOption.VulcanizationDoorDown)); //冷却门降 _option = (Bit.Tst(state, eVulcanizeState.CoolerDoorDown) ? Bit.Set(_option, eVulcanizeViceOption.CoolerDoorDown) : Bit.Clr(_option, eVulcanizeViceOption.CoolerDoorDown)); //手动冷却传送带动 _option = (Bit.Tst(state, eVulcanizeState.HandOpertionCoolerTransmission) ? Bit.Set(_option, eVulcanizeViceOption.HandOpertionCoolerTransmission) : Bit.Clr(_option, eVulcanizeViceOption.HandOpertionCoolerTransmission)); //出口到小车 _option = (Bit.Tst(state, eVulcanizeState.OutToAGV) ? Bit.Set(_option, eVulcanizeViceOption.OutToAGV) : Bit.Clr(_option, eVulcanizeViceOption.OutToAGV)); //急停 _option = (Bit.Tst(state, eVulcanizeState.Estop) ? Bit.Set(_option, eVulcanizeViceOption.EStop) : Bit.Clr(_option, eVulcanizeViceOption.EStop)); //从机复位 _option = (Bit.Tst(state, eVulcanizeState.ViceReset) ? Bit.Set(_option, eVulcanizeViceOption.ViceReset) : Bit.Clr(_option, eVulcanizeViceOption.ViceReset)); _port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 3 * 16, (ushort)_option))); _port.Read(out byte[] result); #if DEBUG var res = _serialize.Deserialize <WriteRandomResult>(result); Logger.LogInfo($"VulcanizeVice:Sync, code:{state.ToString()}"); Logger.LogInfo($"VulcanizeVice:Sync, code:{res.Code.ToString()}"); #endif } }
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; } }