Esempio n. 1
0
        private void libDeviceList_Click(object sender, EventArgs e)
        {
            DataTable dtTemp = new DataTable();

            try
            {
                if (libDeviceList.SelectedIndex >= 0)
                {
                    var query = (from a in dtController.AsEnumerable()

                                 where a.Field <string>("device_name") == libDeviceList.SelectedValue.ToString()
                                 //select  new { a, b }).ToList();
                                 select new
                    {
                        Vendor = a.Field <string>("device_type"),
                        ControllerID = a.Field <string>("device_name"),
                        ConnType = a.Field <string>("conn_type")
                    }).ToList();



                    if (query.Count > 0)
                    {
                        Vendor       = query[0].Vendor.ToString();
                        ControllerID = query[0].ControllerID.ToString();

                        btnTCPIP.BackColor  = Color.White;
                        btnRS232C.BackColor = Color.White;

                        switch (query[0].ConnType.ToString())
                        {
                        case "Socket":
                            btnTCPIP_Click(this, null);
                            break;

                        case "ComPort":
                            btnRS232C_Click(this, null);
                            break;
                        }
                        DeviceController ctrl = ControllerManagement.Get(ControllerID);
                        if (ctrl != null)
                        {
                            CommunicationsUpdate.UpdateConnection(ControllerID, ctrl.IsConnected());
                        }
                    }
                    else
                    {
                        CleanConnectMode();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Esempio n. 2
0
        public void getStatus()
        {
            StateUtil.Init();
            foreach (Node each in NodeManagement.GetList())
            {
                string Message = "";
                try
                {
                    IController Ctrl = ControllerManagement.Get(each.Controller);
                    //string ctrl_status = ControllerManagement.Get(each.Controller).Status;
                    string ctrl_status = ControllerManagement.Get(each.Controller) != null?ControllerManagement.Get(each.Controller).GetStatus() : "";

                    if (ctrl_status.Equals("Connected") && each.ByPass == false)
                    {
                        string      seq = "";
                        Transaction txn = new Transaction();
                        if (each.Brand.ToUpper().Equals("KAWASAKI"))
                        {
                            seq = Ctrl.GetNextSeq();
                        }
                        else
                        {
                            seq = "";
                        }
                        switch (each.Type)
                        {
                        case "ROBOT":
                            txn.Method = Transaction.Command.RobotType.GetStatus;
                            break;

                        case "ALIGNER":
                            txn.Method = Transaction.Command.AlignerType.GetStatus;
                            break;

                        case "LOADPORT":
                            txn.Method = Transaction.Command.LoadPortType.ReadStatus;
                            break;
                        }
                        txn.FormName = "FormStatus";
                        txn.AdrNo    = each.AdrNo;
                        txn.Seq      = seq;
                        if (!txn.Method.Equals(""))
                        {
                            each.SendCommand(txn, out Message);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e.StackTrace);
                }
            }
        }
Esempio n. 3
0
        public RobotState(string name)
        {
            Node robot = NodeManagement.Get(name);

            this.Name   = name;
            this.Status = robot != null ? robot.State : "N/A";
            if (this.Status.Equals("N/A") && ControllerManagement.Get(name) != null)
            {
                this.Status = ControllerManagement.Get(name).GetStatus();// 如果 NODE 無狀態,改抓 Controller 的狀態
            }
            this.State     = "".PadLeft(32);
            this.Present_L = "";
            this.Present_R = "";
            this.Vacuum_L  = "";
            this.Vacuum_R  = "";
            this.Speed     = "";
            this.Mode      = "";
            this.Error     = "";
        }
Esempio n. 4
0
        public void setStatus()
        {
            try
            {
                //clear old data
                dgvRstatus.Rows.Clear();
                dgvAstatus.Rows.Clear();
                dgvLstatus.Rows.Clear();
                Thread.Sleep(1000);//避免查詢指令尚未回來
                foreach (Node each in NodeManagement.GetList())
                {
                    string ctrl_status = ControllerManagement.Get(each.Controller) != null?ControllerManagement.Get(each.Controller).GetStatus() : "";

                    if (ctrl_status.Equals("Connected") && each.ByPass == false)
                    {
                        if (each.Brand.ToUpper().Equals("KAWASAKI"))
                        {
                        }
                        else
                        {
                        }
                        String state = "";
                        switch (each.Type)
                        {
                        case "ROBOT":
                            DataGridViewRow robotRow = (DataGridViewRow)dgvRstatus.Rows[0].Clone();
                            robotRow.Cells[0].Value = each.Name;
                            state = ((RobotState)StateUtil.device[each.Name]).State;
                            for (int i = 1; i <= state.Length; i++)
                            {
                                string value = state.Substring(i - 1, 1);
                                robotRow.Cells[i].Value           = value;
                                robotRow.Cells[i].Style.BackColor = getStatusColor(value);
                            }
                            dgvRstatus.Rows.Add(robotRow);
                            break;

                        case "ALIGNER":
                            DataGridViewRow alignerRow = (DataGridViewRow)dgvAstatus.Rows[0].Clone();
                            alignerRow.Cells[0].Value = each.Name;
                            state = ((AlignerState)StateUtil.device[each.Name]).State;
                            for (int i = 1; i <= state.Length; i++)
                            {
                                string value = state.Substring(i - 1, 1);
                                alignerRow.Cells[i].Value           = value;
                                alignerRow.Cells[i].Style.BackColor = getStatusColor(value);
                            }
                            dgvAstatus.Rows.Add(alignerRow);
                            break;

                        case "LOADPORT":
                            DataGridViewRow portRow = (DataGridViewRow)dgvLstatus.Rows[0].Clone();
                            portRow.Cells[0].Value = each.Name;
                            state = ((LoadPortState)StateUtil.device[each.Name]).State;
                            for (int i = 1; i <= state.Length; i++)
                            {
                                string value = state.Substring(i - 1, 1);
                                portRow.Cells[i].Value           = value;
                                portRow.Cells[i].Style.BackColor = getStatusColor(value);
                            }
                            dgvLstatus.Rows.Add(portRow);
                            break;
                        }
                    }
                    else
                    {
                        ////continue;
                        ////do nothing 以下為假資料
                        //string[] states = new String[] { "0", "1", "2", "3", "A", "E", "?" };
                        //string state;
                        //int idx = 0;
                        //switch (each.Type)
                        //{
                        //    case "Robot":
                        //        DataGridViewRow robotRow = (DataGridViewRow)dgvRstatus.Rows[0].Clone();
                        //        robotRow.Cells[0].Value = each.Name;
                        //        for (int i = 1; i <= 32; i++)
                        //        {
                        //            idx = new Random(i).Next() % 7;
                        //            state = states[idx];
                        //            string value = state;
                        //            robotRow.Cells[i].Value = value;
                        //            robotRow.Cells[i].Style.BackColor = getStatusColor(value);
                        //        }
                        //        dgvRstatus.Rows.Add(robotRow);
                        //        break;
                        //    case "Aligner":
                        //        DataGridViewRow alignerRow = (DataGridViewRow)dgvAstatus.Rows[0].Clone();
                        //        alignerRow.Cells[0].Value = each.Name;
                        //        for (int i = 1; i <= 32; i++)
                        //        {
                        //            idx = new Random(i).Next() % 7;
                        //            state = states[idx];
                        //            string value = state;
                        //            alignerRow.Cells[i].Value = value;
                        //            alignerRow.Cells[i].Style.BackColor = getStatusColor(value);
                        //        }
                        //        dgvAstatus.Rows.Add(alignerRow);
                        //        break;
                        //    case "LoadPort":
                        //        DataGridViewRow portRow = (DataGridViewRow)dgvLstatus.Rows[0].Clone();
                        //        portRow.Cells[0].Value = each.Name;
                        //        for (int i = 1; i <= 20; i++)
                        //        {
                        //            idx = new Random(i).Next() % 7;
                        //            state = states[idx];
                        //            string value = state;
                        //            portRow.Cells[i].Value = state;
                        //            portRow.Cells[i].Style.BackColor = getStatusColor(value);
                        //        }
                        //        dgvLstatus.Rows.Add(portRow);
                        //        break;
                        //}
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
            }
        }
Esempio n. 5
0
        private void CommandRun()
        {
            try
            {
                while (JobStart)
                {
                    if (Jobs.Count > 0 && !JobLock)
                    {
                        Adam.UI_Update.Terminal.TerminalUpdate.UpdateButtonEnable("btnSend", false);
                        Adam.UI_Update.Terminal.TerminalUpdate.UpdateSplitButtonEnable("sbtnRun", false);

                        foreach (TerminalJob item in Jobs)
                        {
                            if (item.Active)
                            {
                                Adam.UI_Update.Terminal.TerminalUpdate.UpdateLabelText("lbQueue", "Queue:" + (Jobs.Count - (int)item.No).ToString());

                                for (int i = 0; i < ((ArrayList)item.List).Count; i++)
                                {
                                    Adam.UI_Update.Terminal.TerminalUpdate.UpdateReturnList("lsbHistory", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffffff") + "    " + ((ArrayList)item.Device)[i].ToString() + " <<  " + ((ArrayList)item.List)[i].ToString(), false);

                                    // * 回傳訊息處理 待處理
                                    ((ArrayList)item.Message).Add(ControllerManagement.Get(((ArrayList)item.Device)[i].ToString()).DoWorkSync(((ArrayList)item.List)[i].ToString(), ((ArrayList)item.List)[i].ToString().IndexOf("CMD") > 0 ? "CMD" : string.Empty));

                                    if (((ArrayList)item.Message)[i].ToString().IndexOf("FIN") > 0 || ((ArrayList)item.Message)[i].ToString().IndexOf("NAK") > 0)
                                    {
                                        if (!((ArrayList)item.Message)[i].ToString().Split(':')[2].ToString().Equals("00000000") || ((ArrayList)item.Message)[i].ToString().Equals("Command time out!"))
                                        {
                                            item.Active = false;
                                            btnStop_Click(this, null);
                                            Adam.UI_Update.Terminal.TerminalUpdate.UpdateReturnList("lsbHistory", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffffff") + "    " + ((ArrayList)item.Device)[i].ToString() + " >>  " + ((ArrayList)item.Message)[i].ToString(), false);
                                            break;
                                        }
                                    }
                                    //((ArrayList)item.Message).Add("TEST");
                                    //Thread.Sleep(1000);
                                    Adam.UI_Update.Terminal.TerminalUpdate.UpdateReturnList("lsbHistory", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffffff") + "    " + ((ArrayList)item.Device)[i].ToString() + " >>  " + ((ArrayList)item.Message)[i].ToString(), false);

                                    if (!item.Active)
                                    {
                                        break;
                                    }
                                }

                                item.Active = false;
                            }
                        }

                        for (int i = 0; i < Jobs.Count; i++)
                        {
                            if (!Jobs[i].Active)
                            {
                                Jobs.Remove(Jobs[i]);
                            }
                        }
                    }
                    else if (!JobLock)
                    {
                        Adam.UI_Update.Terminal.TerminalUpdate.UpdateLabelText("lbQueue", "Queue:" + Jobs.Count);
                        JobLock = true;
                        Adam.UI_Update.Terminal.TerminalUpdate.UpdateButtonEnable("btnSend", true);
                        Adam.UI_Update.Terminal.TerminalUpdate.UpdateSplitButtonEnable("sbtnRun", true);
                    }

                    if (!JobStart)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new Exception(ex.ToString());
            }
        }
Esempio n. 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string        strSql                  = string.Empty;
            StringBuilder sbErrorMessage          = new StringBuilder();
            Dictionary <string, object> keyValues = new Dictionary <string, object>();
            DBUtil    dBUtil = new DBUtil();
            DataTable dtTemp = new DataTable();


            try
            {
                Node currentNode = NodeManagement.Get(Setting_NodeName_lb.Text);

                if (currentNode == null)
                {
                    MessageBox.Show("Node " + Setting_NodeName_lb.Text + " is not exist!");
                    return;
                }
                IController currentController = ControllerManagement.Get(currentNode.Controller);
                if (currentController == null)
                {
                    MessageBox.Show("Controller " + currentNode.Controller + " is not exist!");
                    return;
                }
                //權限檢查
                using (var form = new FormConfirm("是否儲存變更?"))
                {
                    var result = form.ShowDialog();
                    if (result != DialogResult.OK)
                    {
                        MessageBox.Show("Cancel.", "Notice");
                        return;
                    }
                }
                currentNode.Enable      = Setting_NodeEnable_rb.Checked;
                currentNode.CarrierType = Setting_CarrierType_cb.Text;
                currentNode.Mode        = Setting_Mode_cb.Text;
                strSql = @"UPDATE config_node SET enable_flg = @enable_flg ,carrier_type = @carrier_type, mode = @mode WHERE equipment_model_id = @equipment_model_id AND node_id = @node_id";

                keyValues.Add("@equipment_model_id", SystemConfig.Get().SystemMode);
                keyValues.Add("@node_id", currentNode.Name);
                keyValues.Add("@enable_flg", currentNode.Enable ? 1 : 0);
                keyValues.Add("@carrier_type", currentNode.CarrierType);
                keyValues.Add("@mode", currentNode.Mode);

                dBUtil.ExecuteNonQuery(strSql, keyValues);

                keyValues.Clear();

                strSql = "UPDATE config_controller_setting SET conn_type = @conn_type, conn_address = @conn_address , conn_port = @conn_port WHERE equipment_model_id = @equipment_model_id AND device_name = @device_name";

                keyValues.Add("@equipment_model_id", SystemConfig.Get().SystemMode);
                keyValues.Add("@device_name", currentNode.Controller);
                keyValues.Add("@conn_type", Setting_connectType_cb.Text);
                keyValues.Add("@conn_address", Setting_Address_tb.Text);
                keyValues.Add("@conn_port", Setting_Port_tb.Text);
                dBUtil.ExecuteNonQuery(strSql, keyValues);



                MessageBox.Show("連線相關設定值,將於重啟程式後生效.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }