Beispiel #1
0
        private bool GetRobotSetting(out string robotWorkSpace)
        {
            byte[] dataIdle, dataBusy;
            robotWorkSpace = "";
            if (!GetRobotEvent(0, out dataIdle))
            {
                return(false);
            }
            if (!GetRobotEvent(1, out dataBusy))
            {
                return(false);
            }

            XmlDocument root   = new XmlDocument();
            XmlElement  parent = root.CreateElement(string.Empty, "xml", string.Empty);

            parent.SetAttribute("id", "workspaceBlocks");
            parent.SetAttribute("style", "display:none");
            root.AppendChild(parent);

            RobotHandler rhIdle = new RobotHandler(dataIdle, BLOCKLY.HAT.IDLE, 0, 0);
            RobotHandler rhBusy = new RobotHandler(dataBusy, BLOCKLY.HAT.BUSY, 400, 0);

            parent.AppendChild(rhIdle.ToXml(root));
            parent.AppendChild(rhBusy.ToXml(root));

            robotWorkSpace = XmlToString(root);
            return(true);
        }
        private void BuildObject(string xmlStr)
        {
            sbObjInfo = new StringBuilder();
            xmlStr    = RemoveXmlNamespace(xmlStr);

            XmlDocument xml = new XmlDocument();

            xml.LoadXml(xmlStr);

            string nodePath;

            nodePath = string.Format("//block[@type=\"{0}\"]", BLOCKLY.HAT.BUSY);
            XmlNodeList busyNode = xml.SelectNodes(nodePath);

            if (busyNode.Count == 0)
            {
                MessageBox.Show("動作執行中事件遺失了");
                return;
            }
            if (busyNode.Count > 1)
            {
                MessageBox.Show("超過一個動作執行中事件");
                return;
            }

            nodePath = string.Format("//block[@type=\"{0}\"]", BLOCKLY.HAT.IDLE);
            XmlNodeList idleNode = xml.SelectNodes(nodePath);

            if (idleNode.Count == 0)
            {
                MessageBox.Show("閒置事件遺失了");
                return;
            }
            if (idleNode.Count > 1)
            {
                MessageBox.Show("超過一個閒置事件");
                return;
            }

            RobotHandler idle = new RobotHandler(idleNode[0], BLOCKLY.HAT.IDLE, 0, 0);
            RobotHandler busy = new RobotHandler(busyNode[0], BLOCKLY.HAT.BUSY, 400, 0);

            ParentCommand(CONST.COMMAND.StartSystemWork, false);
            bool success = UpdateRobotEvents(idle, (byte)RobotHandler.MODE.idle) &&
                           UpdateRobotEvents(busy, (byte)RobotHandler.MODE.busy);

            ParentCommand(CONST.COMMAND.EndSystemWork, false);

            if (success)
            {
                MessageBox.Show("事件處理設定已更新, 請重啟機械人.");
            }
            return;
        }
        private bool UpdateRobotEvents(RobotHandler rh, byte mode)
        {
            byte count = (byte)rh.events.Count;

            if (!UBT.V2_SaveEventHeader(mode, count, (byte)RobotHandler.ACTION.before))
            {
                return(false);
            }
            try
            {
                byte[] data     = rh.ToBytes();
                byte   startIdx = 0;
                while (startIdx < count)
                {
                    byte batchCount = (byte)(count - startIdx);
                    if (batchCount > CONST.ED.BATCH_SIZE)
                    {
                        batchCount = CONST.ED.BATCH_SIZE;
                    }
                    if (!UBT.V2_SaveEventData(mode, startIdx, batchCount, data))
                    {
                        return(false);
                    }
                    startIdx += batchCount;
                }
            }
            catch
            {
                MessageBox.Show("事件設定不正常, 請小心檢查一下.");
                return(false);
            }
            if (!UBT.V2_SaveEventHeader(mode, count, (byte)RobotHandler.ACTION.after))
            {
                return(false);
            }
            return(true);
        }