예제 #1
0
        protected async void Update()
        {
            while (true)
            {
                var status = Task.Run(() =>
                {
                    byte[] result;
                    eVulcanizeViceState newState = default(eVulcanizeViceState);
                    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 = (eVulcanizeViceState)res.WordData;
                            }
                        }
                    }

                    //Sync
                    lock (_port)
                    {
                        _port.Write(_serialize.Serialize(new ReadCommand(eElementCode.D, 50, 24)))
                        .Read(out result);
                    }
                    var data = _serialize.Deserialize <PlcResultBase>(result);
                    if (ePlcResultCode.OK == data.Code)
                    {
                        try
                        {
                            OnViceSync?.Invoke(this, result.Skip(11).ToArray(), newState);
                        }
                        catch (Exception ex)
                        {
                            Logger.ErrorInfo("副同步主调用", ex);
                        }
                    }
                    Thread.Sleep(100);
                    return(newState);
                });
                Status = await status;
            }
        }
예제 #2
0
        public void ViceSync(object sender, byte[] args, eVulcanizeViceState state)
        {
            var cmd = _serialize.Serialize(new WriteCommand(eElementCode.D, 50, 24))
                      .Concat(args).ToArray();

            lock (_port)
            {
                _port.Write(cmd)
                .Read(out byte[] result);
                var data = _serialize.Deserialize <PlcResultBase>(result);
            }

            lock (_port)
            {
                //硫化门已升
                _option = (Bit.Tst(state, eVulcanizeViceState.VulcanizationDoorUpReady) ? Bit.Set(_option, eVulcanizeOption.VulcanizationDoorUpReady) : Bit.Clr(_option, eVulcanizeOption.VulcanizationDoorUpReady));
                //出盘已准备
                _option = (Bit.Tst(state, eVulcanizeViceState.OutDiscReady) ? Bit.Set(_option, eVulcanizeOption.OutDiscReady) : Bit.Clr(_option, eVulcanizeOption.OutDiscReady));
                //硫化门已降
                _option = (Bit.Tst(state, eVulcanizeViceState.VulcanizationDoorDownReady) ? Bit.Set(_option, eVulcanizeOption.VulcanizationDoorDownReady) : Bit.Clr(_option, eVulcanizeOption.VulcanizationDoorDownReady));
                //出口到小车
                _option = (Bit.Tst(state, eVulcanizeViceState.ExitToAGV) ? Bit.Set(_option, eVulcanizeOption.ExitToAGV) : Bit.Clr(_option, eVulcanizeOption.ExitToAGV));
                //硫化到冷却已完成
                _option = (Bit.Tst(state, eVulcanizeViceState.CoolerReady) ? Bit.Set(_option, eVulcanizeOption.CoolerReady) : Bit.Clr(_option, eVulcanizeOption.CoolerReady));

                _port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 5 * 16, (ushort)_option)));
                _port.Read(out byte [] result);

#if DEBUG
                var res = _serialize.Deserialize <WriteRandomResult>(result);

                Logger.LogInfo($"Vulcanize:ViceSync, code:{state.ToString()}");
                Logger.LogInfo($"Vulcanize:ViceSync, code:{res.Code.ToString()}");
#endif
            }
        }