/// <summary> /// read a word /// </summary> private void ReadWord() { if (string.IsNullOrWhiteSpace(word_position.Text) || string.IsNullOrWhiteSpace(word_count.Text)) return; UInt16 val = 0; try { MemoryArea area = (MemoryArea) word_memory_area.SelectedItem; UInt16 position = Convert.ToUInt16(word_position.Text); UInt16 count = Convert.ToUInt16(word_count.Text); if (! plc.finsMemoryAreadRead(area, position, 0, count)) { throw new Exception(plc.LastError); } val = BTool.BytesToUInt16(plc.FinsCommand.Response[0], plc.FinsCommand.Response[1]); word_value.Text = val.ToString(); dialog.Text = plc.LastDialog("READ WORD"); dialog.AppendText("WORD VALUE: " + val.ToString()); } catch (Exception ex) { MessageBox.Show("ReadWord() Error: " + ex.Message); } }
/// <summary> /// write a single word /// </summary> private void WriteWord() { if (string.IsNullOrWhiteSpace(word_position.Text) || string.IsNullOrWhiteSpace(word_count.Text)) return; UInt16 val = 0; try { val = Convert.ToUInt16(word_value.Text); if (MessageBox.Show("This action will write some memory area of your PLC.\n\nContinue anyway?" , "OMRON PLC text" , MessageBoxButtons.OKCancel , MessageBoxIcon.Question , MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.OK) { return; } var area = (MemoryArea) word_memory_area.SelectedItem; var position = Convert.ToUInt16(word_position.Text); var count = Convert.ToUInt16(word_count.Text); var data = BTool.Uint16toBytes(val); if (count > 1) return; if (! plc.finsMemoryAreadWrite(area, position, 0, 1, data)) { throw new Exception(plc.LastError); } dialog.Text = plc.LastDialog("WRITE WORD"); } catch (Exception ex) { MessageBox.Show("WriteWord() error: " + ex.Message); } }
private bool ProcessCommand(UnitCommand cmd) { if (!GetReady()) { return(false); } EUnitCommand eCmd = cmd._eCommandID; if (eCmd == EUnitCommand.UNITCMD_MOVE) { if (!_unit._isMobile) { return(false); } } else if (eCmd == EUnitCommand.UNITCMD_ATTACK) { if (!_unit._canAttack) { return(false); } } Behavior behavior = null; if (cmd._yQueue == QueueType.QUEUE_NONE) { // ClearBrainQueue(); } else { if (_behaviors.Count > 0) { behavior = _behaviors.Peek(); if (behavior.GetDefault()) { } else { bool popFront = true; if (eCmd == EUnitCommand.UNITCMD_TOOL) { GameObject obj = GameEntity.GetEntity(cmd._param); if (obj != null) { Tool tool = obj.GetComponent <Tool>(); if (tool != null) { popFront = !tool.NonInterrupting; } } } if (popFront) { behavior.EndBehavior(); _behaviors.Dequeue(); } } } } switch (eCmd) { case EUnitCommand.UNITCMD_MOVE: behavior = new BMove(this, _unit); break; case EUnitCommand.UNITCMD_ATTACK: behavior = new BAttack(this, _unit); break; case EUnitCommand.UNITCMD_TOOL: behavior = new BTool(this, _unit, cmd._param); break; default: Debug.LogWarning("Brain ProcessCommand: Unrecognized Unit Command"); break; } if (behavior != null) { behavior.SetDir(cmd._v3Dir); behavior.SetIssuedClientNumber(cmd._clientNumber); behavior.SetDefault(cmd._default); behavior.SetLevel(cmd._level); if (cmd._forced) { behavior.SetForced(true); behavior.SetForcedTime(Game._instance.GetGameTime() + cmd._forcedDuration); } if (cmd._restricted) { behavior.SetRestricted(true); } if (cmd._duration != uint.MaxValue) { behavior.SetEndTime(Game._instance.GetGameTime() + cmd._duration); } else { behavior.SetEndTime(uint.MaxValue); } if (cmd._yQueue == QueueType.QUEUE_FRONT) { if (_behaviors.Count > 0) { Behavior front = _behaviors.Peek(); if (front != null && front.GetRestricted()) { bool popFront = true; if (eCmd == EUnitCommand.UNITCMD_TOOL) { GameObject obj = GameEntity.GetEntity(cmd._param); if (obj != null) { Tool tool = obj.GetComponent <Tool>(); if (tool != null) { popFront = !tool.NonInterrupting; } } } if (popFront) { front.EndBehavior(); _behaviors.Dequeue(); } } } _behaviors.PushFront(behavior); } else if (cmd._yQueue == QueueType.QUEUE_FRONT_CLEAR_MOVES) { foreach (Behavior temp in _behaviors) { if (temp == null) { continue; } if (temp.GetBType() == Behavior.EBehaviorType.EBT_MOVE) { _behaviors.Erase(temp); continue; } } _behaviors.PushFront(behavior); } else { _behaviors.Enqueue(behavior); } return(true); } return(false); }